diff --git a/common/src/main/java/com/seibel/distanthorizons/common/wrappers/block/BiomeWrapper.java b/common/src/main/java/com/seibel/distanthorizons/common/wrappers/block/BiomeWrapper.java index fcb59ad9a..f7282de12 100644 --- a/common/src/main/java/com/seibel/distanthorizons/common/wrappers/block/BiomeWrapper.java +++ b/common/src/main/java/com/seibel/distanthorizons/common/wrappers/block/BiomeWrapper.java @@ -254,6 +254,9 @@ public class BiomeWrapper implements IBiomeWrapper // TODO would it be worth while to cache these objects in a ConcurrentHashMap? public static IBiomeWrapper deserialize(String resourceLocationString, ILevelWrapper levelWrapper) throws IOException { + // we need the final string for the concurrent hash map later + final String finalResourceStateString = resourceLocationString; + if (resourceLocationString.equals(EMPTY_BIOME_STRING)) { if (!emptyStringWarningLogged) @@ -269,9 +272,9 @@ public class BiomeWrapper implements IBiomeWrapper return EMPTY_WRAPPER; } - if (WRAPPER_BY_RESOURCE_LOCATION.containsKey(resourceLocationString)) + if (WRAPPER_BY_RESOURCE_LOCATION.containsKey(finalResourceStateString)) { - return WRAPPER_BY_RESOURCE_LOCATION.get(resourceLocationString); + return WRAPPER_BY_RESOURCE_LOCATION.get(finalResourceStateString); } @@ -335,12 +338,12 @@ public class BiomeWrapper implements IBiomeWrapper } catch (Exception e) { - throw new IOException("Failed to deserialize the string [" + resourceLocationString + "] into a BiomeWrapper: " + e.getMessage(), e); + throw new IOException("Failed to deserialize the string [" + finalResourceStateString + "] into a BiomeWrapper: " + e.getMessage(), e); } } finally { - WRAPPER_BY_RESOURCE_LOCATION.putIfAbsent(resourceLocationString, foundWrapper); + WRAPPER_BY_RESOURCE_LOCATION.putIfAbsent(finalResourceStateString, foundWrapper); } } diff --git a/common/src/main/java/com/seibel/distanthorizons/common/wrappers/block/BlockStateWrapper.java b/common/src/main/java/com/seibel/distanthorizons/common/wrappers/block/BlockStateWrapper.java index 75004f474..4a40c6e1f 100644 --- a/common/src/main/java/com/seibel/distanthorizons/common/wrappers/block/BlockStateWrapper.java +++ b/common/src/main/java/com/seibel/distanthorizons/common/wrappers/block/BlockStateWrapper.java @@ -340,15 +340,18 @@ public class BlockStateWrapper implements IBlockStateWrapper /** will only work if a level is currently loaded */ public static IBlockStateWrapper deserialize(String resourceStateString, ILevelWrapper levelWrapper) throws IOException { - if (resourceStateString.equals(AIR_STRING) || resourceStateString.equals("")) // the empty string shouldn't normally happen, but just in case + // we need the final string for the concurrent hash map later + final String finalResourceStateString = resourceStateString; + + if (finalResourceStateString.equals(AIR_STRING) || finalResourceStateString.equals("")) // the empty string shouldn't normally happen, but just in case { return AIR; } // attempt to use the existing wrapper - if (WRAPPER_BY_RESOURCE_LOCATION.containsKey(resourceStateString)) + if (WRAPPER_BY_RESOURCE_LOCATION.containsKey(finalResourceStateString)) { - return WRAPPER_BY_RESOURCE_LOCATION.get(resourceStateString); + return WRAPPER_BY_RESOURCE_LOCATION.get(finalResourceStateString); } @@ -458,14 +461,14 @@ public class BlockStateWrapper implements IBlockStateWrapper } catch (Exception e) { - throw new IOException("Failed to deserialize the string [" + resourceStateString + "] into a BlockStateWrapper: " + e.getMessage(), e); + throw new IOException("Failed to deserialize the string [" + finalResourceStateString + "] into a BlockStateWrapper: " + e.getMessage(), e); } } finally { // put if absent in case two threads deserialize at the same time // unfortunately we can't put everything in a computeIfAbsent() since we also throw exceptions - WRAPPER_BY_RESOURCE_LOCATION.putIfAbsent(resourceStateString, foundWrapper); + WRAPPER_BY_RESOURCE_LOCATION.putIfAbsent(finalResourceStateString, foundWrapper); } }