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

Unable to execute nativeTest under Junit 5.11.0-M2 #602

Open
linghengqian opened this issue Jun 12, 2024 · 1 comment · May be fixed by #603
Open

Unable to execute nativeTest under Junit 5.11.0-M2 #602

linghengqian opened this issue Jun 12, 2024 · 1 comment · May be fixed by #603
Labels
bug Something isn't working

Comments

@linghengqian
Copy link
Contributor

linghengqian commented Jun 12, 2024

Before reporting

  • This repository should be used to report issues on the Maven or Gradle plugins for GraalVM.
  • Please report issues which are specific to the Spring Framework or the Micronaut framework to their specific repositories.
  • Do not report issues with building your specific application, e.g errors which happen at image build time like classes initialized at build time, or missing classes as run time: those are not related to the plugins but problems with configuration. You can refer to the GraalVM native image documentation for available options and the plugins documentation for how to use them with the plugin.

Describe the bug
A clear and concise description of what the bug is.
Make sure that you have read the documentation and that you are using the latest plugin version.

To Reproduce

When possible, provide a link to a repository which reproduces the issue, with instructions on how to use.
The reproducer must make use of either the Maven or Gradle plugin.

Steps to reproduce the behavior:

  • Execute the following command on the Ubuntu 22.04.4 instance with SDKMAN! installed.
sdk install java 22.0.1-graalce
sdk use java 22.0.1-graalce
sudo apt-get install build-essential libz-dev zlib1g-dev -y

git clone [email protected]:linghengqian/junit-v5110-test.git
cd ./junit-v5110-test/
./mvnw -PnativeTestInJunit -T1C -e clean test

Please use backticks to properly format code.
If possible please attach a complete reproducer here (either as a zip file or as a link to public repository/branch).

Expected behavior
A clear and concise description of what you expected to happen.

Logs
Add logs to help explain your problem.
Please use backticks to properly format big logs.

[2/8] Performing analysis...  [****]                                                                    (11.8s @ 0.69GB)
    6,818 reachable types   (81.3% of    8,388 total)
    9,294 reachable fields  (51.0% of   18,209 total)
   30,315 reachable methods (52.4% of   57,859 total)
    2,358 types,    72 fields, and   883 methods registered for reflection
       58 types,    58 fields, and    52 methods registered for JNI access
        4 native libraries: dl, pthread, rt, z

Error: An object of type 'org.junit.platform.commons.util.LruCache' was found in the image heap. This type, however, is marked for initialization at image run time for the following reason: classes are initialized at run time by default.
This is not allowed for correctness reasons: All objects that are stored in the image heap must be initialized at build time.

You now have two options to resolve this:

1) If it is intended that objects of type 'org.junit.platform.commons.util.LruCache' are persisted in the image heap, add 

    '--initialize-at-build-time=org.junit.platform.commons.util.LruCache'

to the native-image arguments. Note that initializing new types can store additional objects to the heap. It is advised to check the static fields of 'org.junit.platform.commons.util.LruCache' to see if they are safe for build-time initialization,  and that they do not contain any sensitive data that should not become part of the image.

2) If these objects should not be stored in the image heap, you can use 

    '--trace-object-instantiation=org.junit.platform.commons.util.LruCache'

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.

If you are seeing this message after upgrading to a new GraalVM release, this means that some objects ended up in the image heap without their type being marked with --initialize-at-build-time.
To fix this, include '--initialize-at-build-time=org.junit.platform.commons.util.LruCache' in your configuration. If the classes do not originate from your code, it is advised to update all library or framework dependencies to the latest version before addressing this error.

The following detailed trace displays from which field in the code the object was reached.
Detailed message:
Trace: Object was reached by
  reading field java.util.Collections$SynchronizedMap.m of constant 
    java.util.Collections$SynchronizedMap@2633a885: {}
  reading static field org.junit.platform.commons.util.ReflectionUtils.interfaceMethodCache
    at <unknown-location>
  registered as read because: null

System Info (please complete the following information):

  • OS: [e.g. Windows] Ubuntu 22.04.4
  • GraalVM Version [e.g. 22.0 CE] 24.0.1 CE
  • Java Version [e.g. 17] 22
  • Plugin version [e.g. native-gradle-plugin:0.9.10] native-maven-plugin:0.10.2

Additional context
Add any other context about the problem here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
1 participant