Skip to content

Commit b903836

Browse files
Ensure reflection method name at runtime is the expected one.
If a hosted method is renamed for the sake of unique names generated in `HostedMethod#create0`, ensure that reflection still uses the original name.
1 parent a034fdd commit b903836

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/code/RuntimeMetadataEncoderImpl.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -445,7 +445,7 @@ public void addReflectionFieldMetadata(MetaAccessProvider metaAccess, HostedFiel
445445
public void addReflectionExecutableMetadata(MetaAccessProvider metaAccess, HostedMethod hostedMethod, ConditionalRuntimeValue<Executable> conditionalMethod, Object accessor) {
446446
boolean isMethod = !hostedMethod.isConstructor();
447447
HostedType declaringType = hostedMethod.getDeclaringClass();
448-
String name = isMethod ? hostedMethod.getName() : null;
448+
String name = isMethod ? hostedMethod.getReflectionName() : null;
449449
HostedType[] parameterTypes = getParameterTypes(hostedMethod);
450450
/* Reflect method because substitution of Object.hashCode() is private */
451451
Executable reflectMethod = conditionalMethod.getValueUnconditionally();
@@ -643,7 +643,7 @@ public void addReachableFieldMetadata(HostedField field) {
643643
public void addReachableExecutableMetadata(HostedMethod executable) {
644644
boolean isMethod = !executable.isConstructor();
645645
HostedType declaringType = executable.getDeclaringClass();
646-
String name = isMethod ? executable.getName() : null;
646+
String name = isMethod ? executable.getReflectionName() : null;
647647
String[] parameterTypeNames = getParameterTypeNames(executable);
648648

649649
/* Fill encoders with the necessary values. */

substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/meta/HostedMethod.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -398,6 +398,15 @@ public String getName() {
398398
return name;
399399
}
400400

401+
/**
402+
* Returns the original name of the method, without any suffix that might have been added by
403+
* {@link HostedMethodNameFactory}.
404+
*/
405+
public String getReflectionName() {
406+
VMError.guarantee(this.isOriginalMethod());
407+
return wrapped.getName();
408+
}
409+
401410
@Override
402411
public ResolvedSignature<HostedType> getSignature() {
403412
return signature;

0 commit comments

Comments
 (0)