Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[native-image] Annotations on reflection might fail #1048

Closed
johanvos opened this issue Mar 8, 2019 · 2 comments

Comments

2 participants
@johanvos
Copy link
Contributor

commented Mar 8, 2019

The following application will fail during native-image:

import java.lang.reflect.*;
import java.lang.annotation.*;

public class HelloWorld {

    public static void main(String[] args) throws Exception  {
        Class type = Dummy.class;
        Method[] methods = type.getDeclaredMethods();
        for (Method m : methods) {
            if (m.getAnnotation(Override.class) != null) {
                System.err.println("yes");
            } else {
                System.err.println("no");
            }
        }
    }
}

public class Dummy { 

    public Dummy() { }

    public void a() { } 

    private void b() { } 

    protected void c() { } 
}

Where Dummy is added in reflectionconfig (passed to native-image with -H:ReflectionConfigurationFiles=reflectionconfig.json)

[
  {
    "name" : "Dummy",
    "allDeclaredConstructors" : true,
    "allPublicConstructors" : true,
    "allDeclaredFields" : true,
    "allPublicFields" : true,
    "allDeclaredMethods" : true,
    "allPublicMethods" : true
  }
]

This fails with


Error: Error encountered while parsing com.oracle.svm.reflect.target.ReflectionHelper.getHolder(java.lang.reflect.Executable) 
Parsing context:
	parsing com.oracle.svm.reflect.target.Target_java_lang_reflect_Executable.declaredAnnotations(Target_java_lang_reflect_Executable.java:93)
	parsing java.base@11.0.2/java.lang.reflect.Executable.getAnnotation(Executable.java:572)
	parsing java.base@11.0.2/java.lang.reflect.Method.getAnnotation(Method.java:695)
	parsing HelloWorld.main(HelloWorld.java:10)
	parsing app//com.oracle.svm.core.JavaMainWrapper.run(JavaMainWrapper.java:152)
	parsing com.oracle.svm.core.code.IsolateEnterStub.JavaMainWrapper_run_5087f5482cc9a6abc971913ece43acb471d2631b(generated:0)

@johanvos

This comment has been minimized.

Copy link
Contributor Author

commented Mar 8, 2019

Stacktrace to the NullPointerException in ReflectionHelper:

Caused by: org.graalvm.compiler.java.BytecodeParser$BytecodeParserError: java.lang.NullPointerException
	at parsing com.oracle.svm.reflect.target.ReflectionHelper.getHolder(ReflectionHelper.java:38)
	at jdk.internal.vm.compiler/org.graalvm.compiler.java.BytecodeParser.throwParserError(BytecodeParser.java:2435)
	at com.oracle.svm.hosted.phases.SharedGraphBuilderPhase$SharedBytecodeParser.throwParserError(SharedGraphBuilderPhase.java:88)
	at jdk.internal.vm.compiler/org.graalvm.compiler.java.BytecodeParser.iterateBytecodesForBlock(BytecodeParser.java:3189)
	at jdk.internal.vm.compiler/org.graalvm.compiler.java.BytecodeParser.processBlock(BytecodeParser.java:2993)
	at jdk.internal.vm.compiler/org.graalvm.compiler.java.BytecodeParser.build(BytecodeParser.java:891)
	at jdk.internal.vm.compiler/org.graalvm.compiler.java.BytecodeParser.buildRootMethod(BytecodeParser.java:785)
	at jdk.internal.vm.compiler/org.graalvm.compiler.java.GraphBuilderPhase$Instance.run(GraphBuilderPhase.java:95)
	at jdk.internal.vm.compiler/org.graalvm.compiler.phases.Phase.run(Phase.java:49)
	at jdk.internal.vm.compiler/org.graalvm.compiler.phases.BasePhase.apply(BasePhase.java:197)
	at jdk.internal.vm.compiler/org.graalvm.compiler.phases.Phase.apply(Phase.java:42)
	at jdk.internal.vm.compiler/org.graalvm.compiler.phases.Phase.apply(Phase.java:38)
	at com.oracle.graal.pointsto.flow.MethodTypeFlowBuilder.parse(MethodTypeFlowBuilder.java:213)
	at com.oracle.graal.pointsto.flow.MethodTypeFlowBuilder.apply(MethodTypeFlowBuilder.java:332)
	at com.oracle.graal.pointsto.flow.MethodTypeFlow.doParse(MethodTypeFlow.java:310)
	... 11 more
Caused by: java.lang.NullPointerException
	at jdk.internal.vm.ci/jdk.vm.ci.meta.Signature.getReturnKind(Signature.java:83)
	at jdk.internal.vm.compiler/org.graalvm.compiler.java.BytecodeParser.appendInvoke(BytecodeParser.java:1680)
	at jdk.internal.vm.compiler/org.graalvm.compiler.java.BytecodeParser.genDynamicInvokeHelper(BytecodeParser.java:1585)
	at jdk.internal.vm.compiler/org.graalvm.compiler.java.BytecodeParser.genInvokeVirtual(BytecodeParser.java:1535)
	at jdk.internal.vm.compiler/org.graalvm.compiler.java.BytecodeParser.genInvokeVirtual(BytecodeParser.java:1520)
	at jdk.internal.vm.compiler/org.graalvm.compiler.java.BytecodeParser.processBytecode(BytecodeParser.java:5018)
	at jdk.internal.vm.compiler/org.graalvm.compiler.java.BytecodeParser.iterateBytecodesForBlock(BytecodeParser.java:3184)
	... 22 more
Error: Image building with exit status 1

@vjovanov vjovanov changed the title Annotations on reflection might fail [native-image] Annotations on reflection might fail Mar 8, 2019

@vjovanov

This comment has been minimized.

Copy link
Contributor

commented Mar 12, 2019

Fixed here.

@vjovanov vjovanov closed this Mar 12, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.