Skip to content

Commit b9440e0

Browse files
committed
Do not differentiate configuration type descriptors based on whether they come from a name or type field
1 parent 882ba24 commit b9440e0

File tree

6 files changed

+21
-31
lines changed

6 files changed

+21
-31
lines changed

substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/configure/ConfigurationParser.java

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -262,21 +262,25 @@ private static JsonParserException failOnSchemaError(String message) {
262262
throw new JsonParserException(message);
263263
}
264264

265-
protected static Optional<ConfigurationTypeDescriptor> parseTypeOrName(EconomicMap<String, Object> data, boolean treatAllNameEntriesAsType) {
265+
protected record TypeDescriptorWithOrigin(ConfigurationTypeDescriptor typeDescriptor, boolean definedAsType) {
266+
}
267+
268+
protected static Optional<TypeDescriptorWithOrigin> parseTypeOrName(EconomicMap<String, Object> data, boolean treatAllNameEntriesAsType) {
266269
Object typeObject = data.get(TYPE_KEY);
267270
Object name = data.get(NAME_KEY);
268271
if (typeObject != null) {
269-
return parseTypeContents(typeObject);
272+
return parseTypeContents(typeObject).map(typeDescriptor -> new TypeDescriptorWithOrigin(typeDescriptor, true));
270273
} else if (name != null) {
271-
return Optional.of(new NamedConfigurationTypeDescriptor(asString(name), treatAllNameEntriesAsType));
274+
NamedConfigurationTypeDescriptor typeDescriptor = new NamedConfigurationTypeDescriptor(asString(name));
275+
return Optional.of(new TypeDescriptorWithOrigin(typeDescriptor, treatAllNameEntriesAsType));
272276
} else {
273277
throw failOnSchemaError("must have type or name specified for an element");
274278
}
275279
}
276280

277281
protected static Optional<ConfigurationTypeDescriptor> parseTypeContents(Object typeObject) {
278282
if (typeObject instanceof String stringValue) {
279-
return Optional.of(new NamedConfigurationTypeDescriptor(stringValue, true));
283+
return Optional.of(new NamedConfigurationTypeDescriptor(stringValue));
280284
} else {
281285
EconomicMap<String, Object> type = asMap(typeObject, "type descriptor should be a string or object");
282286
if (type.containsKey(PROXY_KEY)) {

substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/configure/ConfigurationTypeDescriptor.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,4 @@ static String checkQualifiedJavaName(String javaName) {
7171
assert javaName.indexOf('/') == -1 || javaName.indexOf('/') > javaName.lastIndexOf('.') : "Requires qualified Java name, not internal representation: %s".formatted(javaName);
7272
return canonicalizeTypeName(javaName);
7373
}
74-
75-
boolean definedAsType();
7674
}

substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/configure/LegacyReflectionConfigurationParser.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,11 @@ protected void parseClass(EconomicMap<String, Object> data) {
6262
checkAttributes(data, "reflection class descriptor object", Collections.emptyList(), OPTIONAL_REFLECT_CONFIG_OBJECT_ATTRS);
6363
checkHasExactlyOneAttribute(data, "reflection class descriptor object", List.of(NAME_KEY, TYPE_KEY));
6464

65-
Optional<ConfigurationTypeDescriptor> type = parseTypeOrName(data, treatAllNameEntriesAsType);
65+
Optional<TypeDescriptorWithOrigin> type = parseTypeOrName(data, treatAllNameEntriesAsType);
6666
if (type.isEmpty()) {
6767
return;
6868
}
69+
ConfigurationTypeDescriptor typeDescriptor = type.get().typeDescriptor();
6970
/*
7071
* Classes registered using the old ("name") syntax requires elements (fields, methods,
7172
* constructors, ...) to be registered for runtime queries, whereas the new ("type") syntax
@@ -84,9 +85,9 @@ protected void parseClass(EconomicMap<String, Object> data) {
8485
* allow getDeclaredMethods() and similar bulk queries at run time.
8586
*/
8687
C condition = conditionResult.get();
87-
TypeResult<T> result = delegate.resolveType(condition, type.get(), true);
88+
TypeResult<T> result = delegate.resolveType(condition, typeDescriptor, true);
8889
if (!result.isPresent()) {
89-
handleMissingElement("Could not resolve " + type.get() + " for reflection configuration.", result.getException());
90+
handleMissingElement("Could not resolve " + typeDescriptor + " for reflection configuration.", result.getException());
9091
return;
9192
}
9293

substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/configure/LegacySerializationConfigurationParser.java

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -89,26 +89,28 @@ protected void parseSerializationDescriptorObject(EconomicMap<String, Object> da
8989
checkHasExactlyOneAttribute(data, "serialization descriptor object", List.of(TYPE_KEY, NAME_KEY));
9090
}
9191

92-
Optional<ConfigurationTypeDescriptor> targetSerializationClass = parseTypeOrName(data, false);
93-
if (targetSerializationClass.isEmpty()) {
92+
Optional<TypeDescriptorWithOrigin> target = parseTypeOrName(data, false);
93+
if (target.isEmpty()) {
9494
return;
9595
}
96+
ConfigurationTypeDescriptor targetSerializationClass = target.get().typeDescriptor();
97+
boolean definedAsType = target.get().definedAsType();
9698

97-
UnresolvedConfigurationCondition unresolvedCondition = parseCondition(data, targetSerializationClass.get().definedAsType());
99+
UnresolvedConfigurationCondition unresolvedCondition = parseCondition(data, definedAsType);
98100
var condition = conditionResolver.resolveCondition(unresolvedCondition);
99101
if (!condition.isPresent()) {
100102
return;
101103
}
102104

103105
if (lambdaCapturingType) {
104-
String className = ((NamedConfigurationTypeDescriptor) targetSerializationClass.get()).name();
106+
String className = ((NamedConfigurationTypeDescriptor) targetSerializationClass).name();
105107
serializationSupport.registerLambdaCapturingClass(condition.get(), className);
106108
} else {
107109
Object optionalCustomCtorValue = data.get(CUSTOM_TARGET_CONSTRUCTOR_CLASS_KEY);
108110
String customTargetConstructorClass = optionalCustomCtorValue != null ? asString(optionalCustomCtorValue) : null;
109-
if (targetSerializationClass.get() instanceof NamedConfigurationTypeDescriptor namedClass) {
111+
if (targetSerializationClass instanceof NamedConfigurationTypeDescriptor namedClass) {
110112
serializationSupport.registerWithTargetConstructorClass(condition.get(), namedClass.name(), customTargetConstructorClass);
111-
} else if (targetSerializationClass.get() instanceof ProxyConfigurationTypeDescriptor proxyClass) {
113+
} else if (targetSerializationClass instanceof ProxyConfigurationTypeDescriptor proxyClass) {
112114
serializationSupport.registerProxyClass(condition.get(), Arrays.asList(proxyClass.interfaceNames()));
113115
} else {
114116
throw new JsonParserException("Unknown configuration type descriptor: %s".formatted(targetSerializationClass.toString()));

substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/configure/NamedConfigurationTypeDescriptor.java

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -30,20 +30,10 @@
3030

3131
import jdk.graal.compiler.util.json.JsonWriter;
3232

33-
public record NamedConfigurationTypeDescriptor(String name, boolean definedAsType) implements ConfigurationTypeDescriptor {
33+
public record NamedConfigurationTypeDescriptor(String name) implements ConfigurationTypeDescriptor {
3434

3535
public NamedConfigurationTypeDescriptor(String name) {
36-
this(name, false);
37-
}
38-
39-
public NamedConfigurationTypeDescriptor(String name, boolean definedAsType) {
4036
this.name = ConfigurationTypeDescriptor.checkQualifiedJavaName(name);
41-
this.definedAsType = definedAsType;
42-
}
43-
44-
@Override
45-
public boolean definedAsType() {
46-
return definedAsType;
4737
}
4838

4939
@Override

substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/configure/ProxyConfigurationTypeDescriptor.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -65,11 +65,6 @@ public int compareTo(ConfigurationTypeDescriptor other) {
6565
}
6666
}
6767

68-
@Override
69-
public boolean definedAsType() {
70-
return true;
71-
}
72-
7368
@Override
7469
public void printJson(JsonWriter writer) throws IOException {
7570
writer.append("{").indent().newline();

0 commit comments

Comments
 (0)