{"record":{"id":"182f1320d9a2bf72","repo":"aeron-io/aeron","slug":"the-type-for-counterid-counterid-typeid-countertypeid-does","errorCode":null,"errorMessage":"The type for counterId=<counterId>, typeId=<counterTypeId> does not match the expected=<expectedCounterTypeId>","messagePattern":"The type for counterId=<counterId>, typeId=<counterTypeId> does not match the expected=<expectedCounterTypeId>","errorType":"validation","errorClass":"ConfigurationException","httpStatus":null,"severity":"error","filePath":"aeron-client/src/main/java/io/aeron/AeronCounters.java","lineNumber":1543,"sourceCode":"    /**\n     * Checks that the counter specified by {@code counterId} has the counterTypeId that matches the specified value.\n     * If not it will throw a {@link io.aeron.exceptions.ConfigurationException}.\n     *\n     * @param countersReader        to look up the counter type id.\n     * @param counterId             counter to reference.\n     * @param expectedCounterTypeId the expected type id for the counter.\n     * @throws io.aeron.exceptions.ConfigurationException if the type id does not match.\n     * @throws IllegalArgumentException                   if the counterId is not valid.\n     */\n    public static void validateCounterTypeId(\n        final CountersReader countersReader,\n        final int counterId,\n        final int expectedCounterTypeId)\n    {\n        final int counterTypeId = countersReader.getCounterTypeId(counterId);\n        if (expectedCounterTypeId != counterTypeId)\n        {\n            throw new ConfigurationException(\n                \"The type for counterId=\" + counterId +\n                    \", typeId=\" + counterTypeId +\n                    \" does not match the expected=\" + expectedCounterTypeId);\n        }\n    }\n\n    /**\n     * Convenience overload for {@link AeronCounters#validateCounterTypeId(CountersReader, int, int)}.\n     *\n     * @param aeron                 to resolve a counters' reader.\n     * @param counter               to be checked for the appropriate counterTypeId.\n     * @param expectedCounterTypeId the expected type id for the counter.\n     * @throws io.aeron.exceptions.ConfigurationException if the type id does not match.\n     * @throws IllegalArgumentException                   if the counterId is not valid.\n     * @see AeronCounters#validateCounterTypeId(CountersReader, int, int)\n     */\n    public static void validateCounterTypeId(\n        final Aeron aeron,","sourceCodeStart":1525,"sourceCodeEnd":1561,"githubUrl":"https://github.com/aeron-io/aeron/blob/6d60124e15e35c11b49ba2e3c2c2858a09a18803/aeron-client/src/main/java/io/aeron/AeronCounters.java#L1525-L1561","documentation":"AeronCounters validation throws this ConfigurationException when the counter at counterId has a typeId that does not match the expected type. Counter typeIds identify the counter's semantics (Aeron reserves ids below 1000), so reading or allocating with the wrong expected type would misinterpret the counter; the helper validates before use.","triggerScenarios":"Calling AeronCounters.validateCounterTypeId (directly or via allocation/lookup helpers) with an expectedCounterTypeId that differs from the typeId actually registered at counterId in the CountersReader — e.g. expecting a stream-position counter but the id points at a rate counter or a freed-and-reused counter slot.","commonSituations":"Cacheing counter ids across driver restarts where ids get reallocated to different counter types; looking up counters by label/index and assuming the wrong type; applications allocating custom counters with typeIds colliding with expected Aeron types.","solutions":["Re-resolve the counter id by searching the CountersReader for the correct label/type rather than reusing a stale id","Pass the correct expectedCounterTypeId constant for the counter you actually allocated/looked up","Verify the driver did not restart (freeing counters) between capturing the id and validating it"],"exampleFix":"// before\nint counterId = findAnyCounterWithName(counters, \"my-rate\");\nAeronCounters.validateCounterTypeId(counters, counterId, AeronCounters.SYSTEM_COUNTER_TYPE_ID); // wrong expected type\n// after\nint counterId = findCounter(counters, \"my-rate\", MY_APP_RATE_COUNTER_TYPE_ID);\nAeronCounters.validateCounterTypeId(counters, counterId, MY_APP_RATE_COUNTER_TYPE_ID);","handlingStrategy":"validation","validationCode":"int actual = countersReader.getCounterTypeId(counterId); if (actual != expectedCounterTypeId) { /* resolve correct id before proceeding */ }","typeGuard":"boolean isCounterOfType(CountersReader r, int counterId, int typeId) { return r.getCounterTypeId(counterId) == typeId; }","tryCatchPattern":"try { AeronCounters.validateCounterTypeId(counters, counterId, expectedTypeId); } catch (ConfigurationException e) { if (e.getMessage().startsWith(\"The type for counterId\")) { counterId = relookupCounterByLabel(counters, expectedTypeId); } else throw e; }","preventionTips":["Never cache counter ids across driver restarts; re-resolve by label and type","Define app counter typeIds as named constants (>= 1000) and use them consistently","Validate typeId immediately after any counter lookup"],"tags":["counters","type-mismatch","validation","type-id"],"backgroundTag":"type-mismatch","analyzedSha":"6d60124e15e35c11b49ba2e3c2c2858a09a18803","analyzedAt":"2026-09-12T11:17:07.683Z","contentChangedAt":"2026-09-12T11:17:07.683Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}