{"record":{"id":"69da206eec32745d","repo":"pinpoint-apm/pinpoint","slug":"annotationkey-code-of-pair-is-duplicated-with","errorCode":null,"errorMessage":"AnnotationKey code of ${pair} is duplicated with ${prev}","messagePattern":"AnnotationKey code of (.+?) is duplicated with (.+?)","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"commons-profiler/src/main/java/com/navercorp/pinpoint/common/profiler/trace/TraceMetadataLoader.java","lineNumber":260,"sourceCode":"                logger.info(serviceTypePairToString(serviceType));\n            }\n        }\n\n        private int getCode(Pair<ServiceType> p) {\n            return p.value.getCode();\n        }\n    }\n\n    private class AnnotationKeyChecker {\n        private final Map<Integer, Pair<AnnotationKey>> annotationKeyCodeMap = new HashMap<>();\n\n        private void check(AnnotationKey key, TraceMetadataProvider provider) {\n            Pair<AnnotationKey> pair = new Pair<>(key, provider);\n            Pair<AnnotationKey> prev = annotationKeyCodeMap.put(key.getCode(), pair);\n    \n            if (prev != null) {\n                // TODO change exception type\n                throw new RuntimeException(\"AnnotationKey code of \" + annotationKeyPairToString(pair) + \" is duplicated with \" + annotationKeyPairToString(prev));\n            }\n        }\n\n        private void logResult() {\n            logger.info(\"Finished loading AnnotationKeys:\");\n\n            List<Pair<AnnotationKey>> annotationKeys = new ArrayList<>(annotationKeyCodeMap.values());\n            annotationKeys.sort(Comparator.comparingInt(this::getCode));\n\n            for (Pair<AnnotationKey> annotationKey : annotationKeys) {\n                logger.info(annotationKeyPairToString(annotationKey));\n            }\n        }\n\n        private int getCode(Pair<AnnotationKey> a) {\n            return a.value.getCode();\n        }\n    }","sourceCodeStart":242,"sourceCodeEnd":278,"githubUrl":"https://github.com/pinpoint-apm/pinpoint/blob/744c3d3075e595656abb1ae331ad2c0e4c9eb996/commons-profiler/src/main/java/com/navercorp/pinpoint/common/profiler/trace/TraceMetadataLoader.java#L242-L278","documentation":"TraceMetadataLoader.check registers AnnotationKeys into a code->pair map while loading TraceMetadataProviders. If two providers declare AnnotationKeys with the same integer code, the second put returns the previous entry and this RuntimeException is thrown, aborting metadata loading. It is a deliberate duplicate-registration guard so annotation codes stay unambiguous across providers.","triggerScenarios":"Calling TraceMetadataLoader.load (via ServiceTypeRegistry/AnnotationKeyRegistry building) when two loaded TraceMetadataProvider implementations both return AnnotationKey objects with the same getCode() value from their addAnnotationKeys/addAllAnnotationKeys callbacks.","commonSituations":"A plugin bundle and a custom provider both define AnnotationKey with a hand-picked code that collides with Pinpoint's built-in codes (e.g. reusing code 1/10/9000); two versions of a plugin jar on the classpath each registering the same keys; copy-pasting an AnnotationKey definition and forgetting to change the code.","solutions":["Find the two AnnotationKey definitions named in the message and change your custom key's code to an unused value (use AnnotationKeyFactory / pick a code outside Pinpoint's reserved ranges, e.g. a high vendor range).","Check the classpath for duplicate plugin jars or stale old versions of your provider and remove them.","Verify all TraceMetadataProviders registered via ServiceLoader are intentional; remove test/development providers from the deployment."],"exampleFix":"// before\npublic static final AnnotationKey MY_KEY = AnnotationKeyFactory.of(1200, \"MY_KEY\");\n// after\npublic static final AnnotationKey MY_KEY = AnnotationKeyFactory.of(9500, \"MY_KEY\"); // unused code","handlingStrategy":"validation","validationCode":"// before loading, ensure unique codes across providers\nMap<Integer, String> seen = new HashMap<>();\nfor (AnnotationKey key : myProvider.getAnnotationKeys()) {\n    String prev = seen.putIfAbsent(key.getCode(), key.getName());\n    if (prev != null) throw new IllegalStateException(\"Duplicate AnnotationKey code \" + key.getCode());\n    seen.put(key.getCode(), key.getName());\n}","typeGuard":null,"tryCatchPattern":"try {\n    loader.load(provider);\n} catch (RuntimeException e) {\n    if (e.getMessage() != null && e.getMessage().contains(\"is duplicated with\")) {\n        logger.error(\"Duplicate AnnotationKey code in provider\", e); // fail fast, fix codes\n    } else { throw e; }\n}","preventionTips":["Pick custom AnnotationKey codes from a documented unused high range (never reuse built-in Pinpoint codes).","Grep the classpath/plugins for duplicate provider jars before deployment.","Keep a central registry of assigned codes across your team's plugins.","Write a unit test that loads all your providers and asserts no duplicate codes."],"tags":["java","duplicate-registration","classpath","pinpoint"],"backgroundTag":"internal-invariant-violation","analyzedSha":"744c3d3075e595656abb1ae331ad2c0e4c9eb996","analyzedAt":"2026-09-07T18:48:45.289Z","contentChangedAt":"2026-09-07T18:48:45.289Z","schemaVersion":2},"datasetVersion":"2026-09-17T15:17:12.973Z"}