oracle/graal · error · RuntimeException

Invalid character at index ${cur} in signature: ${signature}

Error message

Invalid character at index ${cur} in signature: ${signature}

What it means

While walking a JVM type descriptor, APHotSpotSignature.parseSignature accepts only primitives ('V','I','B','C','D','F','J','S','Z'), 'L...;' class references and '[' array prefixes. Any other character at the current index throws RuntimeException naming the index and the full signature. This is the generic 'malformed descriptor' error for substitution processors that read signature strings from annotations.

Source

Thrown at compiler/src/jdk.graal.compiler.processor/src/jdk/graal/compiler/replacements/processor/APHotSpotSignature.java:96

        switch (first) {
            case 'L':
                while (signature.charAt(cur) != ';') {
                    cur++;
                }
                cur++;
                break;
            case 'V':
            case 'I':
            case 'B':
            case 'C':
            case 'D':
            case 'F':
            case 'J':
            case 'S':
            case 'Z':
                break;
            default:
                throw new RuntimeException("Invalid character at index " + cur + " in signature: " + signature);
        }
        return cur;
    }

    public int getParameterCount(boolean withReceiver) {
        return arguments.size() + (withReceiver ? 1 : 0);
    }

    public TypeMirror getParameterType(ProcessingEnvironment env, int index) {
        if (argumentTypes == null) {
            argumentTypes = new TypeMirror[arguments.size()];
        }
        TypeMirror type = argumentTypes[index];
        if (arguments.get(index) == null) {
            throw new RuntimeException(String.format("Invalid argument at index %s.", index));
        }

        if (type == null) {

View on GitHub (pinned to a66e9ccd1d)

Solutions

  1. Rewrite the descriptor using JVM type syntax: primitives as I/B/C/D/F/J/S/Z, objects as 'Lfully/qualified/Name;' (semicolons mandatory), arrays as '[' prefixes.
  2. Use the index in the message to locate the exact bad character.
  3. Cross-check the descriptor with javap -s output for the target method.
  4. Prefer generating descriptors via MethodType.toMethodDescriptorString when building them programmatically.

Example fix

// before
new APHotSpotSignature("(LFoo)V"); // missing ';' after Foo

// after
new APHotSpotSignature("(LFoo;)V");
Defensive patterns

Strategy: validation

Validate before calling

static int checkDescriptor(String sig, int i) {
    char c = sig.charAt(i);
    if (c == '[') return checkDescriptor(sig, i + 1);
    if ("VIBCDFJSZ".indexOf(c) >= 0) return i + 1;
    if (c == 'L') {
        int semi = sig.indexOf(';', i);
        if (semi < 0) throw new IllegalArgumentException("missing ';' at " + i);
        return semi + 1;
    }
    throw new IllegalArgumentException("bad char '" + c + "' at " + i + " in " + sig);
}

// validate each parameter/return chunk before constructing APHotSpotSignature

Try / catch

try {
    new APHotSpotSignature(descriptor);
} catch (RuntimeException e) {
    // message contains 'Invalid character at index N': use N to fix that exact spot
    reportMalformedDescriptor(descriptor, e);
}

Prevention

When it happens

Trigger: A descriptor containing an invalid character where a type is expected: '(Q;)V', '(LFoo)V' (missing semicolon), '()X' or a stray space '(I I)V'. The switch in parseSignature falls through to default and throws at APHotSpotSignature.java:96. The reported index points at the first bad character.

Common situations: Typos in hand-written signature strings in replacement/intrinsics annotations; missing ';' after L<class> entries; using Java source syntax ('int') instead of descriptor syntax ('I'); unicode/whitespace accidentally pasted into the annotation value.

Understand the failure class

Related errors


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