9

Using records (preview feature java-14) in a jlink:ed application, gives below error when using options:

options = ['--strip-debug', '--compress', '2', '--no-header-files', '--no-man-pages']

java.lang.ClassFormatError: Invalid constant pool index 11 for name in Record attribute in class file 
myproj/MyClass$MyRecord
    at java.base/java.lang.ClassLoader.defineClass1(Native Method)
    at java.base/java.lang.ClassLoader.defineClass(Unknown Source)
    at java.base/java.lang.ClassLoader.defineClass(Unknown Source)
Naman
  • 27,789
  • 26
  • 218
  • 353
Aksel Willgert
  • 11,367
  • 5
  • 53
  • 74
  • 3
    Got a link handy to try this out? Reproducible example if I would ask for. – Naman Apr 29 '20 at 16:07
  • 3
    @Aksel Willgert, could you provide a way to reproduce the error? simple source + commands you are using? you can also send us a detailed report to: amber-dev@openjdk.java.net – Vicente Romero Apr 29 '20 at 16:30

4 Answers4

7

I suggest you to try with JDK-15 which has an updated version of ASM (ASM 8.0.1) which have support for records. That should fix your issue. This is the bug report that relates to the update to ASM (ASM 8.0.1): JDK-8241627. This version of ASM was not available while we were developing JDK 14. I've never seen a backport of ASM to a previous JDK version, and considering that records are a preview feature...

Vicente Romero
  • 1,460
  • 13
  • 16
  • An important point, but why not move that support to JDK-14 as well? In my understanding the vesion `ASM 8.0.1` is crucial for preview-features to some extent, isn't it true? – Naman May 07 '20 at 06:48
  • Do you have a link to a bug report? – Johannes Kuhn May 10 '20 at 23:29
  • 1
    I have edited my answer to add a link to the bug report that introduced ASM `8.0.1` in JDK 15. @Naman, thanks for the edits you did too – Vicente Romero May 13 '20 at 01:08
6

I can reproduce this issue with a simple "hello world" module that uses record feature along with JDK-14.

On the other hand with JDK-15 build (built from the source repo), it just works fine.

Naman
  • 27,789
  • 26
  • 218
  • 353
A. Sundararajan
  • 4,277
  • 1
  • 15
  • 30
  • 2
    FWIW, I've also tested with the latest JDK 15 EA build from [jdk.java.net](http://jdk.java.net/15/). Also works fine there. – Jorn Vernee Apr 29 '20 at 17:22
  • To add to the details as mentioned in [Vicente's answer](https://stackoverflow.com/a/61507179/1746118), this could mostly be because of the preview-feature support in the latest ASM. Not that I am confirming it, but it's just a point you can look further into and update in the answer for people to be really able to know "why not Java-14?". – Naman May 07 '20 at 06:45
3

Remove Option --strip-debug

options = ['--compress', '2', '--no-header-files', '--no-man-pages']
Aksel Willgert
  • 11,367
  • 5
  • 53
  • 74
3

Assuming the end goal is to reduce the size of the custom Java runtime image, an option on JDK14 (Linux only) is to only remove the native debug symbols (where the fat really is!) and keep the Java debug attributes (to avoid the current ASM issue) by using —-strip-native-debug-symbols.

See https://delabassee.com/StrippingDebug-Jlink/ for some details.

davidd
  • 655
  • 1
  • 4
  • 7