aeron-io/aeron · error · ConfigurationException

The type for counterId=

Error message

The type for counterId=<counterId>, typeId=<counterTypeId> does not match the expected=<expectedCounterTypeId>

What it means

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.

Solutions

  1. Re-resolve the counter id by searching the CountersReader for the correct label/type rather than reusing a stale id
  2. Pass the correct expectedCounterTypeId constant for the counter you actually allocated/looked up
  3. Verify the driver did not restart (freeing counters) between capturing the id and validating it

Example fix

// before
int counterId = findAnyCounterWithName(counters, "my-rate");
AeronCounters.validateCounterTypeId(counters, counterId, AeronCounters.SYSTEM_COUNTER_TYPE_ID); // wrong expected type
// after
int counterId = findCounter(counters, "my-rate", MY_APP_RATE_COUNTER_TYPE_ID);
AeronCounters.validateCounterTypeId(counters, counterId, MY_APP_RATE_COUNTER_TYPE_ID);
Defensive patterns

Strategy: validation

Validate before calling

int actual = countersReader.getCounterTypeId(counterId); if (actual != expectedCounterTypeId) { /* resolve correct id before proceeding */ }

Type guard

boolean isCounterOfType(CountersReader r, int counterId, int typeId) { return r.getCounterTypeId(counterId) == typeId; }

Try / catch

try { AeronCounters.validateCounterTypeId(counters, counterId, expectedTypeId); } catch (ConfigurationException e) { if (e.getMessage().startsWith("The type for counterId")) { counterId = relookupCounterByLabel(counters, expectedTypeId); } else throw e; }

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Understand the failure class

Background: Type mismatch errors: IllegalArgumentException, TypeError and type guards across 150 open-source libraries — this error's family across 150 libraries.

Related errors


AI-assisted analysis of aeron-io/aeron@6d60124e15 (2026-09-12). Data as JSON: /api/errors/182f1320d9a2bf72. Report an issue: GitHub.

Appendix: source

Thrown at aeron-client/src/main/java/io/aeron/AeronCounters.java:1543

    /**
     * Checks that the counter specified by {@code counterId} has the counterTypeId that matches the specified value.
     * If not it will throw a {@link io.aeron.exceptions.ConfigurationException}.
     *
     * @param countersReader        to look up the counter type id.
     * @param counterId             counter to reference.
     * @param expectedCounterTypeId the expected type id for the counter.
     * @throws io.aeron.exceptions.ConfigurationException if the type id does not match.
     * @throws IllegalArgumentException                   if the counterId is not valid.
     */
    public static void validateCounterTypeId(
        final CountersReader countersReader,
        final int counterId,
        final int expectedCounterTypeId)
    {
        final int counterTypeId = countersReader.getCounterTypeId(counterId);
        if (expectedCounterTypeId != counterTypeId)
        {
            throw new ConfigurationException(
                "The type for counterId=" + counterId +
                    ", typeId=" + counterTypeId +
                    " does not match the expected=" + expectedCounterTypeId);
        }
    }

    /**
     * Convenience overload for {@link AeronCounters#validateCounterTypeId(CountersReader, int, int)}.
     *
     * @param aeron                 to resolve a counters' reader.
     * @param counter               to be checked for the appropriate counterTypeId.
     * @param expectedCounterTypeId the expected type id for the counter.
     * @throws io.aeron.exceptions.ConfigurationException if the type id does not match.
     * @throws IllegalArgumentException                   if the counterId is not valid.
     * @see AeronCounters#validateCounterTypeId(CountersReader, int, int)
     */
    public static void validateCounterTypeId(
        final Aeron aeron,

View on GitHub (pinned to 6d60124e15)