Azure / azure-sdk-for-java

This repository is for active development of the Azure SDK for Java. For consumers of the SDK we recommend visiting our public developer docs at https://docs.microsoft.com/java/azure/ or our versioned developer docs at https://azure.github.io/azure-sdk-for-java.
MIT License
2.25k stars 1.93k forks source link

Detected an instance of Random/SplittableRandom class in the image heap #40785

Open parasjain27031994 opened 4 days ago

parasjain27031994 commented 4 days ago

Describe the bug While trying to build a native image for a Quarkus based project, the build is failing with 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."

Exception or Stack Trace

Caused by: com.oracle.graal.pointsto.constraints.UnsupportedFeatureException: 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. If these objects should not be stored in the image heap, you can use 
    '--trace-object-instantiation=java.security.SecureRandom'
to find classes that instantiate these objects. Once you found such a class, you can mark it explicitly for run time initialization with 
    '--initialize-at-run-time=<culprit>'
to prevent the instantiation of the object.
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
  trying to constant fold static field com.microsoft.azure.proton.transport.proxy.impl.DigestProxyChallengeProcessorImpl.SECURE_RANDOM
    at com.microsoft.azure.proton.transport.proxy.impl.DigestProxyChallengeProcessorImpl.computeDigestAuthHeader(DigestProxyChallengeProcessorImpl.java:143)
  parsing method com.microsoft.azure.proton.transport.proxy.impl.DigestProxyChallengeProcessorImpl.computeDigestAuthHeader(DigestProxyChallengeProcessorImpl.java:116) reachable via the parsing context
    at static root method.(Unknown Source)
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. If these objects should not be stored in the image heap, you can use 
    '--trace-object-instantiation=java.security.SecureRandom'
to find classes that instantiate these objects. Once you found such a class, you can mark it explicitly for run time initialization with 
    '--initialize-at-run-time=<culprit>'
to prevent the instantiation of the object.
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
  trying to constant fold static field com.microsoft.azure.proton.transport.ws.impl.Utils.SECURE_RANDOM
    at com.microsoft.azure.proton.transport.ws.impl.Utils.getSecureRandom(Utils.java:20)
  parsing method com.microsoft.azure.proton.transport.ws.impl.Utils.getSecureRandom(Utils.java:20) reachable via the parsing context
    at static root method.(Unknown Source)
    at org.graalvm.nativeimage.pointsto/com.oracle.graal.pointsto.constraints.UnsupportedFeatures.report(UnsupportedFeatures.java:129)
    at org.graalvm.nativeimage.builder/com.oracle.svm.hosted.NativeImageGenerator.runPointsToAnalysis(NativeImageGenerator.java:809)
    ... 6 more
 2m 42s.

To Reproduce Steps to reproduce the behavior:

Code Snippet Snippets from pom.xml

 <dependency>
            <groupId>io.quarkiverse.azureservices</groupId>
            <artifactId>quarkus-azure-http-client-vertx</artifactId>
            <version>1.0.4</version>
        </dependency>
        <dependency>
            <groupId>com.azure</groupId>
            <artifactId>azure-messaging-eventhubs</artifactId>
            <exclusions>
                <exclusion>
                    <groupId>com.azure</groupId>
                    <artifactId>azure-core-http-netty</artifactId>
                </exclusion>
            </exclusions>
        </dependency>

Declaration of Azure EventHub producer :

@Singleton
public class EventHubConfig {

    @Inject
    EventHubCredentialService eventHubCredentialService;

    private EventHubProducerClient eventHubProducerClient;

    @Produces
    public EventHubProducerClient eventHubProducerClient() {
        if (eventHubProducerClient == null) {
            EventHubDetails eventHubDetails = eventHubCredentialService.getEvenHubDetails();
            eventHubProducerClient = new EventHubClientBuilder()
                    .connectionString(eventHubDetails.connectionString(), eventHubDetails.eventHubName())
                    .retryOptions(
                            new AmqpRetryOptions()
                                    .setDelay(Duration.ofSeconds(2))
                                    .setMaxRetries(3)
                                    .setMode(AmqpRetryMode.EXPONENTIAL)
                    )
                    .buildProducerClient();
        }
        return eventHubProducerClient;
    }

    @PreDestroy
    public void closeEventHubProducerClient() {
        if (eventHubProducerClient != null) {
            eventHubProducerClient.close();
        }
    }

Expected behavior Since Azure SDK is compatible with GraalVM, the build should succeed.

Screenshots N/A

Setup (please complete the following information):

Additional context The project uses Azure EventHub library to produce messages, running on AWS Lambda function.

Information Checklist Kindly make sure that you have added all the following information above and checkoff the required fields otherwise we will treat the issuer as an incomplete report

github-actions[bot] commented 4 days ago

@anuchandy @conniey @lmolkova

github-actions[bot] commented 4 days ago

Thank you for your feedback. Tagging and routing to the team member best able to assist.