Skip to content

Commit

Permalink
Fix race condition making it possible to return a non-ready future fr…
Browse files Browse the repository at this point in the history
…om BlueNBT
  • Loading branch information
TBlueF committed Jul 26, 2024
1 parent ce2be84 commit 147e981
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/main/java/de/bluecolored/bluenbt/BlueNBT.java
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ public <U> Optional<? extends InstanceCreator<U>> create(TypeToken<U> createType
@SuppressWarnings("unchecked")
public <T> TypeSerializer<T> getTypeSerializer(TypeToken<T> type) {
TypeSerializer<T> serializer = (TypeSerializer<T>) typeSerializerMap.get(type);
if (serializer != null) return serializer;
if (serializer != null && (!(serializer instanceof FutureTypeSerializer))) return serializer;

synchronized (this) {
serializer = (TypeSerializer<T>) typeSerializerMap.get(type);
Expand Down Expand Up @@ -196,7 +196,7 @@ public <T> TypeSerializer<T> getTypeSerializer(TypeToken<T> type) {
@SuppressWarnings("unchecked")
public <T> TypeDeserializer<T> getTypeDeserializer(TypeToken<T> type) {
TypeDeserializer<T> deserializer = (TypeDeserializer<T>) typeDeserializerMap.get(type);
if (deserializer != null) return deserializer;
if (deserializer != null && (!(deserializer instanceof FutureTypeDeserializer))) return deserializer;

synchronized (this) {
deserializer = (TypeDeserializer<T>) typeDeserializerMap.get(type);
Expand Down Expand Up @@ -227,7 +227,7 @@ public <T> TypeDeserializer<T> getTypeDeserializer(TypeToken<T> type) {
@SuppressWarnings("unchecked")
public <T> InstanceCreator<T> getInstanceCreator(TypeToken<T> type) {
InstanceCreator<T> instanceCreator = (InstanceCreator<T>) instanceCreatorMap.get(type);
if (instanceCreator != null) return instanceCreator;
if (instanceCreator != null && (!(instanceCreator instanceof FutureInstanceCreator))) return instanceCreator;

synchronized (this) {
instanceCreator = (InstanceCreator<T>) instanceCreatorMap.get(type);
Expand Down

0 comments on commit 147e981

Please sign in to comment.