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

[GR-42095] Track object instantiation presenting stacktraces that are not possible #5267

Open
galderz opened this issue Oct 21, 2022 · 1 comment
Assignees
Labels
bug native-image quarkus quarkus related issue

Comments

@galderz
Copy link
Contributor

galderz commented Oct 21, 2022

Trace object instantiation can at times show stacktraces that will never be invoked by the application. You can find an example in Quarkus's Native Reference guide.

In there, a class that is build time initialized, initializes a cryptographic key pair in a static block:

public class EncryptDecryptResource {

    static final KeyPairGenerator KEY_PAIR_GEN;

    static {
        try {
            KEY_PAIR_GEN = KeyPairGenerator.getInstance("RSA");
            KEY_PAIR_GEN.initialize(1024);
        } catch (NoSuchAlgorithmException | NoSuchPaddingException e) {
            throw new RuntimeException(e);
        }
    }

This causes an error because it would lead to a SecureRandom ending up in the build time heap:

Error: Unsupported features in 2 methods
Detailed message:
Error: Detected an instance of Random/SplittableRandom class in the image heap. Instances created during image generation have cached seed values and don't behave as expected.  To see how this object got instantiated use --trace-object-instantiation=java.security.SecureRandom. The object was probably created by a class initializer and is reachable from a static field. You can request class initialization at image runtime by using the option --initialize-at-run-time=<class-name>. Or you can write your own initialization methods and call them explicitly from your main entry point.
Trace: Object was reached by
	reading field java.security.KeyPairGenerator$Delegate.initRandom of
		constant java.security.KeyPairGenerator$Delegate@58b0fe1b reached by
	reading field org.acme.EncryptDecryptResource.KEY_PAIR_GEN
Error: Detected an instance of Random/SplittableRandom class in the image heap. Instances created during image generation have cached seed values and don't behave as expected.  To see how this object got instantiated use --trace-object-instantiation=java.security.SecureRandom. The object was probably created by a class initializer and is reachable from a static field. You can request class initialization at image runtime by using the option --initialize-at-run-time=<class-name>. Or you can write your own initialization methods and call them explicitly from your main entry point.
Trace: Object was reached by
	reading field sun.security.rsa.RSAKeyPairGenerator.random of
		constant sun.security.rsa.RSAKeyPairGenerator$Legacy@3248a092 reached by
	reading field java.security.KeyPairGenerator$Delegate.spi of
		constant java.security.KeyPairGenerator$Delegate@58b0fe1b reached by
	reading field org.acme.EncryptDecryptResource.KEY_PAIR_GEN

If you then pass in --trace-object-instantiation=java.security.SecureRandom to track object instantiation, it shows the following stacktrace, which is not something the application will call:

Error: Detected an instance of Random/SplittableRandom class in the image heap. Instances created during image generation have cached seed values and don't behave as expected.  Object has been initialized by the com.sun.jndi.dns.DnsClient class initializer with a trace:
 	at java.security.SecureRandom.<init>(SecureRandom.java:218)
	at sun.security.jca.JCAUtil$CachedSecureRandomHolder.<clinit>(JCAUtil.java:59)
	at sun.security.jca.JCAUtil.getSecureRandom(JCAUtil.java:69)
	at com.sun.jndi.dns.DnsClient.<clinit>(DnsClient.java:82)

Sure, the DnsClient caches a SecureRandom statically, but the application doesn't call this. This kind of error reporting can be very confusing for the end user.

@galderz galderz added the bug label Oct 21, 2022
@oubidar-Abderrahim oubidar-Abderrahim self-assigned this Oct 26, 2022
@oubidar-Abderrahim oubidar-Abderrahim added native-image quarkus quarkus related issue labels Oct 26, 2022
@oubidar-Abderrahim
Copy link
Member

Hi, Thank you for reporting this. this is tracked internally GR 42095

@wirthi wirthi changed the title Track object instantiation presenting stacktraces that are not possible [GR-42095] Track object instantiation presenting stacktraces that are not possible Jan 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug native-image quarkus quarkus related issue
Projects
None yet
Development

No branches or pull requests

3 participants