mirror of
https://github.com/MinecraftForge/MinecraftForge.git
synced 2026-11-13 00:37:52 +00:00
Fix LazyOptional throwing NPE to consumers when owners null. (#5772)
This commit is contained in:
1 parent
48fa2f458c
commit
7acb380ba8
1 file changed
+10
-9
@@ -29,6 +29,10 @@ import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import javax.annotation.ParametersAreNonnullByDefault;
|
||||
|
||||
import org.apache.logging.log4j.Level;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
import mcp.MethodsReturnNonnullByDefault;
|
||||
import net.minecraftforge.common.capabilities.Capability;
|
||||
|
||||
@@ -58,6 +62,7 @@ public class LazyOptional<T>
|
||||
private boolean isValid = true;
|
||||
|
||||
private static final @Nonnull LazyOptional<Void> EMPTY = new LazyOptional<>(null);
|
||||
private static final Logger LOGGER = LogManager.getLogger();
|
||||
|
||||
/**
|
||||
* Construct a new {@link LazyOptional} that wraps the given
|
||||
@@ -108,18 +113,14 @@ public class LazyOptional<T>
|
||||
if (supplier != null)
|
||||
{
|
||||
resolved = new AtomicReference<>(null);
|
||||
try
|
||||
{
|
||||
T temp = supplier.get();
|
||||
if (temp == null)
|
||||
throw new IllegalStateException("Supplier must not return null value");
|
||||
resolved.set(temp);
|
||||
return resolved.get();
|
||||
}
|
||||
catch (Throwable e)
|
||||
T temp = supplier.get();
|
||||
if (temp == null)
|
||||
{
|
||||
LOGGER.catching(Level.WARN, new NullPointerException("Supplier should not return null value"));
|
||||
return null;
|
||||
}
|
||||
resolved.set(temp);
|
||||
return resolved.get();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user