The problem
I need to use JDK10 to compile a legacy project I have to work on. I know it is a short-term support release whose lifetime has ended. But before the project is updated to a newer Java version I need to be able to build and run it on my development machine.
Note: The project does build correctly on its CI pipeline and does run on the production environment. The problem is not related to the project but to my machine.
The problem I am running into is I cannot compile any java code with JDK10, but other JDKs such as 8, 9, 11, 12 and 17 do work.
Reproduce the problem
To showcase my problem, I am trying to compile a simple hello world program Test.java
:
public class Test {
public static void main(String[] args) {
System.out.println("Hello, world!");
}
}
I am using the prebuilt JDK from OpenJDK, but I have also tried and reproduced this problem with the Zulu distribution.
I can consistently reproduce the problem with:
$ wget https://download.java.net/java/GA/jdk10/10.0.2/19aef61b38124481863b1413dce1855f/13/openjdk-10.0.2_linux-x64_bin.tar.gz
...
2022-10-24 14:10:31 (11,1 MB/s) - ‘openjdk-10.0.2_linux-x64_bin.tar.gz’ saved [204892533/204892533]
$ tar -xzf openjdk-10.0.2_linux-x64_bin.tar.gz
$ jdk-10.0.2/bin/java -version
openjdk version "10.0.2" 2018-07-17
OpenJDK Runtime Environment 18.3 (build 10.0.2+13)
OpenJDK 64-Bit Server VM 18.3 (build 10.0.2+13, mixed mode)
$ jdk-10.0.2/bin/javac -version
javac 10.0.2
$ jdk-10.0.2/bin/javac Test.java
Exception in thread "main" java.lang.ClassFormatError: Ille in class file <Unknown>
at java.base/jdk.internal.misc.Unsafe.defineAnonymousClass0(Native Method)
at java.base/jdk.internal.misc.Unsafe.defineAnonymousClass(Unsafe.java:1223)
at java.base/java.lang.invoke.InnerClassLambdaMetafactory.spinInnerClass(InnerClassLambdaMetafactory.java:320)
at java.base/java.lang.invoke.InnerClassLambdaMetafactory.buildCallSite(InnerClassLambdaMetafactory.java:188)
at java.base/java.lang.invoke.LambdaMetafactory.metafactory(LambdaMetafactory.java:317)
at java.base/java.lang.invoke.CallSite.makeSite(CallSite.java:330)
at java.base/java.lang.invoke.MethodHandleNatives.linkCallSiteImpl(MethodHandleNatives.java:250)
at java.base/java.lang.invoke.MethodHandleNatives.linkCallSite(MethodHandleNatives.java:240)
at jdk.compiler/com.sun.tools.javac.code.Symtab.doEnterClass(Symtab.java:700)
at jdk.compiler/com.sun.tools.javac.code.Symtab.enterClass(Symtab.java:714)
at jdk.compiler/com.sun.tools.javac.code.Symtab.enterClass(Symtab.java:275)
at jdk.compiler/com.sun.tools.javac.code.Symtab.<init>(Symtab.java:485)
at jdk.compiler/com.sun.tools.javac.code.Symtab.instance(Symtab.java:89)
at jdk.compiler/com.sun.tools.javac.comp.Attr.<init>(Attr.java:128)
at jdk.compiler/com.sun.tools.javac.comp.Attr.instance(Attr.java:119)
at jdk.compiler/com.sun.tools.javac.comp.Annotate.<init>(Annotate.java:109)
at jdk.compiler/com.sun.tools.javac.comp.Annotate.instance(Annotate.java:84)
at jdk.compiler/com.sun.tools.javac.jvm.ClassReader.<init>(ClassReader.java:235)
at jdk.compiler/com.sun.tools.javac.jvm.ClassReader.instance(ClassReader.java:228)
at jdk.compiler/com.sun.tools.javac.code.ClassFinder.<init>(ClassFinder.java:180)
at jdk.compiler/com.sun.tools.javac.code.ClassFinder.instance(ClassFinder.java:173)
at jdk.compiler/com.sun.tools.javac.main.JavaCompiler.<init>(JavaCompiler.java:386)
at jdk.compiler/com.sun.tools.javac.main.JavaCompiler.instance(JavaCompiler.java:115)
at jdk.compiler/com.sun.tools.javac.main.Main.compile(Main.java:291)
at jdk.compiler/com.sun.tools.javac.main.Main.compile(Main.java:165)
at jdk.compiler/com.sun.tools.javac.Main.compile(Main.java:57)
at jdk.compiler/com.sun.tools.javac.Main.main(Main.java:43)
Already checked
Other JDKs
With java 11 it works:
$ wget https://download.java.net/java/GA/jdk11/9/GPL/openjdk-11.0.2_linux-x64_bin.tar.gz
...
2022-10-24 14:08:42 (10,6 MB/s) - ‘openjdk-11.0.2_linux-x64_bin.tar.gz’ saved [187513052/187513052]
$ tar -xzf openjdk-11.0.2_linux-x64_bin.tar.gz
$ jdk-11.0.2/bin/java -version
openjdk version "11.0.2" 2019-01-15
OpenJDK Runtime Environment 18.9 (build 11.0.2+9)
OpenJDK 64-Bit Server VM 18.9 (build 11.0.2+9, mixed mode)
$ jdk-11.0.2/bin/javac -version
javac 11.0.2
$ jdk-11.0.2/bin/javac Test.java
$ jdk-11.0.2/bin/java Test
Hello, world!
It also works with java 9:
$ wget https://download.java.net/java/GA/jdk9/9.0.4/binaries/openjdk-9.0.4_linux-x64_bin.tar.gz
...
2022-10-24 14:31:05 (11,0 MB/s) - ‘openjdk-9.0.4_linux-x64_bin.tar.gz’ saved [206018615/206018615]
$ tar -xzf openjdk-9.0.4_linux-x64_bin.tar.gz
$ jdk-9.0.4/bin/java -version
openjdk version "9.0.4"
OpenJDK Runtime Environment (build 9.0.4+11)
OpenJDK 64-Bit Server VM (build 9.0.4+11, mixed mode)
$ jdk-9.0.4/bin/javac -version
javac 9.0.4
$ jdk-9.0.4/bin/javac Test.java
$ jdk-9.0.4/bin/java Test
Hello, world!
Same goes with java 8, 12 and 17.
I have also tried the Zulu distributions.
Fresh install
I have tried installing a fresh Ubuntu 22.04 Desktop image on a VirtualBox. The problem cannot be reproduced. When downloading openjdk 10 and compiling/running the simple Test.java
file, it does work as expected. It has to be related to my machine configuration.
OS information
Here are some details about my OS:
$ cat /etc/os-release
PRETTY_NAME="Ubuntu 22.04.1 LTS"
NAME="Ubuntu"
VERSION_ID="22.04"
VERSION="22.04.1 LTS (Jammy Jellyfish)"
VERSION_CODENAME=jammy
ID=ubuntu
ID_LIKE=debian
HOME_URL="https://www.ubuntu.com/"
SUPPORT_URL="https://help.ubuntu.com/"
BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/"
PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy"
UBUNTU_CODENAME=jammy
$ uname --all
Linux Work-Miguel 5.15.0-52-generic #58-Ubuntu SMP Thu Oct 13 08:03:55 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux