quarkusio/quarkus · error · RuntimeException

Incorrect family size: " + pokemons.size() + ", expected: "

Error message

Incorrect family size: " + pokemons.size() + ", expected: " + expectedSize

What it means

Assertion inside verifyReadWriteCollection: loads Trainer id=1 and checks its Pokemon collection has the expected size, throwing this RuntimeException on mismatch. The test verifies that the collection second-level cache (read-write strategy) returns the correct collection contents after cached access.

Source

Thrown at integration-tests/hibernate-orm-cache/src/main/java/io/quarkus/it/hibernate/orm/cache/HibernateOrmCacheTestEndpoint.java:301

            final Pokemon golem = new Pokemon(76, "Alolan Golem", 2233);
            em.persist(golem);
            pokemons.add(golem);
        });

        assertRegionStats(counts);
    }

    private void verifyReadWriteCollection(int expectedSize,
            Map<String, Counts> counts) {
        clearStatistics();

        QuarkusTransaction.requiringNew().run(() -> {
            final Trainer t1 = em.find(Trainer.class, 1L);
            final List<Pokemon> pokemons = t1.getPokemons();

            if (pokemons.size() != expectedSize)
                throw new RuntimeException("Incorrect family size: " + pokemons.size() + ", expected: " + expectedSize);
        });

        assertRegionStats(counts);
    }

    private void testNonStrictReadWrite() {
        // NONSTRICT_READ_WRITE with JCache does not cache on insert
        storeTestItems(new Counts(0, 0, 0, 0));

        // Loading items will populate the cache (puts on read)
        final String[] expected = { "Hibernate T-shirt", "Hibernate Sticker", "Hibernate Mug" };
        verifyFindByIdItems(expected, new Counts(3, 0, 3, 3));

        // Modifying items will load from cache, then evict cache entries (numElements=0 after)
        final String[] newValues = { "Infinispan T-shirt", "Infinispan Sticker", "Infinispan Mug" };
        updateItemDescriptions(newValues, new Counts(0, 3, 0, 0));

        // Verify descriptions after update - cache was evicted, will reload from DB

View on GitHub (pinned to e1c734241f)

Solutions

  1. Evict the Trainer collection region (and Pokemon entity region) before verifying
  2. Reset/seed the database consistently before the test so Trainer 1 has exactly the expected Pokemons
  3. Verify the @Cache annotation on the Trainer.getPokemons() collection uses the intended strategy
  4. Clear the whole second-level cache between test runs

Example fix

// before
final List<Pokemon> pokemons = t1.getPokemons();
if (pokemons.size() != expectedSize) throw ...
// after
sessionFactory.getCache().evictCollection(Trainer.class.getName() + ".pokemons", 1L);
final List<Pokemon> pokemons = t1.getPokemons();
if (pokemons.size() != expectedSize) throw ...
Defensive patterns

Strategy: validation

Validate before calling

Trainer t1 = em.find(Trainer.class, 1L);
if (t1 == null) throw new IllegalStateException("Trainer 1 not seeded");
sessionFactory.getCache().evictCollection(Trainer.class.getName() + ".pokemons", 1L);

Try / catch

try {
    verifyReadWriteCollection(expectedSize);
} catch (RuntimeException e) {
    sessionFactory.getCache().evictCollection(Trainer.class.getName() + ".pokemons", 1L);
    // reload and re-check to distinguish stale collection cache from bad seed data
}

Prevention

When it happens

Trigger: Hitting the collection test endpoint when t1.getPokemons() resolves from the collection cache with a different number of Pokemon than expected — stale collection cache entries, cache storing an outdated collection snapshot, or missing/extra seeded Pokemon rows.

Common situations: Collection cache not invalidated after adding/removing Pokemon; leftover data from previous test runs; wrong collection cache concurrency strategy; collection region evicted but entity cache stale (or vice versa) yielding inconsistent loads.

Related errors


AI-assisted analysis of quarkusio/quarkus@e1c734241f (2026-09-05). Data as JSON: /api/errors/5ea54e12ed0b3f75. Report an issue: GitHub.