Java errors
Introduction
A Java error names what went wrong, often with the file and the line. This page collects the errors that take the longest to place: a class built for a newer Java than the runtime that loads it, a release that the compiler no longer accepts, and a UTF-8 file that the compiler reads as windows-1252. The commands use the Hello.java of a first program.
UnsupportedClassVersionError
Error: A JNI error has occurred, please check your installation and try again Exception in thread "main" java.lang.UnsupportedClassVersionError: hudson/remoting/Launcher has been compiled by a more recent version of the Java Runtime (class file version 55.0), this version of the Java Runtime only recognizes class file versions up to 52.0 at java.lang.ClassLoader.defineClass1(Native Method) at java.lang.ClassLoader.defineClass(ClassLoader.java:756) at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142) at java.net.URLClassLoader.defineClass(URLClassLoader.java:468) at java.net.URLClassLoader.access$100(URLClassLoader.java:74) at java.net.URLClassLoader$1.run(URLClassLoader.java:369) at java.net.URLClassLoader$1.run(URLClassLoader.java:363) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(URLClassLoader.java:362) at java.lang.ClassLoader.loadClass(ClassLoader.java:418) at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:352) at java.lang.ClassLoader.loadClass(ClassLoader.java:351) at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:601) Agent JVM has terminated. Exit code=1
The numbers in the message are the whole answer: class file version 55.0 is Java 11 and 52.0 is Java 8, so the class was built by a newer Java than the runtime that loads it. Here the class is the remoting jar of Jenkins which has required Java 11 since 2.357: an agent on Java 8 fails before the build starts. Check the Java version on the agent host if you connect it directly, and in the Dockerfile if the agents run in Docker which is the newer approach.
The paste comes from a Java 8 runtime, so it prints the JNI line and the whole stack. A class file one version above 65.0, the newest version JDK 21 accepts, gives the same error with the numbers of this runtime:
Error: LinkageError occurred while loading main class Hello java.lang.UnsupportedClassVersionError: Hello has been compiled by a more recent version of the Java Runtime (class file version 66.0), this version of the Java Runtime only recognizes class file versions up to 65.0
java: error: release version 5 not supported
IntelliJ IDEA puts java: in front of the output of the compiler it runs; the compiler itself prints
javac --release 5 Hello.java
error: release version 5 not supported Usage: javac <options> <source files> use --help for a list of possible options
The error says that the JDK is above 8 and the bytecode you are compiling to is
version 5. After the eighth version, the bytecode of the fifth version is no longer
supported: JDK 21 accepts releases 8 to 21 and rejects 5 and 7.
This is one of the reasons version 8 is considered the most
«stable»
I do not recommend changing the JDK to 8; it is better to change the target bytecode.
In
IntelliJ IDEA
this can be done like this
File → Settings → Build, Execution, Deployment → Compiler → Target bytecode version → 14
14 is not obligatory, but you will clearly need something above 5
error: unmappable character (0x8F) for encoding windows-1252
If your code has comments in Russian and the compiler reads the file as windows-1252, it stops on the first bytes it cannot map. A comment with the letter я is enough:
javac -encoding windows-1252 Hello.java
Hello.java:2: error: unmappable character (0x8F) for encoding windows-1252 // � ^ 1 error
0x8F is the second byte of the UTF-8 letter я and windows-1252 has no character at that position. The compiler prints the source line decoded as windows-1252, so the letter appears as two strange characters, and the caret marks the byte. A longer comment gives the same error again.
The file is not broken: compile it as UTF-8, the encoding it is saved in:
javac -encoding UTF-8 Hello.java
The same file now builds and runs:
java Hello
Hello Java!
The commands and the output on this page were run with OpenJDK 21.0.13.1 on Alpine Linux 3.24.3 (x86_64) in a Docker container.
Article author: Arthur Isaev