pinpoint-apm/pinpoint · warning · java.util.NoSuchElementException

NoSuchElementException

Error message

NoSuchElementException

What it means

findAnnotationKeyByName looks up an AnnotationKey by its display name in the registry's name table. When no key with that name is registered, the method throws NoSuchElementException rather than returning null — callers are expected to only query names that exist. The exception message is the missing key name itself.

Source

Thrown at commons-profiler/src/main/java/com/navercorp/pinpoint/common/profiler/trace/AnnotationKeyRegistry.java:89

            }
        }
        return table;
    }

    @Override
    public AnnotationKey findAnnotationKey(int code) {
        final AnnotationKey annotationKey = codeLookupTable.get(code);
        if (annotationKey == null) {
            return AnnotationKey.UNKNOWN;
        }
        return annotationKey;
    }

    @Override
    public AnnotationKey findAnnotationKeyByName(String keyName) {
        final AnnotationKey annotationKey = nameLookupTable.get(keyName);
        if (annotationKey == null) {
            throw new NoSuchElementException(keyName);
        }
        return annotationKey;
    }

    @Override
    public AnnotationKey findApiErrorCode(int annotationCode) {
        return this.apiErrorLookupTable.get(annotationCode);
    }

    static class Builder {

        private final Map<Integer, AnnotationKey> buildMap = new HashMap<>();

        void addAnnotationKey(AnnotationKey annotationKey) {
            Objects.requireNonNull(annotationKey, "annotationKey");

            int code = annotationKey.getCode();
            final AnnotationKey exist = this.buildMap.put(code, annotationKey);

View on GitHub (pinned to 744c3d3075)

Solutions

  1. Use findAnnotationKeyByNameOrNull or check registration first if a lenient lookup is desired (check the AnnotationKeyRegistry API surface for the nullable variant)
  2. Fix the key name string to match the registered AnnotationKey's getName() exactly
  3. Ensure the plugin that defines the annotation key is actually loaded before querying
  4. For optional lookups, wrap in try-catch on NoSuchElementException and handle absence

Example fix

// before
AnnotationKey key = registry.findAnnotationKeyByName("unknown.key"); // throws
// after
AnnotationKey key;
try {
    key = registry.findAnnotationKeyByName("my.data");
} catch (NoSuchElementException e) {
    key = AnnotationKey.UNKNOWN; // or log and skip
}
Defensive patterns

Strategy: try-catch

Validate before calling

AnnotationKey key = registry.findAnnotationKeyByNameOrNull(keyName); // lenient variant, if available
if (key == null) {
    LOGGER.warn("annotation key name not registered: {}", keyName);
}

Type guard

boolean isRegisteredKey(AnnotationKeyRegistry r, String name) {
    try { r.findAnnotationKeyByName(name); return true; }
    catch (NoSuchElementException e) { return false; }
}

Try / catch

try {
    AnnotationKey key = registry.findAnnotationKeyByName(keyName);
} catch (NoSuchElementException e) {
    // missing key name: use AnnotationKey.UNKNOWN or skip
}

Prevention

When it happens

Trigger: Calling findAnnotationKeyByName("...") with a name that no registered AnnotationKey uses — a typo in the name, a key from a plugin that isn't loaded, or a name whose registration was skipped because the plugin failed to initialize.

Common situations: Metaspace/verification utilities (unregisteredAnnotationKeyTest, verifyAnnotationKey in the codebase) checking that keys referenced elsewhere are registered; UI/server code resolving annotation names from stored spans whose defining plugin is absent in this deployment.

Understand the failure class

Background: Record Not Found Errors: "not found", RecordNotFound, and "was not found" — what they mean and how to fix them — this error's family across 28 libraries.

Related errors


AI-assisted analysis of pinpoint-apm/pinpoint@744c3d3075 (2026-09-07). Data as JSON: /api/errors/37809eb7afb9a737. Report an issue: GitHub.