sbt / sbt-native-packager

sbt Native Packager
https://sbt-native-packager.readthedocs.io/en/stable/
BSD 2-Clause "Simplified" License
1.6k stars 442 forks source link

MalformedParameterizedTypeException when building Graal Native Image #1286

Open gvolpe opened 5 years ago

gvolpe commented 5 years ago

Expected behaviour

sbt 'show graalvm-native-image:packageBin' generates a Graal Native image using GraalVM Version 19.3.0 CE.

Actual behaviour

Running sbt 'show graalvm-native-image:packageBin' with the following arguments:

graalVMNativeImageOptions ++= Seq(
      "--initialize-at-build-time",
      "--initialize-at-run-time=" +
        "com.typesafe.config.impl.ConfigImpl$EnvVariablesHolder," +
        "com.typesafe.config.impl.ConfigImpl$SystemPropertiesHolder",
      "--no-fallback",
      "--static"
    )

Gives the following error:

[error] Fatal error: java.lang.reflect.MalformedParameterizedTypeException
[error]         at sun.reflect.generics.reflectiveObjects.ParameterizedTypeImpl.validateConstructorArguments(ParameterizedTypeImpl.java:58)
[error]         at sun.reflect.generics.reflectiveObjects.ParameterizedTypeImpl.<init>(ParameterizedTypeImpl.java:51)
[error]         at sun.reflect.generics.reflectiveObjects.ParameterizedTypeImpl.make(ParameterizedTypeImpl.java:92)
[error]         at sun.reflect.generics.factory.CoreReflectionFactory.makeParameterizedType(CoreReflectionFactory.java:105)
[error]         at sun.reflect.generics.visitor.Reifier.visitClassTypeSignature(Reifier.java:140)
[error]         at sun.reflect.generics.tree.ClassTypeSignature.accept(ClassTypeSignature.java:49)
[error]         at sun.reflect.generics.repository.ConstructorRepository.getParameterTypes(ConstructorRepository.java:94)
[error]         at java.lang.reflect.Executable.getGenericParameterTypes(Executable.java:283)
[error]         at java.lang.reflect.Method.getGenericParameterTypes(Method.java:283)
[error]         at com.oracle.svm.reflect.hosted.ReflectionMetadataFeature.replacer(ReflectionMetadataFeature.java:65)
[error]         at com.oracle.graal.pointsto.meta.AnalysisUniverse.replaceObject(AnalysisUniverse.java:534)
[error]         at com.oracle.svm.hosted.ameta.AnalysisConstantReflectionProvider.replaceObject(AnalysisConstantReflectionProvider.java:201)
[error]         at com.oracle.svm.hosted.ameta.AnalysisConstantReflectionProvider.interceptValue(AnalysisConstantReflectionProvider.java:172)
[error]         at com.oracle.svm.hosted.ameta.AnalysisConstantReflectionProvider.readValue(AnalysisConstantReflectionProvider.java:101)
[error]         at com.oracle.svm.hosted.ameta.AnalysisConstantReflectionProvider.readFieldValue(AnalysisConstantReflectionProvider.java:77)
[error]         at com.oracle.graal.pointsto.ObjectScanner.scanField(ObjectScanner.java:175)
[error]         at com.oracle.graal.pointsto.ObjectScanner.doScan(ObjectScanner.java:344)
[error]         at com.oracle.graal.pointsto.ObjectScanner.access$400(ObjectScanner.java:62)
[error]         at com.oracle.graal.pointsto.ObjectScanner$3$1.run(ObjectScanner.java:414)
[error]         at com.oracle.graal.pointsto.util.CompletionExecutor.lambda$execute$0(CompletionExecutor.java:171)
[error]         at java.util.concurrent.ForkJoinTask$RunnableExecuteAction.exec(ForkJoinTask.java:1402)
[error]         at java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:289)
[error]         at java.util.concurrent.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:1056)
[error]         at java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1692)
[error]         at java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:157)
[error] Error: Image build request failed with exit status 1
[error] stack trace is suppressed; run last core / Graalvm-native-image / packageBin for the full output
[error] (core / Graalvm-native-image / packageBin) Failed to run

Previously reporting a few warnings such as the ones below:

[error] warning: unknown anonymous info of class cats.effect.concurrent.Deferred$State$Unset, assuming class is not anonymous. To remove the warning report an issue to the library or language author. The issue is caused by cats.effect.concurrent.Deferred$State$Unset which is not following the naming convention.
[error] warning: unknown anonymous info of class scala.reflect.runtime.JavaMirrors$JavaMirror$toAnnotArg$PrimitiveClass$, assuming class is not anonymous. To remove the warning report an issue to the library or language author. The issue is caused by scala.reflect.runtime.JavaMirrors$JavaMirror$toAnnotArg$PrimitiveClass$ which is not following the naming convention.
[error] warning: unknown anonymous info of class scala.reflect.runtime.JavaMirrors$JavaMirror$toAnnotArg$EnumClass$, assuming class is not anonymous. To remove the warning report an issue to the library or language author. The issue is caused by scala.reflect.runtime.JavaMirrors$JavaMirror$toAnnotArg$EnumClass$ which is not following the naming convention.
[error] warning: unknown anonymous info of class scala.reflect.runtime.JavaMirrors$JavaMirror$toAnnotArg$ArrayClass$, assuming class is not anonymous. To remove the warning report an issue to the library or language author. The issue is caused by scala.reflect.runtime.JavaMirrors$JavaMirror$toAnnotArg$ArrayClass$ which is not following the naming convention.
[error] warning: unknown anonymous info of class scala.reflect.runtime.JavaMirrors$JavaMirror$toAnnotArg$AnnotationClass$, assuming class is not anonymous. To remove the warning report an issue to the library or language author. The issue is caused by scala.reflect.runtime.JavaMirrors$JavaMirror$toAnnotArg$AnnotationClass$ which is not following the naming convention.
[error] warning: unknown anonymous info of class scala.reflect.runtime.JavaMirrors$JavaMirror$toAnnotArg$ConstantArg$, assuming class is not anonymous. To remove the warning report an issue to the library or language author. The issue is caused by scala.reflect.runtime.JavaMirrors$JavaMirror$toAnnotArg$ConstantArg$ which is not following the naming convention.
[error] warning: unknown anonymous info of class skunk.util.Typer$Strategy$SearchPath$, assuming class is not anonymous. To remove the warning report an issue to the library or language author. The issue is caused by skunk.util.Typer$Strategy$SearchPath$ which is not following the naming convention.

Information

muuki88 commented 5 years ago

Thanks for the comprehensive bug report :hugs:

Do you know what would fix this issue? Why parameters are responsible for the error. The error itself is a bit vague :grimacing:

gvolpe commented 5 years ago

I've no idea, to be honest. If I remove the graalVMNativeImageOptions I get this error instead:

[error] Fatal error: com.oracle.graal.pointsto.util.AnalysisError$ParsingError: Error encountered while parsing scala.reflect.runtime.ReflectionUtils$.reflMethod$Method1(java.lang.Class) 
[error] Parsing context:
[error]         parsing scala.reflect.runtime.ReflectionUtils$.inferClasspath$1(ReflectionUtils.scala:56)
[error]         parsing scala.reflect.runtime.ReflectionUtils$.show(ReflectionUtils.scala:67)
[error]         parsing scala.reflect.api.JavaUniverse$JavaMirror.toString(JavaUniverse.scala:60)
[error]         parsing scala.reflect.api.JavaUniverse$JavaMirror.toString$(JavaUniverse.scala:60)
[error]         parsing scala.reflect.runtime.JavaMirrors$JavaMirror.toString(JavaMirrors.scala:68)
[error]         parsing io.netty.util.internal.logging.MessageFormatter.safeObjectAppend(MessageFormatter.java:276)
[error]         parsing io.netty.util.internal.logging.MessageFormatter.deeplyAppendParameter(MessageFormatter.java:242)
[error]         parsing io.netty.util.internal.logging.MessageFormatter.arrayFormat(MessageFormatter.java:206)
[error]         parsing io.netty.util.internal.logging.MessageFormatter.format(MessageFormatter.java:133)
[error]         parsing io.netty.util.internal.logging.JdkLogger.debug(JdkLogger.java:206)
[error]         parsing io.netty.util.ResourceLeakDetector.<clinit>(ResourceLeakDetector.java:107)
[error]         at com.oracle.graal.pointsto.util.AnalysisError.parsingError(AnalysisError.java:138)
[error]         at com.oracle.graal.pointsto.flow.MethodTypeFlow.doParse(MethodTypeFlow.java:327)
[error]         at com.oracle.graal.pointsto.flow.MethodTypeFlow.ensureParsed(MethodTypeFlow.java:300)
[error]         at com.oracle.graal.pointsto.flow.MethodTypeFlow.addContext(MethodTypeFlow.java:107)
[error]         at com.oracle.graal.pointsto.flow.StaticInvokeTypeFlow.update(InvokeTypeFlow.java:346)
[error]         at com.oracle.graal.pointsto.BigBang$2.run(BigBang.java:511)
[error]         at com.oracle.graal.pointsto.util.CompletionExecutor.lambda$execute$0(CompletionExecutor.java:171)
[error]         at java.util.concurrent.ForkJoinTask$RunnableExecuteAction.exec(ForkJoinTask.java:1402)
[error]         at java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:289)
[error]         at java.util.concurrent.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:1056)
[error]         at java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1692)
[error]         at java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:157)
[error] Caused by: com.oracle.graal.pointsto.constraints.UnsupportedFeatureException: No instances of scala.runtime.StructuralCallSite are allowed in the image heap as this class should be initialized at image runtime. To see how this object got instantiated use -H:+TraceClassInitialization.
[error]         at com.oracle.svm.hosted.classinitialization.ClassInitializationFeature.checkImageHeapInstance(ClassInitializationFeature.java:173)
[error]         at com.oracle.graal.pointsto.meta.AnalysisUniverse.replaceObject(AnalysisUniverse.java:534)
[error]         at com.oracle.svm.hosted.analysis.flow.SVMMethodTypeFlowBuilder.registerUsedElements(SVMMethodTypeFlowBuilder.java:82)
[error]         at com.oracle.graal.pointsto.flow.MethodTypeFlowBuilder.parse(MethodTypeFlowBuilder.java:229)
[error]         at com.oracle.graal.pointsto.flow.MethodTypeFlowBuilder.apply(MethodTypeFlowBuilder.java:340)
[error]         at com.oracle.graal.pointsto.flow.MethodTypeFlow.doParse(MethodTypeFlow.java:310)
[error]         ... 10 more
[error] Error: Image build request failed with exit status 1
[error] stack trace is suppressed; run last core / Graalvm-native-image / packageBin for the full output
[error] (core / Graalvm-native-image / packageBin)

My experience with GraalVM is minimal so I'm just reporting these issues hoping that someone more experienced can shed some light...

muuki88 commented 5 years ago

@ScalaWilliam did the initial implementation. May he has some light to shed on this :hugs:

ScalaWilliam commented 5 years ago

Hello! It looks like a Graalvm specific issue. Can you try a previous version of Graalvm?

gvolpe commented 4 years ago

Sure, any specific version you would recommend? The one mentioned in the documentation seems to have a broken link.

ScalaWilliam commented 4 years ago

Originally I had set it up against GraalVM 1.0.0-rc8.

However if that doesn't fix it, as from my point of view, the issue is most likely GraalVM-specific, you would be best off to try to run the command directly and report any error to the GraalVM GitHub with a minimum reproducible example. https://github.com/oracle/graal/issues

I have limited time at the moment so am afraid I cannot look into depth at this point - apart from suggest to look at how we construct the graalvm command that we run in sbt-native-packager - see the sources.

ScalaWilliam commented 4 years ago

Did you have any luck yet @gvolpe?

muuki88 commented 4 years ago

I have limited time at the moment so am afraid I cannot look into depth at this point

Then thanks a lot for still being active one this issue :hugs:

gvolpe commented 4 years ago

Did you have any luck yet @gvolpe?

I'm really busy these days as well but I'll try to give this a shot when I get some time, thanks again for your help!

ALPSMAC commented 4 years ago

Just as an additional data point, I'm seeing a similar issue trying to build a native image using the 20.0.0 tag of the Graal Image.

There doesn't appear to be an 1.0.0-rc8 on DockerHub anymore, so I tried it with 1.0.0-rc16 but there's no joy there either due to missing the native image update:

[info] Error: Unknown component: native-image
[error] The command 'gu install native-image' returned a non-zero code: 3
[info] 
[error] java.lang.RuntimeException: Nonzero exit value when generating GraalVM container build image: 3
[error]         at com.typesafe.sbt.packager.graalvmnativeimage.GraalVMNativeImagePlugin$.$anonfun$generateContainerBuildImage$1(GraalVMNativeImagePlugin.scala:174)
[error]         at scala.Function1.$anonfun$compose$1(Function1.scala:49)
[error]         at sbt.internal.util.$tilde$greater.$anonfun$$u2219$1(TypeFunctions.scala:62)
[error]         at sbt.std.Transform$$anon$4.work(Transform.scala:67)
[error]         at sbt.Execute.$anonfun$submit$2(Execute.scala:281)
[error]         at sbt.internal.util.ErrorHandling$.wideConvert(ErrorHandling.scala:19)
[error]         at sbt.Execute.work(Execute.scala:290)
[error]         at sbt.Execute.$anonfun$submit$1(Execute.scala:281)
[error]         at sbt.ConcurrentRestrictions$$anon$4.$anonfun$submitValid$1(ConcurrentRestrictions.scala:178)
[error]         at sbt.CompletionService$$anon$2.call(CompletionService.scala:37)
[error]         at java.util.concurrent.FutureTask.run(FutureTask.java:266)
[error]         at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
[error]         at java.util.concurrent.FutureTask.run(FutureTask.java:266)
[error]         at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
[error]         at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
[error]         at java.lang.Thread.run(Thread.java:748)

Cheers.

sshark commented 4 years ago

@ALPSMAC is native-image installed? use the given command gu install native-image to install native-image and try again