Aksel Willgert
Aksel Willgert

Reputation: 11547

Records in jlink:ed application throws exception

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)

Upvotes: 9

Views: 261

Answers (4)

Vicente Romero
Vicente Romero

Reputation: 1460

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...

Upvotes: 7

A. Sundararajan
A. Sundararajan

Reputation: 4405

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.

Upvotes: 6

davidd
davidd

Reputation: 665

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.

Upvotes: 3

Aksel Willgert
Aksel Willgert

Reputation: 11547

Remove Option --strip-debug

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

Upvotes: 3

Related Questions