{"record":{"id":"5ea54e12ed0b3f75","repo":"quarkusio/quarkus","slug":"incorrect-family-size-pokemons-size-ex","errorCode":null,"errorMessage":"Incorrect family size: \" + pokemons.size() + \", expected: \" + expectedSize","messagePattern":"Incorrect family size: \" \\+ pokemons\\.size\\(\\) \\+ \", expected: \" \\+ expectedSize","errorType":"exception","errorClass":"RuntimeException","httpStatus":500,"severity":"error","filePath":"integration-tests/hibernate-orm-cache/src/main/java/io/quarkus/it/hibernate/orm/cache/HibernateOrmCacheTestEndpoint.java","lineNumber":301,"sourceCode":"\n            final Pokemon golem = new Pokemon(76, \"Alolan Golem\", 2233);\n            em.persist(golem);\n            pokemons.add(golem);\n        });\n\n        assertRegionStats(counts);\n    }\n\n    private void verifyReadWriteCollection(int expectedSize,\n            Map<String, Counts> counts) {\n        clearStatistics();\n\n        QuarkusTransaction.requiringNew().run(() -> {\n            final Trainer t1 = em.find(Trainer.class, 1L);\n            final List<Pokemon> pokemons = t1.getPokemons();\n\n            if (pokemons.size() != expectedSize)\n                throw new RuntimeException(\"Incorrect family size: \" + pokemons.size() + \", expected: \" + expectedSize);\n        });\n\n        assertRegionStats(counts);\n    }\n\n    private void testNonStrictReadWrite() {\n        // NONSTRICT_READ_WRITE with JCache does not cache on insert\n        storeTestItems(new Counts(0, 0, 0, 0));\n\n        // Loading items will populate the cache (puts on read)\n        final String[] expected = { \"Hibernate T-shirt\", \"Hibernate Sticker\", \"Hibernate Mug\" };\n        verifyFindByIdItems(expected, new Counts(3, 0, 3, 3));\n\n        // Modifying items will load from cache, then evict cache entries (numElements=0 after)\n        final String[] newValues = { \"Infinispan T-shirt\", \"Infinispan Sticker\", \"Infinispan Mug\" };\n        updateItemDescriptions(newValues, new Counts(0, 3, 0, 0));\n\n        // Verify descriptions after update - cache was evicted, will reload from DB","sourceCodeStart":283,"sourceCodeEnd":319,"githubUrl":"https://github.com/quarkusio/quarkus/blob/e1c734241f34c7919086ceb4c9262b4a58f6de44/integration-tests/hibernate-orm-cache/src/main/java/io/quarkus/it/hibernate/orm/cache/HibernateOrmCacheTestEndpoint.java#L283-L319","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Evict the Trainer collection region (and Pokemon entity region) before verifying","Reset/seed the database consistently before the test so Trainer 1 has exactly the expected Pokemons","Verify the @Cache annotation on the Trainer.getPokemons() collection uses the intended strategy","Clear the whole second-level cache between test runs"],"exampleFix":"// before\nfinal List<Pokemon> pokemons = t1.getPokemons();\nif (pokemons.size() != expectedSize) throw ...\n// after\nsessionFactory.getCache().evictCollection(Trainer.class.getName() + \".pokemons\", 1L);\nfinal List<Pokemon> pokemons = t1.getPokemons();\nif (pokemons.size() != expectedSize) throw ...","handlingStrategy":"validation","validationCode":"Trainer t1 = em.find(Trainer.class, 1L);\nif (t1 == null) throw new IllegalStateException(\"Trainer 1 not seeded\");\nsessionFactory.getCache().evictCollection(Trainer.class.getName() + \".pokemons\", 1L);","typeGuard":null,"tryCatchPattern":"try {\n    verifyReadWriteCollection(expectedSize);\n} catch (RuntimeException e) {\n    sessionFactory.getCache().evictCollection(Trainer.class.getName() + \".pokemons\", 1L);\n    // reload and re-check to distinguish stale collection cache from bad seed data\n}","preventionTips":["Evict collection regions after adding/removing collection elements","Reset seed data before each collection-cache test","Verify collection @Cache strategy matches the mutation pattern"],"tags":["hibernate","collection-cache","second-level-cache","test-assertion","quarkus"],"backgroundTag":"stale-cache-data","analyzedSha":"e1c734241f34c7919086ceb4c9262b4a58f6de44","analyzedAt":"2026-09-05T17:01:29.979Z","contentChangedAt":"2026-09-05T17:01:29.979Z","schemaVersion":2},"datasetVersion":"2026-09-12T22:17:10.623Z"}