Skip to content

Commit 4e0e146

Browse files
committed
Unwrap the original method from the SubstitutionMethod when loading lambda types
1 parent 6ae832d commit 4e0e146

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/imagelayer/SVMImageLayerLoader.java

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
import java.util.function.Supplier;
5252
import java.util.stream.IntStream;
5353

54+
import com.oracle.svm.hosted.substitute.SubstitutionMethod;
5455
import org.graalvm.collections.EconomicMap;
5556
import org.graalvm.nativeimage.AnnotationAccess;
5657
import org.graalvm.nativeimage.ImageSingletons;
@@ -453,16 +454,32 @@ protected boolean delegateLoadType(PersistedAnalysisType.Reader typeData) {
453454
return false;
454455
}
455456

457+
/**
458+
* The {@link SubstitutionMethod} contains less information than the original
459+
* {@link ResolvedJavaMethod} and trying to access it can result in an exception.
460+
*/
461+
private static ResolvedJavaMethod getOriginalWrapped(AnalysisMethod method) {
462+
ResolvedJavaMethod wrapped = method.getWrapped();
463+
if (wrapped instanceof SubstitutionMethod subst) {
464+
return subst.getAnnotated();
465+
}
466+
return wrapped;
467+
}
468+
456469
/**
457470
* Load all lambda types of the given capturing class. Each method of the capturing class is
458471
* parsed (see {@link LambdaParser#createMethodGraph(ResolvedJavaMethod, OptionValues)}). The
459472
* lambda types can then be found in the constant nodes of the graphs.
460473
*/
461474
private void loadLambdaTypes(Class<?> capturingClass) {
462475
capturingClasses.computeIfAbsent(capturingClass, key -> {
476+
/*
477+
* Getting the original wrapped method is important to avoid getting exceptions that
478+
* would be ignored otherwise.
479+
*/
463480
LambdaParser.allExecutablesDeclaredInClass(universe.getBigbang().getMetaAccess().lookupJavaType(capturingClass))
464481
.filter(m -> m.getCode() != null)
465-
.forEach(m -> loadLambdaTypes(((AnalysisMethod) m).getWrapped(), universe.getBigbang()));
482+
.forEach(m -> loadLambdaTypes(getOriginalWrapped((AnalysisMethod) m), universe.getBigbang()));
466483
return true;
467484
});
468485
}

0 commit comments

Comments
 (0)