Skip to content

Commit

Permalink
fix recursive issues
Browse files Browse the repository at this point in the history
  • Loading branch information
Steanky committed Jul 26, 2023
1 parent 2e7e99f commit 430d8fe
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ plugins {
}

group = "com.github.steanky"
version = "0.15.1"
version = "0.15.2"

java {
toolchain.languageVersion.set(JavaLanguageVersion.of(17))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,22 +89,34 @@ public BasicElementContext(final @NotNull Registry<ConfigProcessor<?>> processor
}

final Key objectTypeFinal = objectType;
final DataInfo dataInfo = dataObjects.computeIfAbsent(absolutePath, keyPath -> {
DataInfo dataInfo = dataObjects.get(absolutePath);
if (dataInfo == null) {
try {
final ConfigNode configuration = dataNode != null ? dataNode : keyPath.followNode(rootCopy);
final ConfigNode configuration = dataNode != null ? dataNode : absolutePath.followNode(rootCopy);
final Object data = processorRegistry.contains(objectTypeFinal) ?
processorRegistry.lookup(objectTypeFinal).dataFromElement(configuration) : null;

return new DataInfo(data, objectTypeFinal);
dataInfo = new DataInfo(data, objectTypeFinal);
DataInfo newObject = dataObjects.putIfAbsent(absolutePath, dataInfo);
if (newObject != null) {
dataInfo = newObject;
}
} catch (ConfigProcessException e) {
throw new ElementException("configuration error deserializing data at path " + keyPath, e);
throw new ElementException("configuration error deserializing data at path " + absolutePath, e);
}
});
}

final DataInfo finalDataInfo = dataInfo;
if (cacheElement) {
return (TElement) elementObjects.computeIfAbsent(absolutePath, elementPath ->
((ElementFactory<Object, Object>) factoryRegistry.lookup(dataInfo.type))
.make(dataInfo.data, elementPath, this, dependencyProvider));
final Object elementObject = elementObjects.get(absolutePath);
if (elementObject != null) {
return (TElement) elementObject;
}

TElement object = (TElement) ((ElementFactory<Object, Object>) factoryRegistry.lookup(finalDataInfo.type))
.make(finalDataInfo.data, absolutePath, this, dependencyProvider);
TElement newObject = (TElement) elementObjects.putIfAbsent(absolutePath, object);
return newObject != null ? newObject : object;
}

return (TElement) ((ElementFactory<Object, Object>) factoryRegistry.lookup(dataInfo.type))
Expand Down

0 comments on commit 430d8fe

Please sign in to comment.