Home โบ Java exceptions โบ UnsupportedClassVersionError
UnsupportedClassVersionError: causes and fixes
A class was compiled for a newer Java version than the JVM running it.
What it looks like
java.lang.UnsupportedClassVersionError: com/acme/App has been compiled by a more recent version of the Java Runtime (class file version 65.0), this version of the Java Runtime only recognizes class file versions up to 61.0Extends ClassFormatError in java.lang.
What it means
Each Java release has a class file version number: 52 is Java 8, 55 is 11, 61 is 17, 65 is 21 and 69 is 25. The error means the code was compiled for a higher number than the runtime supports, so you compiled with a newer JDK than the one running the app. The message gives both numbers, so you can read the versions directly from it.
Common causes
- The build used JDK 21 but production or the CI runner has Java 17.
- A dependency was built for a newer Java than your runtime.
- An IDE using a different JDK than Maven or Gradle.
- The wrong
javaon the PATH or in the container base image.
How to fix it
- Run the same Java version everywhere, and run
java -versionandmvn -vto confirm which is used. - Set the target explicitly with
maven.compiler.release(Maven) orjava.toolchain(Gradle). - Upgrade the runtime or the container base image to the version you build for.
- Pick dependency versions that support your Java level.
Broken and fixed
<maven.compiler.release>21</maven.compiler.release> <!-- runtime is Java 17 --><maven.compiler.release>17</maven.compiler.release> <!-- matches the runtime -->๐ Unravel the failing code ๐ Unravel the fix
In Spring and enterprise code
Spring Boot 3 requires Java 17 or later. Seeing this error right after a Boot 3 upgrade usually means the server still runs Java 11.
Debug it faster
Paste the whole stack trace into the stack trace beautifier to hide framework frames, jump to the root cause and find the first line of your own code. It runs in your browser, so the trace never leaves your machine.
Frequently asked questions
Is UnsupportedClassVersionError a checked or unchecked exception?
UnsupportedClassVersionError is an Error (it extends ClassFormatError). Errors signal serious problems in the JVM or environment; applications normally should not catch them, and ordinary catch (Exception e) blocks will not.
Which package is UnsupportedClassVersionError in?
It lives in java.lang, so the import is import java.lang.UnsupportedClassVersionError; (java.lang needs no import).
What is the first thing to check when I see UnsupportedClassVersionError?
Read the message and the first stack trace line in your own code. The usual causes are: The build used JDK 21 but production or the CI runner has Java 17; and A dependency was built for a newer Java than your runtime.