|
51 | 51 | import java.util.function.Supplier;
|
52 | 52 | import java.util.stream.IntStream;
|
53 | 53 |
|
| 54 | +import com.oracle.svm.hosted.substitute.SubstitutionMethod; |
54 | 55 | import org.graalvm.collections.EconomicMap;
|
55 | 56 | import org.graalvm.nativeimage.AnnotationAccess;
|
56 | 57 | import org.graalvm.nativeimage.ImageSingletons;
|
@@ -453,16 +454,32 @@ protected boolean delegateLoadType(PersistedAnalysisType.Reader typeData) {
|
453 | 454 | return false;
|
454 | 455 | }
|
455 | 456 |
|
| 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 | + |
456 | 469 | /**
|
457 | 470 | * Load all lambda types of the given capturing class. Each method of the capturing class is
|
458 | 471 | * parsed (see {@link LambdaParser#createMethodGraph(ResolvedJavaMethod, OptionValues)}). The
|
459 | 472 | * lambda types can then be found in the constant nodes of the graphs.
|
460 | 473 | */
|
461 | 474 | private void loadLambdaTypes(Class<?> capturingClass) {
|
462 | 475 | capturingClasses.computeIfAbsent(capturingClass, key -> {
|
| 476 | + /* |
| 477 | + * Getting the original wrapped method is important to avoid getting exceptions that |
| 478 | + * would be ignored otherwise. |
| 479 | + */ |
463 | 480 | LambdaParser.allExecutablesDeclaredInClass(universe.getBigbang().getMetaAccess().lookupJavaType(capturingClass))
|
464 | 481 | .filter(m -> m.getCode() != null)
|
465 |
| - .forEach(m -> loadLambdaTypes(((AnalysisMethod) m).getWrapped(), universe.getBigbang())); |
| 482 | + .forEach(m -> loadLambdaTypes(getOriginalWrapped((AnalysisMethod) m), universe.getBigbang())); |
466 | 483 | return true;
|
467 | 484 | });
|
468 | 485 | }
|
|
0 commit comments