MineColonies

MineColonies

53M Downloads

NullPointerException when opening resource scroll

TheMrMilchmann opened this issue ยท 0 comments

commented

Prerequisites

  • I am running the latest alpha version of MineColonies and Structurize for my Minecraft version. (Note: I'm running a self-compiled version with one unrelated change.)
  • I checked the MineColonies/Structurize wiki and made sure my issue is not covered there.
  • I made sure that this issue is not a duplicate of any existing issue.

Context

  • Minecraft Version: 1.16.5
  • MineColonies Version: 0.14.358-ALPHA (self-compiled)
  • Structurize Version: 0.13.210-ALPHA
  • Related Mods and their Versions: N/A

Expected behavior

I expect the game not to crash when using a resource scroll.

Actual behavior

The game crashed when I used a resource scroll.

Steps to reproduce the issue

  1. Have insane timing and open a resource scroll right while a request is removed. (The issue is technically reproducible. Practically... not so much.)

Logs

Notes

I tried to open a resource scroll linked to a builder and the game crashed. Some investigation showed that the request in

if (request.getRequest() instanceof Delivery && ((Delivery) request.getRequest()).getTarget().getInDimensionLocation().equals(builder.getID()))
was most likely null due to concurrency issues. Specifically, I assume that a request was somehow removed right as I opened the GUI.

A fix for this particular issue would be checking for null in addDeliveryRequestsToList:

    private void addDeliveryRequestsToList(final List<Delivery> requestList, final ImmutableCollection<IToken<?>> tokensToCheck)
    {
        for (final IToken<?> token : tokensToCheck)
        {
            final IRequest<?> request = builder.getColony().getRequestManager().getRequestForToken(token);
            if (request != null)
            {
                if (request.getRequest() instanceof Delivery && ((Delivery) request.getRequest()).getTarget().getInDimensionLocation().equals(builder.getID()))
                {
                    requestList.add((Delivery) request.getRequest());
                }

                if (request.hasChildren())
                {
                    addDeliveryRequestsToList(requestList, request.getChildren());
                }
            }
        }
    }

However, as this might not be the only place that doesn't properly guard against concurrent modifications, I'm not sure if this is a good fix.


Viewers

  • Add a thumbs-up to the bug report if you are also affected. This helps the bug report become more visible to the team and doesn't clutter the comments.
  • Add a comment if you have any insights or background information that isn't already part of the conversation.