Records in jlink:ed application throws exception
Asked Answered
A

4

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)
Alliaceous answered 29/4, 2020 at 15:1 Comment(2)
Got a link handy to try this out? Reproducible example if I would ask for.Sarong
@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: [email protected]Lonnylonslesaunier
B
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.

Bignonia answered 30/4, 2020 at 8:50 Comment(2)
nice info, only linux currently: bugs.openjdk.java.net/browse/JDK-8219257Alliaceous
Right! I forgot to mention that!Bignonia
L
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...

Lonnylonslesaunier answered 29/4, 2020 at 16:52 Comment(3)
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?Sarong
Do you have a link to a bug report?Auklet
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 tooLonnylonslesaunier
C
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.

Cockney answered 29/4, 2020 at 16:51 Comment(2)
FWIW, I've also tested with the latest JDK 15 EA build from jdk.java.net. Also works fine there.Swallowtail
To add to the details as mentioned in Vicente's answer, 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?".Sarong
A
3

Remove Option --strip-debug

options = ['--compress', '2', '--no-header-files', '--no-man-pages']
Alliaceous answered 29/4, 2020 at 15:1 Comment(2)
it should rather be a bug if using --strip-debug starts failing the execution, isn't it?Sarong
@Aksel: Can you add something about why this would solve the problem?Bricklayer
B
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.

Bignonia answered 30/4, 2020 at 8:50 Comment(2)
nice info, only linux currently: bugs.openjdk.java.net/browse/JDK-8219257Alliaceous
Right! I forgot to mention that!Bignonia

© 2022 - 2024 — McMap. All rights reserved.