Skip to content

Use of LambdaMetafactory broken in Java 17 while working on Java 11 #4006

Closed
@zakkak

Description

@zakkak

Describe the issue

Applications using LambdaMetafactory.metafactory() fail to compile with java17-21.3.0 due to java.lang.Class.protectionDomain() being reached. The issue does not manifest with java11-21.3.0.

Steps to reproduce the issue

cd /tmp
git clone --branch avro-protectiondomain-java17 https://github.com/zakkak/issue-reproducers reproducers
cd reproducers
export JAVA_HOME=/opt/jvms/graalvm-ce-java17-21.3.0
mvn package
$JAVA_HOME/bin/native-image \
  --no-fallback -H:+ReportExceptionStackTraces \
  -jar target/reproducer-1.0-SNAPSHOT.jar
./reproducer-1.0-SNAPSHOT

Describe GraalVM and your environment:

  • GraalVM version: 21.3
  • JDK major version: 17
  • OS: Fedora 34
  • Architecture: AMD64

More details
Note: The provided reproducer is extracted from apache avro.

The build fails with:

Error: com.oracle.svm.hosted.substitute.DeletedElementException: Unsupported method java.lang.Class.protectionDomain() is reachable: The declaring class of this element has been substituted, but this element is not present in the substitution class
To diagnose the issue, you can add the option --report-unsupported-elements-at-runtime. The unsupported element is then reported at run time when it is accessed the first time.
Detailed message:
Trace: 
	at parsing java.lang.System$2.protectionDomain(System.java:2418)
Call path from entry point to java.lang.System$2.protectionDomain(Class): 
	at java.lang.System$2.protectionDomain(System.java:2418)
	at java.lang.invoke.MethodHandles$Lookup.lookupClassProtectionDomain(MethodHandles.java:2457)
	at java.lang.invoke.MethodHandles$Lookup$ClassDefiner.defineClass(MethodHandles.java:2437)
	at java.lang.invoke.MethodHandles$Lookup$ClassDefiner.defineClassAsLookup(MethodHandles.java:2420)
	at java.lang.invoke.MethodHandles$Lookup.defineHiddenClass(MethodHandles.java:2127)
	at java.lang.invoke.InnerClassLambdaMetafactory.generateInnerClass(InnerClassLambdaMetafactory.java:407)
	at java.lang.invoke.InnerClassLambdaMetafactory.spinInnerClass(InnerClassLambdaMetafactory.java:315)
	at java.lang.invoke.LambdaMetafactory.metafactory(LambdaMetafactory.java:341)
	at Main.main(Main.java:16)
	at com.oracle.svm.core.JavaMainWrapper.runCore(JavaMainWrapper.java:147)
	at com.oracle.svm.core.JavaMainWrapper.run(JavaMainWrapper.java:183)
...

Metadata

Metadata

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions