Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Some downstream native configs initialize JUnit classes at build time in production #3707

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

Open
diegomarquezp opened this issue Mar 17, 2025 · 2 comments
Labels
priority: p2 Moderately-important priority. Fix may not be included in next release. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns.

Comments

@diegomarquezp
Copy link
Contributor

From #3674

Some libraries mark JUnit classes for initialization at build time in its production native properties file.

For example: https://github.com/googleapis/java-spanner-jdbc/blob/fa65ead20018c083749bb1bd1cc1993f48745ef9/src/main/resources/META-INF/native-image/com.google.cloud/google-cloud-spanner-jdbc/native-image.properties#L15

I tried moving it to a test-only config file (src/test/resources...) but the image creation would fail asking to specify the JUnit classes to be initialized at runtime.

@diegomarquezp diegomarquezp added type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns. priority: p2 Moderately-important priority. Fix may not be included in next release. labels Mar 17, 2025
@blakeli0
Copy link
Collaborator

I tried moving it to a test-only config file (src/test/resources...) but the image creation would fail

What exactly does this mean? @diegomarquezp Can you please provide more info regarding how to reproduce it?

@diegomarquezp
Copy link
Contributor Author

diegomarquezp commented Mar 19, 2025

I tried moving it to a test-only config file (src/test/resources...) but the image creation would fail

What exactly does this mean? [@diegomarquezp](https://github.com/diegomarquezp) Can you please provide more info regarding how to reproduce it?

@blakeli0 This is pretty much what was attempted in googleapis/java-spanner-jdbc@d78fe2f. When it comes to "the image creation would fail" I was thinking of the failing GraalVM checks in that commit.

The attempt was: Since some JUnit classes are found in src/main/resources/.../native-image.properties, I thought it would be more appropiate to move them to src/test/resources/.../native-image.properties, but the GraalVM image creation would fail complaining with the following error as if the test folder's properties file wasn't being considered:

Fatal error: com.oracle.graal.pointsto.constraints.UnsupportedFeatureException: An object of type 'org.junit.runners.Parameterized' 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.runners.Parameterized' are persisted in the image heap, add 

    '--initialize-at-build-time=org.junit.runners.Parameterized'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
priority: p2 Moderately-important priority. Fix may not be included in next release. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns.
Projects
None yet
Development

No branches or pull requests

2 participants