java runtime_error ai_generated true

java.lang.UnsupportedClassVersionError: org/example/MyClass has been compiled by a more recent version of the Java Runtime (class file version 61.0), this version of the Java Runtime only recognizes class file versions up to 52.0

ID: java/unsupported-major-minor-version

Also available as: JSON · Markdown · 中文
92%Fix Rate
90%Confidence
1Evidence
2023-03-10First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
Java 8 (class version 52.0) active
Java 11 (class version 55.0) active
Java 17 (class version 61.0) active
Java 21 (class version 65.0) active

Root Cause

The compiled class file has a major version (e.g., 61 for Java 17) higher than what the running JVM supports (e.g., 52 for Java 8), indicating a mismatch between compile-time and runtime Java versions.

generic

中文

编译的类文件的主版本(例如 Java 17 的 61)高于正在运行的 JVM 支持的版本(例如 Java 8 的 52),表明编译时和运行时的 Java 版本不匹配。

Official Documentation

https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/lang/UnsupportedClassVersionError.html

Workarounds

  1. 95% success Upgrade the runtime JVM to match the compilation version. For example, if class version is 61.0, run with Java 17 or later. Set JAVA_HOME and update PATH accordingly.
    Upgrade the runtime JVM to match the compilation version. For example, if class version is 61.0, run with Java 17 or later. Set JAVA_HOME and update PATH accordingly.
  2. 90% success Recompile the source code with a lower target version using javac -source 8 -target 8 (or --release 8) if the source is available.
    Recompile the source code with a lower target version using javac -source 8 -target 8 (or --release 8) if the source is available.
  3. 85% success Use a dependency management tool like Maven to enforce a consistent Java version across modules by setting <maven.compiler.source> and <maven.compiler.target> properties.
    Use a dependency management tool like Maven to enforce a consistent Java version across modules by setting <maven.compiler.source> and <maven.compiler.target> properties.

中文步骤

  1. Upgrade the runtime JVM to match the compilation version. For example, if class version is 61.0, run with Java 17 or later. Set JAVA_HOME and update PATH accordingly.
  2. Recompile the source code with a lower target version using javac -source 8 -target 8 (or --release 8) if the source is available.
  3. Use a dependency management tool like Maven to enforce a consistent Java version across modules by setting <maven.compiler.source> and <maven.compiler.target> properties.

Dead Ends

Common approaches that don't work:

  1. Set JAVA_HOME to an older JDK version and recompile 80% fail

    This downgrades the runtime but the compiled classes still have the higher version; the error occurs at runtime, not compile time.

  2. Add --release flag to the compiler without changing the JDK 70% fail

    The --release flag only works if the correct JDK version is used; using it with an older JDK may still produce incompatible class files.

  3. Delete the JAR file and rebuild with same JDK 90% fail

    If the build environment hasn't changed, the same version mismatch will persist.