Konloch/bytecode-viewer · error · IllegalArgumentException

Unknown constant pool tag ${tag}

Error message

Unknown constant pool tag ${tag}

What it means

Thrown by parseConstantPool in the Java class-file parser when the constant pool entry's tag byte is not one of the recognized JVM CONSTANT_* tags. The JVM spec defines tags 1-15 (Utf8, Integer, Float, Long, Double, Class, String, Fieldref, Methodref, InterfaceMethodref, NameAndType, MethodHandle, MethodType, Dynamic, InvokeDynamic, Module, Package); any other value indicates a malformed or unsupported class file. This is a fail-fast guard against silently mis-parsing corrupted input.

Source

Thrown at plugins/java/ClassParser.java:304

                    case ConstantType.CONSTANT_MethodHandle:
                        int referenceKind = buffer.get() & 0xFF;
                        int referenceIndex = buffer.getShort() & 0xFFFF;
                        cpList.add("[" + i + "] CONSTANT_MethodHandle: " + referenceKind + ":#" + referenceIndex);
                        break;

                    case ConstantType.CONSTANT_MethodType:
                        int descriptorIndex1 = buffer.getShort() & 0xFFFF;
                        cpList.add("[" + i + "] CONSTANT_MethodType: #" + descriptorIndex1);
                        break;

                    case ConstantType.CONSTANT_InvokeDynamic:
                        int bootstrapMethodAttrIndex = buffer.getShort() & 0xFFFF;
                        int nameAndTypeIndex3 = buffer.getShort() & 0xFFFF;
                        cpList.add("[" + i + "] CONSTANT_InvokeDynamic: #" + bootstrapMethodAttrIndex + ":#" + nameAndTypeIndex3);
                        break;

                    default:
                        throw new IllegalArgumentException("Unknown constant pool tag " + tag);
                }
            }
        }

        private String getRefTypeName(int tag)
        {
            switch (tag)
            {
                case ConstantType.CONSTANT_Fieldref:
                    return "Fieldref";
                case ConstantType.CONSTANT_Methodref:
                    return "Methodref";
                case ConstantType.CONSTANT_InterfaceMethodref:
                    return "InterfaceMethodref";
                default:
                    return "Unknown";
            }
        }

View on GitHub (pinned to 31430e0033)

Solutions

  1. Verify the input is a genuine class file (magic 0xCAFEBABE) before parsing.
  2. Check the class file's major version and use a parser/jvm version that supports that constant pool format.
  3. Re-obtain or re-download the class file; if it is corrupted, regenerate it from source.
  4. If you maintain the parser, add a case for the unknown tag or convert the throw into a skip/log for resilience.

Example fix

// before
if (!isClassFile(bytes)) parse(bytes); // throws deep in parser
// after
if (readMagic(bytes) != 0xCAFEBABE) { throw new InvalidClassFileException("not a class file"); }
parse(bytes);
Defensive patterns

Strategy: try-catch

Validate before calling

// check magic number + major version before parsing
if (bytes.length < 8 || (bytes[0]&0xFF)!=0xCA||(bytes[1]&0xFF)!=0xFE||(bytes[2]&0xFF)!=0xBA||(bytes[3]&0xFF)!=0xBE)
    throw new IllegalArgumentException("not a class file");

Type guard

boolean isKnownCpTag(int tag) {
    return (tag >= 1 && tag <= 15) || tag == 16 || tag == 17 || tag == 18 || tag == 19 || tag == 20;
}

Try / catch

try { parser.parseConstantPool(buffer); }
catch (IllegalArgumentException e) {
    if (e.getMessage().startsWith("Unknown constant pool tag")) {
        log.warn("unrecognized/unsupported class file: " + e.getMessage());
    } else throw e;
}

Prevention

When it happens

Trigger: Parsing a class file whose constant pool contains a tag byte outside the recognized set, e.g. a truncated, corrupted, or deliberately fuzzed .class file, a file from a newer JVM using a tag this parser doesn't implement, or a non-class file that is not validated by magic-number/header checks before reaching the parser.

Common situations: Fuzzing or security-testing bytecode tooling; processing class files compiled by a much newer JDK than the parser supports; accidentally passing a jar/zip or renamed text file to the class parser; corrupted downloads or partial writes of .class files.

Related errors


AI-assisted analysis of Konloch/bytecode-viewer@31430e0033 (2026-09-05). Data as JSON: /api/errors/95868904ee682f63. Report an issue: GitHub.