{"record":{"id":"de66c83e9b42a857","repo":"quarkusio/quarkus","slug":"incorrect-cp-godzilla-getcp","errorCode":null,"errorMessage":"Incorrect cp: \" + godzilla.getCp()","messagePattern":"Incorrect cp: \" \\+ godzilla\\.getCp\\(\\)","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":581,"sourceCode":"            Pokemon blissey = em.find(Pokemon.class, 242);\n            blissey.setCp(2757);\n\n        });\n\n        assertRegionStats(expected, Pokemon.class.getName());\n    }\n\n    private void verifyFindByIdPokemons(int[] expectedCps, Counts expected) {\n        clearStatistics();\n\n        QuarkusTransaction.requiringNew().run(() -> {\n            Pokemon igeldo = em.find(Pokemon.class, 3);\n            if (igeldo.getCp() != expectedCps[0])\n                throw new RuntimeException(\"Incorrect cp: \" + igeldo.getCp());\n\n            Pokemon godzilla = em.find(Pokemon.class, 248);\n            if (godzilla.getCp() != expectedCps[1])\n                throw new RuntimeException(\"Incorrect cp: \" + godzilla.getCp());\n\n            Pokemon blissey = em.find(Pokemon.class, 242);\n            if (blissey.getCp() != expectedCps[2])\n                throw new RuntimeException(\"Incorrect cp: \" + blissey.getCp());\n\n        });\n\n        assertRegionStats(expected, Pokemon.class.getName());\n    }\n\n    private void storeTestPokemons(Counts expected) {\n        clearStatistics();\n\n        QuarkusTransaction.requiringNew().run(() -> {\n            final Pokemon igeldo = new Pokemon(3, \"Venusaur\", 2555);\n            em.persist(igeldo);\n            final Pokemon godzilla = new Pokemon(248, \"Tyranitar\", 3670);\n            em.persist(godzilla);","sourceCodeStart":563,"sourceCodeEnd":599,"githubUrl":"https://github.com/quarkusio/quarkus/blob/e1c734241f34c7919086ceb4c9262b4a58f6de44/integration-tests/hibernate-orm-cache/src/main/java/io/quarkus/it/hibernate/orm/cache/HibernateOrmCacheTestEndpoint.java#L563-L599","documentation":"RuntimeException thrown by verifyFindByIdPokemons when the Pokemon with ID 248 ('godzilla') has a cp value that does not match expectedCps[1]. Like the igeldo check, it detects that the loaded (possibly cached) entity state diverges from what the write phase should have produced.","triggerScenarios":"em.find(Pokemon.class, 248).getCp() != expectedCps[1]: the write phase did not update this Pokemon, the second-level cache returned the old version, or the expected array is misaligned with the write order.","commonSituations":"Stale second-level cache entry for Pokemon 248 after an update; test write phase skipped or partially failed; expected counts/cps array passed to verifyFindByIdPokemons does not reflect the actual writes; leftover DB state from a prior run.","solutions":["Ensure the write phase updated all three Pokemons (3, 248, 242) in a committed transaction","Verify cache invalidation on update for the Pokemon region (check assertRegionStats hit/miss counts)","Align the expectedCps array order with the find order (3 -> [0], 248 -> [1], 242 -> [2])","Clean the DB and clear cache statistics between test runs"],"exampleFix":"// before\nif (godzilla.getCp() != expectedCps[1]) throw new RuntimeException(\"Incorrect cp: \" + godzilla.getCp());\n// after\nif (godzilla.getCp() != expectedCps[1]) throw new RuntimeException(\"Incorrect cp for godzilla: \" + godzilla.getCp() + \", expected: \" + expectedCps[1]);","handlingStrategy":"validation","validationCode":"Pokemon g = em.find(Pokemon.class, 248);\nif (g == null || g.getCp() != expectedCps[1])\n    throw new IllegalStateException(\"Pokemon 248 cp mismatch or missing: \" + (g == null ? \"null\" : g.getCp()));","typeGuard":"boolean hasExpectedCp(Pokemon p, int expected) { return p != null && p.getCp() == expected; }","tryCatchPattern":"try {\n    verifyFindByIdPokemons(expectedCps, expectedCounts);\n} catch (RuntimeException e) {\n    if (e.getMessage().startsWith(\"Incorrect cp\")) {\n        // identify which pokemon failed from the message, evict its cache entry\n    }\n}","preventionTips":["Keep expectedCps array indices aligned with find order (3,248,242)","Assert write-phase effects immediately after commit","Reset cache statistics before each verification phase"],"tags":["hibernate-orm","cache","stale-data","integration-test"],"backgroundTag":"stale-cache-entity","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"}