oracle/graal · error · GraalError

Unexpected constant pool tag %s

Error message

Unexpected constant pool tag %s

What it means

lookupConstant (the ldc equivalent of this constant-pool implementation) only knows how to materialize primitive constants, CONSTANT_Class, and CONSTANT_String. Any other tag reaching the switch hits default and GraalError('Unexpected constant pool tag') is thrown.

Source

Thrown at compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/replacements/classfile/ClassfileConstantPool.java:252

    public Object lookupConstant(int index) {
        return lookupConstant(index, true);
    }

    @Override
    public Object lookupConstant(int index, boolean resolve) {
        ClassfileConstant c = entries[index];
        if (c instanceof Primitive) {
            Primitive p = (Primitive) c;
            return p.value;
        }
        switch (c.tag) {
            case CONSTANT_Class:
                final int opcode = -1;
                return lookupType(index, opcode);
            case ClassfileConstant.CONSTANT_String:
                return ((ClassfileConstant.StringRef) c).getValue(this);
            default:
                throw new GraalError("Unexpected constant pool tag %s", c.tag);
        }
    }

    @Override
    public JavaConstant lookupAppendix(int index, int opcode) {
        if (opcode == Bytecodes.INVOKEVIRTUAL) {
            return null;
        }
        throw GraalError.shouldNotReachHereUnexpectedValue(opcode); // ExcludeFromJacocoGeneratedReport
    }
}

View on GitHub (pinned to a66e9ccd1d)

Solutions

  1. Remove ldc of MethodType/MethodHandle/condy constants from code parsed as snippets.
  2. If the constant snuck in via compilation of a lambda or bootstrap-linked construct, rewrite that code in plain form (anonymous class / direct calls).
Defensive patterns

Strategy: validation

Prevention

When it happens

Trigger: A class parsed by ClassfileBytecodeProvider executes ldc of a constant whose pool entry is a MethodType, MethodHandle, or Dynamic entry (condy), e.g. from lambda desugaring or explicit MethodType constants.

Common situations: Snippet code that references MethodType/MethodHandle constants or other condy-bearing constructs; same root cause family as the INVOKEDYNAMIC errors of this provider.

Related errors


AI-assisted analysis of oracle/graal@a66e9ccd1d (2026-08-14). Data as JSON: /api/errors/7b3538d21b3f18ef. Report an issue: GitHub.