{"id":"8b17b20662ae06b9","repo":"junit-team/junit5","slug":"state-could-not-be-cloned","errorCode":null,"errorMessage":"State could not be cloned","messagePattern":"State could not be cloned","errorType":"exception","errorClass":"JUnitException","httpStatus":null,"severity":"error","filePath":"junit-jupiter-engine/src/main/java/org/junit/jupiter/engine/execution/JupiterEngineExecutionContext.java","lineNumber":155,"sourceCode":"\t\tExtensionContext extensionContext;\n\n\t\t@Nullable\n\t\tThrowableCollector throwableCollector;\n\n\t\tState(EngineExecutionListener executionListener, JupiterConfiguration configuration,\n\t\t\t\tLauncherStoreFacade launcherStoreFacade) {\n\t\t\tthis.executionListener = executionListener;\n\t\t\tthis.configuration = configuration;\n\t\t\tthis.launcherStoreFacade = launcherStoreFacade;\n\t\t}\n\n\t\t@Override\n\t\tpublic State clone() {\n\t\t\ttry {\n\t\t\t\treturn (State) super.clone();\n\t\t\t}\n\t\t\tcatch (CloneNotSupportedException e) {\n\t\t\t\tthrow new JUnitException(\"State could not be cloned\", e);\n\t\t\t}\n\t\t}\n\n\t}\n\n\tpublic static class Builder {\n\n\t\tprivate State originalState;\n\n\t\t@Nullable\n\t\tprivate State newState = null;\n\n\t\tprivate Builder(State originalState) {\n\t\t\tthis.originalState = originalState;\n\t\t}\n\n\t\tpublic Builder withTestInstancesProvider(TestInstancesProvider testInstancesProvider) {\n\t\t\tnewState().testInstancesProvider = testInstancesProvider;","sourceCodeStart":137,"sourceCodeEnd":173,"githubUrl":"https://github.com/junit-team/junit5/blob/956246301e03d757539f7b76dd5a91f298637563/junit-jupiter-engine/src/main/java/org/junit/jupiter/engine/execution/JupiterEngineExecutionContext.java#L137-L173","documentation":"Thrown by JupiterEngineExecutionContext.State.clone() if Object.clone() raises CloneNotSupportedException. State explicitly implements Cloneable, so under normal JVM semantics clone() cannot fail; this is a defensive guard against a corrupted/instrumented runtime that violates the Cloneable contract.","triggerScenarios":"Effectively unreachable in a stock JVM because State implements Cloneable. Could only occur if a bytecode-rewriting agent or a hostile classloader strips the Cloneable interface at runtime, or if a future refactor removes `implements Cloneable` from State without removing clone().","commonSituations":"A testing/coverage/profiling agent that rewrites the State class and drops its Cloneable marker interface; an exotic JVM that does not honor Cloneable.","solutions":["Treat as an environment/JVM defect — verify no bytecode agent is rewriting org.junit.jupiter.engine.execution classes.","Ensure the junit-jupiter-engine jar is intact (no class corruption); re-fetch the dependency.","If you forked the engine, confirm State still declares `implements Cloneable`."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"// Defensive: catch if you instrument the engine\ntry { context.extend().build(); }\ncatch (JUnitException e) {\n    if (e.getMessage().contains(\"State could not be cloned\")) {\n        throw new IllegalStateException(\"Cloneable contract violated — check for bytecode agents\", e);\n    }\n    throw e;\n}","preventionTips":["Do not run bytecode-rewriting agents that strip Cloneable from engine internals.","Keep the junit-jupiter-engine jar intact (verify checksums).","If forking the engine, keep `implements Cloneable` on State."],"tags":["junit-jupiter","internal","clone","defensive"],"analyzedSha":"956246301e03d757539f7b76dd5a91f298637563","analyzedAt":"2026-08-04T19:25:17.049Z","schemaVersion":2}