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] Error "Class 'org.aeonbits.owner.crypto.IdentityDecryptor' cannot be instantiated; " #1547

Closed
neomatrix369 opened this issue Jul 26, 2019 · 18 comments
Assignees

Comments

@neomatrix369
Copy link
Contributor

neomatrix369 commented Jul 26, 2019

When trying to build a native image from a new uber jar, I get the below message.

I have generated the needed config (in META-INF) file needed using the tracing agent and also manually added an entry.

Command:

OPTIONS="${2:-} --no-fallback --allow-incomplete-classpath --enable-all-security-services 
--enable-http --enable-https --enable-url-protocols"

native-image ${OPTIONS} -jar ${JARFILE} ${IMAGE_NAME}

Config (META-INF/native-image) snippet related to the error:

{
  "name":"org.aeonbits.owner.crypto.IdentityDecryptor",
  "methods":[{"name":"<init>","parameterTypes":[] }],
  "allPublicMethods":true
},

I have added the above to the reflect-config.json file but has no effect.

Output:

16:57:13.830 [main] DEBUG org.neomatrix369.cli.Main - Unable to suppress JDK9 message
java.lang.ClassNotFoundException: jdk.internal.module.IllegalAccessLogger. This exception was synthesized during native image building from a call to java.lang.Class.forName(String) with a constant class name argument.
	at org.neomatrix369.cli.Main.disableAnnoyingJDK9PlusWarning(Main.java:1487)
	at org.neomatrix369.cli.Main.main(Main.java:150)
16:57:13.831 [main] WARN org.neomatrix369.cli.Main - Unable to load version properties!
Exception in thread "main" java.lang.UnsupportedOperationException: Class 'org.aeonbits.owner.crypto.IdentityDecryptor' cannot be instantiated; see the cause below in the stack trace
	at org.aeonbits.owner.Util.unsupported(Util.java:139)
	at org.aeonbits.owner.Util.newInstance(Util.java:273)
	at org.aeonbits.owner.PropertiesManager.<init>(PropertiesManager.java:161)
	at org.aeonbits.owner.DefaultFactory.create(DefaultFactory.java:43)
	at org.aeonbits.owner.ConfigFactory.create(ConfigFactory.java:73)
	at org.neomatrix369.cli.Main.displayHelp(Main.java:1431)
	at org.neomatrix369.cli.Main.main(Main.java:155)
Caused by: java.lang.InstantiationException: Type `org.aeonbits.owner.crypto.IdentityDecryptor` can not be instantiated reflectively as it does not have a no-parameter constructor or the no-parameter constructor has not been added explicitly to the native image.
	at java.lang.Class.newInstance(DynamicHub.java:740)
	at org.aeonbits.owner.Util.newInstance(Util.java:271)
	... 5 more

Environment:

Darwin manis-MacBook.local 17.7.0 Darwin Kernel Version 17.7.0: Sun Jun  2 20:31:42 PDT 2019; root:xnu-4570.71.46~1/RELEASE_X86_64 x86_64

java -version
openjdk version "1.8.0_212"
OpenJDK Runtime Environment (build 1.8.0_212-20190420112649.buildslave.jdk8u-src-tar--b03)
OpenJDK GraalVM CE 19.0.0 (build 25.212-b03-jvmci-19-b01, mixed mode)

I looked at #1163 and #926 and the suggestions there do not help resolve this one. Is this still being worked on?

@cstancu
Copy link
Member

cstancu commented Jul 26, 2019

What's weird with this error is that jdk.internal.module.IllegalAccessLogger is a JDK9+ class and your java is JDK8. Did you compile your app code with a later JDK, i.e., JDK11?

@cstancu cstancu self-assigned this Jul 26, 2019
@neomatrix369
Copy link
Contributor Author

What's weird with this error is that jdk.internal.module.IllegalAccessLogger is a JDK9+ class and your java is JDK8. Did you compile your app code with a later JDK, i.e., JDK11?

Good point, I will look into this, and see if I can eliminate it on my end. But if I can't (and this could be an example of an edge-case), then would look up to you guys for some support.

@neomatrix369
Copy link
Contributor Author

neomatrix369 commented Jul 28, 2019

When trying to build a native image from a new uber jar, I get the below message.

I have generated the needed config (in META-INF) file needed using the tracing agent and also manually added an entry.

Command:

OPTIONS="${2:-} --no-fallback --allow-incomplete-classpath --enable-all-security-services 
--enable-http --enable-https --enable-url-protocols"

native-image ${OPTIONS} -jar ${JARFILE} ${IMAGE_NAME}

Config (META-INF/native-image) snippet related to the error:

{
  "name":"org.aeonbits.owner.crypto.IdentityDecryptor",
  "methods":[{"name":"<init>","parameterTypes":[] }],
  "allPublicMethods":true
},

I have added the above to the reflect-config.json file but has no effect.

Output:

16:57:13.830 [main] DEBUG org.neomatrix369.cli.Main - Unable to suppress JDK9 message
java.lang.ClassNotFoundException: jdk.internal.module.IllegalAccessLogger. This exception was synthesized during native image building from a call to java.lang.Class.forName(String) with a constant class name argument.
	at org.neomatrix369.cli.Main.disableAnnoyingJDK9PlusWarning(Main.java:1487)
	at org.neomatrix369.cli.Main.main(Main.java:150)
16:57:13.831 [main] WARN org.neomatrix369.cli.Main - Unable to load version properties!
Exception in thread "main" java.lang.UnsupportedOperationException: Class 'org.aeonbits.owner.crypto.IdentityDecryptor' cannot be instantiated; see the cause below in the stack trace
	at org.aeonbits.owner.Util.unsupported(Util.java:139)
	at org.aeonbits.owner.Util.newInstance(Util.java:273)
	at org.aeonbits.owner.PropertiesManager.<init>(PropertiesManager.java:161)
	at org.aeonbits.owner.DefaultFactory.create(DefaultFactory.java:43)
	at org.aeonbits.owner.ConfigFactory.create(ConfigFactory.java:73)
	at org.neomatrix369.cli.Main.displayHelp(Main.java:1431)
	at org.neomatrix369.cli.Main.main(Main.java:155)
Caused by: java.lang.InstantiationException: Type `org.aeonbits.owner.crypto.IdentityDecryptor` can not be instantiated reflectively as it does not have a no-parameter constructor or the no-parameter constructor has not been added explicitly to the native image.
	at java.lang.Class.newInstance(DynamicHub.java:740)
	at org.aeonbits.owner.Util.newInstance(Util.java:271)
	... 5 more

Environment:

Darwin manis-MacBook.local 17.7.0 Darwin Kernel Version 17.7.0: Sun Jun  2 20:31:42 PDT 2019; root:xnu-4570.71.46~1/RELEASE_X86_64 x86_64

java -version
openjdk version "1.8.0_212"
OpenJDK Runtime Environment (build 1.8.0_212-20190420112649.buildslave.jdk8u-src-tar--b03)
OpenJDK GraalVM CE 19.0.0 (build 25.212-b03-jvmci-19-b01, mixed mode)

I looked at #1163 and #926 and the suggestions there do not help resolve this one. Is this still being worked on?

How do we tackle the second issue:

Exception in thread "main" java.lang.UnsupportedOperationException: Class 'org.aeonbits.owner.crypto.IdentityDecryptor' cannot be instantiated; see the cause below in the stack trace
...

As mentioned, despite the definition in the META-INF reflection config file, we still get this error message.

@neomatrix369
Copy link
Contributor Author

The latest update is that we are now down to this error message:

14:04:41.578 [main] WARN org.neomatrix369.cli.Main - Unable to load version properties!
Exception in thread "main" java.lang.UnsupportedOperationException: Class 'org.aeonbits.owner.crypto.IdentityDecryptor' cannot be instantiated; see the cause below in the stack trace
	at org.aeonbits.owner.Util.unsupported(Util.java:139)
	at org.aeonbits.owner.Util.newInstance(Util.java:273)
	at org.aeonbits.owner.PropertiesManager.<init>(PropertiesManager.java:161)
	at org.aeonbits.owner.DefaultFactory.create(DefaultFactory.java:43)
	at org.aeonbits.owner.ConfigFactory.create(ConfigFactory.java:73)
	at org.neomatrix369.cli.Main.displayHelp(Main.java:1495)
	at org.neomatrix369.cli.Main.main(Main.java:159)
Caused by: java.lang.InstantiationException: Type `org.aeonbits.owner.crypto.IdentityDecryptor` can not be instantiated reflectively as it does not have a no-parameter constructor or the no-parameter constructor has not been added explicitly to the native image.
	at java.lang.Class.newInstance(DynamicHub.java:754)
	at org.aeonbits.owner.Util.newInstance(Util.java:271)
	... 5 more

I get these generated in the reflect-config.json for org.aeonbit related packages:

{
  "name":"org.aeonbits.owner.JMXSupport",
  "allPublicMethods":true
},
{
  "name":"org.aeonbits.owner.PropertiesManager",
  "allPublicMethods":true
},
{
  "name":"org.aeonbits.owner.crypto.IdentityDecryptor",
  "methods":[{"name":"<init>","parameterTypes":[] }]
},

Is this sufficient for the native-image?

@cstancu
Copy link
Member

cstancu commented Jul 29, 2019

Can you try specifying the reflection config file directly via -H:ReflectionConfigurationFiles=/path/to/reflectconfig to eliminate the possibility that the file is not found?

@neomatrix369
Copy link
Contributor Author

neomatrix369 commented Jul 29, 2019

Can you try specifying the reflection config file directly via -H:ReflectionConfigurationFiles=/path/to/reflectconfig to eliminate the possibility that the file is not found?

That advice helped, I did that for all the 4 config files:

OPTIONS="${OPTIONS} -H:ReflectionConfigurationFiles=${PWD}/META-INF/native-image/reflect-config.json"
OPTIONS="${OPTIONS} -H:DynamicProxyConfigurationFiles=${PWD}/META-INF/native-image/proxy-config.json"
OPTIONS="${OPTIONS} -H:ResourceConfigurationFiles=${PWD}/META-INF/native-image/resource-config.json"
OPTIONS="${OPTIONS} -H:JNIConfigurationFiles=${PWD}/META-INF/native-image/jni-config.json"

Although I was under the impression native-image detected the META-INF/native-image folder with the config files. if placed next to the jar file.

@neomatrix369
Copy link
Contributor Author

I can now run the program further, and it now breaks at the below:

Exception in thread "main" java.lang.UnsupportedOperationException: Cannot convert 'false' to java.lang.Boolean
	at org.aeonbits.owner.Util.unsupported(Util.java:143)
	at org.aeonbits.owner.Converters.unsupportedConversion(Converters.java:296)
	at org.aeonbits.owner.Converters.access$500(Converters.java:36)
	at org.aeonbits.owner.Converters$12.tryConvert(Converters.java:248)
	at org.aeonbits.owner.Converters.doConvert(Converters.java:284)
	at org.aeonbits.owner.Converters.convert(Converters.java:279)
	at org.aeonbits.owner.PropertiesInvocationHandler.resolveProperty(PropertiesInvocationHandler.java:90)
	at org.aeonbits.owner.PropertiesInvocationHandler.invoke(PropertiesInvocationHandler.java:67)
	at com.sun.proxy.$Proxy412.doesScanJavascript(Unknown Source)
	at org.neomatrix369.cli.Main.isViableFolder(Main.java:420)
	at org.neomatrix369.cli.Main.run(Main.java:263)
	at org.neomatrix369.cli.Main.main(Main.java:172)

This must be something new.

@cstancu
Copy link
Member

cstancu commented Jul 29, 2019

Although I was under the impression native-image detected the META-INF/native-image folder with the config files. if placed next to the jar file.

META-INF/native-image needs to be inside the jar file. I think META-INF/native-image should also work when is placed next to the code organized in directories, but not archived.

@cstancu
Copy link
Member

cstancu commented Jul 29, 2019

Regarding the error Cannot convert 'false' to java.lang.Boolean, does your code execute successfully on HotSpot?

@neomatrix369
Copy link
Contributor Author

neomatrix369 commented Jul 29, 2019

Regarding the error Cannot convert 'false' to java.lang.Boolean, does your code execute successfully on HotSpot?

Yes, the uber jar runs fine on traditional JDK (Hotspot) - Java 8.

I'm trying to use the native-image binary to do the same things as the uberjar.

@olpaw
Copy link
Member

olpaw commented Jul 30, 2019

Although I was under the impression native-image detected the META-INF/native-image folder with the config files. if placed next to the jar file.

Placing it next to the jar file has not effect whatsoever. You need to have META-INF/native-image on the classpath. Either by having it right inside your jar file or by adding the parent directory of META-INF to the classpath:

@neomatrix369
Copy link
Contributor Author

Although I was under the impression native-image detected the META-INF/native-image folder with the config files. if placed next to the jar file.

Placing it next to the jar file has not effect whatsoever. You need to have META-INF/native-image on the classpath. Either by having it right inside your jar file or by adding the parent directory of META-INF to the classpath:

From this blog I picked up the below:

The native image generator automatically picks up configuration files in META-INF/native-image or subdirectories, the same way that native-image.properties files are automatically picked up.

Although doing what @cstancu and you suggested fixed the first error.

@neomatrix369
Copy link
Contributor Author

Regarding the error Cannot convert 'false' to java.lang.Boolean, does your code execute successfully on HotSpot?

@cstancu
It's this properties files loading library behind the dynamic code generation, see http://owner.aeonbits.org/. Hence we have the error message #1547 (comment)

@cstancu
Copy link
Member

cstancu commented Jul 30, 2019

@neomatrix369 can you provide minimal reproducible code?

@neomatrix369
Copy link
Contributor Author

neomatrix369 commented Aug 1, 2019

@neomatrix369 can you provide minimal reproducible code?

@cstancu
aeonbits-example.zip

I have an example attached to this message. Usage:

  • unzip the zip artifact
  • cd into folder
  • run mvn package
  • run ./prepareForNativeBuild.sh target/hotreload-jar-with-dependencies.jar
  • run ./buildNativeImage.sh target/hotreload-jar-with-dependencies.jar

And you should see a message like this at the end of the process:

[snipped]

~~~~ Testing built binary hotreload-jar-with-dependencies


 HOT RELOAD EXAMPLE

The program is running.
Now you can change the file located at:

	/path/to/aeonbits-example/target/examples-generated-resources/HotReloadExample.properties

 ...and see the changes reflected below


Exception in thread "main" java.lang.UnsupportedOperationException: Cannot convert '10' to java.lang.Integer
	at org.aeonbits.owner.Util.unsupported(Util.java:143)
	at org.aeonbits.owner.Converters.unsupportedConversion(Converters.java:296)
	at org.aeonbits.owner.Converters.access$500(Converters.java:36)
	at org.aeonbits.owner.Converters$12.tryConvert(Converters.java:248)
	at org.aeonbits.owner.Converters.doConvert(Converters.java:284)
	at org.aeonbits.owner.Converters.convert(Converters.java:279)
	at org.aeonbits.owner.PropertiesInvocationHandler.resolveProperty(PropertiesInvocationHandler.java:90)
	at org.aeonbits.owner.PropertiesInvocationHandler.invoke(PropertiesInvocationHandler.java:67)
	at org.aeonbits.owner.examples.$Proxy205.someValue(Unknown Source)
	at org.aeonbits.owner.examples.HotReloadExample.main(HotReloadExample.java:69)

Which is synonymous to #1547 (comment)

@neomatrix369
Copy link
Contributor Author

@cstancu is the above good enough for your analysis? Let me know if anything else might help.

@cstancu
Copy link
Member

cstancu commented Oct 13, 2020

@neomatrix369 I'm closing this issue as I don't think it is a bug. I suggest using the Native Image agent to get the complete configuration.

@cstancu cstancu closed this as completed Oct 13, 2020
@neomatrix369
Copy link
Contributor Author

neomatrix369 commented Oct 14, 2020

@neomatrix369 I'm closing this issue as I don't think it is a bug. I suggest using the Native Image agent to get the complete configuration.

No worries @cstancu I think this issue is long gone because I was able to rebuild and run the native-image with success, later on, I think the tracing-agent plus some manual config must have helped, it's been a long time since I worked on it. Thank you for following up.

PS: long time no speaks, keep up the good work (and to your team! 👏 )

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants