java runtime_error ai_generated true

java.lang.ClassFormatError: Constant pool tag 18 is invalid

ID: java/class-format-error-constant-pool-tag

Also available as: JSON · Markdown · 中文
85%Fix Rate
85%Confidence
1Evidence
2023-09-15First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
Java 8 active
Java 11 active
Java 17 active
Java 21 active

Root Cause

This error occurs when the JVM attempts to load a class file with an invalid or unsupported constant pool tag, typically caused by a mismatch between the class file version and the JVM version or corruption of the class file.

generic

中文

当 JVM 尝试加载具有无效或不支持的常量池标签的类文件时发生此错误,通常由类文件版本与 JVM 版本不匹配或类文件损坏引起。

Official Documentation

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

Workarounds

  1. 85% success Ensure all dependencies and the project are compiled with the same Java version. For Maven, set the maven-compiler-plugin source and target to match the runtime JVM.
    Ensure all dependencies and the project are compiled with the same Java version. For Maven, set the maven-compiler-plugin source and target to match the runtime JVM.
  2. 75% success If the error occurs from a third-party library, update the library to a version that matches your JVM, or exclude the problematic class and replace it with a newer version.
    If the error occurs from a third-party library, update the library to a version that matches your JVM, or exclude the problematic class and replace it with a newer version.
  3. 70% success Check the class file version using javap -verbose and ensure it is compatible with the JVM. Regenerate the class file if needed.
    Check the class file version using javap -verbose and ensure it is compatible with the JVM. Regenerate the class file if needed.

中文步骤

  1. Ensure all dependencies and the project are compiled with the same Java version. For Maven, set the maven-compiler-plugin source and target to match the runtime JVM.
  2. If the error occurs from a third-party library, update the library to a version that matches your JVM, or exclude the problematic class and replace it with a newer version.
  3. Check the class file version using javap -verbose and ensure it is compatible with the JVM. Regenerate the class file if needed.

Dead Ends

Common approaches that don't work:

  1. 90% fail

    Cleaning the project and rebuilding does not fix the underlying binary incompatibility or class corruption.

  2. 80% fail

    Recompiling with the same compiler version does not change the constant pool format; the issue is often from mixing class files from different Java versions.

  3. 95% fail

    The error is not related to JDK installation; reinstalling JDK does not fix class file corruption.