{"record":{"id":"7a73e0a0b9ef3550","repo":"pinpoint-apm/pinpoint","slug":"already-exist-servicetype-servicetype-exist","errorCode":null,"errorMessage":"already exist. serviceType:${serviceType}, exist:${exist}","messagePattern":"already exist\\. serviceType:(.+?), exist:(.+?)","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"commons-profiler/src/main/java/com/navercorp/pinpoint/common/profiler/trace/ServiceTypeRegistry.java","lineNumber":122,"sourceCode":"\n        for (Map.Entry<String, List<ServiceType>> entry : table.entrySet()) {\n            List<ServiceType> newValue = Collections.unmodifiableList(entry.getValue());\n            copy.put(entry.getKey(), newValue);\n        }\n        return copy;\n    }\n\n    static class Builder {\n\n        private final Map<Integer, ServiceType> buildMap = new HashMap<>();\n\n        void addServiceType(ServiceType serviceType) {\n            Objects.requireNonNull(serviceType, \"serviceType\");\n\n            int code = serviceType.getCode();\n            final ServiceType exist = this.buildMap.put(code, serviceType);\n            if (exist != null) {\n                throw new IllegalStateException(\"already exist. serviceType:\" + serviceType + \", exist:\" + exist);\n            }\n        }\n\n        ServiceTypeRegistry build() {\n            return new ServiceTypeRegistry(buildMap);\n        }\n    }\n\n\n}\n","sourceCodeStart":104,"sourceCodeEnd":133,"githubUrl":"https://github.com/pinpoint-apm/pinpoint/blob/744c3d3075e595656abb1ae331ad2c0e4c9eb996/commons-profiler/src/main/java/com/navercorp/pinpoint/common/profiler/trace/ServiceTypeRegistry.java#L104-L133","documentation":"The registry builder's addServiceType registers a ServiceType keyed by its integer code. If a ServiceType with that code was already added, the put returns the previous entry and an IllegalStateException is thrown — service type codes must be globally unique. Unlike the name collision (error 333), this guard lives in the builder's add method and fires as soon as the duplicate is added.","triggerScenarios":"Calling builder.addServiceType() twice with ServiceTypes sharing the same int code, or adding a custom ServiceType whose code equals a built-in one (built-ins occupy fixed ranges, e.g. 1000-1999 server types).","commonSituations":"Custom plugin picks an arbitrary code that collides with a built-in or another plugin's code; loading two versions of a plugin that both define the same code; copy-pasting a type descriptor and only renaming the string but not the code.","solutions":["Assign the custom ServiceType an unused code (Pinpoint reserves 0-999 and defines 1000+ ranges; pick from the unallocated range documented for user plugins)","Check the 'exist' part of the message to see which type already holds the code and avoid it","Deduplicate the list of ServiceTypes before adding, e.g. with a check via getServiceType(code) first","Remove duplicate plugin jars from the classpath so types aren't registered twice"],"exampleFix":"// before\nbuilder.addServiceType(new DefaultServiceType(1010, \"MY_PLUGIN\", ...)); // 1010 taken\n// after\nbuilder.addServiceType(new DefaultServiceType(9001, \"MY_PLUGIN\", ...)); // free code","handlingStrategy":"validation","validationCode":"if (builder != null && registry.findServiceType(serviceType.getCode()) != null) {\n    throw new IllegalStateException(\"service type code already registered: \" + serviceType.getCode());\n}\nbuilder.addServiceType(serviceType);","typeGuard":null,"tryCatchPattern":"try {\n    builder.addServiceType(serviceType);\n} catch (IllegalStateException e) {\n    LOGGER.error(\"service type code collision: {}\", e.getMessage());\n}","preventionTips":["Pick custom codes from the documented user-plugin range (e.g. 9000+)","Check findServiceType(code) before adding","Never reuse a built-in code with only a renamed descriptor"],"tags":["duplicate-key","registry","service-type"],"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-14T05:17:10.506Z"}