graalvm / native-build-tools

Native-image plugins for various build tools
https://graalvm.github.io/native-build-tools/
Other
371 stars 60 forks source link

Unable to execute nativeTest under Junit 5.11.0-M2 #602

Closed linghengqian closed 2 months ago

linghengqian commented 5 months ago

Before reporting

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:

git clone git@github.com:linghengqian/junit-v5110-test.git cd ./junit-v5110-test/ ./mvnw -PnativeTestInJunit -T1C -e clean test

Please use backticks to [properly format code](https://docs.github.com/en/get-started/writing-on-github/working-with-advanced-formatting/creating-and-highlighting-code-blocks#syntax-highlighting).
If possible please attach a complete reproducer here (either as [a zip file](https://docs.github.com/en/get-started/writing-on-github/working-with-advanced-formatting/attaching-files) 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](https://docs.github.com/en/get-started/writing-on-github/working-with-advanced-formatting/creating-and-highlighting-code-blocks#fenced-code-blocks). 

```bash
[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):

Additional context Add any other context about the problem here.

linghengqian commented 5 months ago
vjovanov commented 4 months ago

@linghengqian will you provide a PR for this issue? We need to add org.junit.platform.commons.util.LruCache to the list of classes initialized at build time for JUnit 5. This class was added in the latest versions of JUnit and therefore we don't support it yet. Here is an example of PR that modifies the list:

https://github.com/graalvm/native-build-tools/pull/573/files

Thank you very much for reporting this issue.

linghengqian commented 4 months ago

@linghengqian will you provide a PR for this issue? We need to add org.junit.platform.commons.util.LruCache to the list of classes initialized at build time for JUnit 5. This class was added in the latest versions of JUnit and therefore we don't support it yet. Here is an example of PR that modifies the list:

https://github.com/graalvm/native-build-tools/pull/573/files

Thank you very much for reporting this issue.