jamm icon indicating copy to clipboard operation
jamm copied to clipboard

Tests fail with OpenJDK 17 due to an illegal reflective access

Open merkys opened this issue 2 years ago • 2 comments

While running tests with OpenJDK 17 a failure occurs due to an illegal reflective access into java.base/java.lang:

  [INFO] -------------------------------------------------------
  [INFO]  T E S T S
  [INFO] -------------------------------------------------------
  [INFO] Running org.github.jamm.MemoryMeterTest
  [ERROR] Tests run: 20, Failures: 1, Errors: 2, Skipped: 5, Time elapsed: 0.147 s <<< FAILURE! - in org.github.jamm.MemoryMeterTest
  [ERROR] testPrimitives(org.github.jamm.MemoryMeterTest)  Time elapsed: 0.005 s  <<< ERROR!
  java.lang.reflect.InaccessibleObjectException: Unable to make field private final byte[] java.lang.String.value accessible: module java.base does not "opens java.lang" to unnamed module @768debd
          at org.github.jamm.MemoryMeterTest.testPrimitives(MemoryMeterTest.java:443)
  
  [ERROR] testUnmeteredAnnotationOnFields(org.github.jamm.MemoryMeterTest)  Time elapsed: 0.001 s  <<< ERROR!
  java.lang.reflect.InaccessibleObjectException: Unable to make field private final byte[] java.lang.String.value accessible: module java.base does not "opens java.lang" to unnamed module @768debd
          at org.github.jamm.MemoryMeterTest.testUnmeteredAnnotationOnFields(MemoryMeterTest.java:614)
  
  [ERROR] testByteBuffer(org.github.jamm.MemoryMeterTest)  Time elapsed: 0 s  <<< FAILURE!
  java.lang.AssertionError: Shallow empty ByteBuffer expected:<48> but was:<56>
          at org.github.jamm.MemoryMeterTest.testByteBuffer(MemoryMeterTest.java:478)
  
  [INFO] Running org.github.jamm.GuessTest
  Guessed 16, instrumented 24 for {LONG*1}->{FLOAT*1}
  Guessed 16, instrumented 24 for {LONG*1}->{BYTE*4}
  [ERROR] Tests run: 4, Failures: 1, Errors: 0, Skipped: 3, Time elapsed: 0.418 s <<< FAILURE! - in org.github.jamm.GuessTest
  [ERROR] testProblemClasses(org.github.jamm.GuessTest)  Time elapsed: 0.385 s  <<< FAILURE!
  java.lang.AssertionError: Not all guesses matched the instrumented values. See output for details. expected:<0> but was:<2>
          at org.github.jamm.GuessTest.testProblemClasses(GuessTest.java:85)
  
  [INFO]
  [INFO] Results:
  [INFO]
  [ERROR] Failures:
  [ERROR]   GuessTest.testProblemClasses:85 Not all guesses matched the instrumented values. See output for details. expected:<0> but was:<2>
  [ERROR]   MemoryMeterTest.testByteBuffer:478 Shallow empty ByteBuffer expected:<48> but was:<56>
  [ERROR] Errors:
  [ERROR]   MemoryMeterTest.testPrimitives:443 » InaccessibleObject Unable to make field p...
  [ERROR]   MemoryMeterTest.testUnmeteredAnnotationOnFields:614 » InaccessibleObject Unabl...
  [INFO]
  [ERROR] Tests run: 24, Failures: 2, Errors: 2, Skipped: 8
  [INFO]
  [INFO] ------------------------------------------------------------------------
  [INFO] BUILD FAILURE
  [INFO] ------------------------------------------------------------------------

merkys avatar Jul 01 '22 07:07 merkys

I just started using jamm today and immediately bumped into a similar issue. It is related to changes introduced in JDK 9 concerning module security. See this. TL;DR, you can add --add-opens directives as command line options, like this:

--add-opens java.base/java.lang=ALL-UNNAMED

For my particular case, I had to add about 20 of them!

ashatch avatar Aug 12 '22 14:08 ashatch

Thanks for the pointer @ashatch!

merkys avatar Aug 15 '22 13:08 merkys

Even with --add-opens there are failing tests unfortunately

INFO] -------------------------------------------------------
[INFO]  T E S T S
[INFO] -------------------------------------------------------
[INFO] Running org.github.jamm.MemoryMeterTest
[ERROR] Tests run: 20, Failures: 1, Errors: 0, Skipped: 3, Time elapsed: 0.444 s <<< FAILURE! - in org.github.jamm.MemoryMeterTest
[ERROR] testByteBuffer(org.github.jamm.MemoryMeterTest)  Time elapsed: 0.004 s  <<< FAILURE!
java.lang.AssertionError: Shallow empty ByteBuffer expected:<48> but was:<56>
        at org.github.jamm.MemoryMeterTest.testByteBuffer(MemoryMeterTest.java:478)

[INFO] Running org.github.jamm.GuessTest
Guessed 40, instrumented 120 for {BOOLEAN*7 OBJECT*20 FLOAT*3 SHORT*1}->{BYTE*1}
Guessed 648, instrumented 808 for {LONG*2 LONG*4 SHORT*1 SHORT*1 SHORT*1}->{FLOAT*35 DOUBLE*11 SHORT*28 DOUBLE*3}->{DOUBLE*33 OBJECT*37 BYTE*3 OBJECT*3}->{BYTE*1 BOOLEAN*2}
Guessed 16, instrumented 24 for {LONG*1}->{FLOAT*1}
Guessed 16, instrumented 24 for {LONG*1}->{BYTE*4}
[ERROR] Tests run: 4, Failures: 2, Errors: 0, Skipped: 0, Time elapsed: 13.542 s <<< FAILURE! - in org.github.jamm.GuessTest
[ERROR] testRandomClasses(org.github.jamm.GuessTest)  Time elapsed: 12.208 s  <<< FAILURE!
java.lang.AssertionError: Not all guesses matched the instrumented values. See output for details. expected:<0> but was:<2>
        at org.github.jamm.GuessTest.testRandomClasses(GuessTest.java:116)

[ERROR] testProblemClasses(org.github.jamm.GuessTest)  Time elapsed: 1.096 s  <<< FAILURE!
java.lang.AssertionError: Not all guesses matched the instrumented values. See output for details. expected:<0> but was:<2>
        at org.github.jamm.GuessTest.testProblemClasses(GuessTest.java:84)

[INFO]
[INFO] Results:
[INFO]
[ERROR] Failures:
[ERROR]   GuessTest.testProblemClasses:84 Not all guesses matched the instrumented values. See output for details. expected:<0> but was:<2>
[ERROR]   GuessTest.testRandomClasses:116 Not all guesses matched the instrumented values. See output for details. expected:<0> but was:<2>
[ERROR]   MemoryMeterTest.testByteBuffer:478 Shallow empty ByteBuffer expected:<48> but was:<56>
[INFO]
[ERROR] Tests run: 24, Failures: 3, Errors: 0, Skipped: 3

ebourg avatar Jan 24 '23 08:01 ebourg

We are working on having Jamm ready for JDK17 and this issue is in our pipeline with many others. Hopefully it should be fixed in the 2 coming weeks.

blerer avatar Jan 24 '23 08:01 blerer

The current master version should work smoothly with the JDKs up to 17.

blerer avatar May 22 '23 16:05 blerer

Great, thanks a lot! Are you planning a release with this fix?

merkys avatar May 23 '23 05:05 merkys

Yes. We plan to run some tests with Apache Cassandra in the coming weeks to make sure that there is no issues that we have missed and once it looks good we will make an official release. We also plan to add support for the latest JDK versions after that release.

blerer avatar May 23 '23 07:05 blerer

Great, thanks!

merkys avatar May 23 '23 07:05 merkys