{"id":"58a2ed201264e0d6","repo":"junit-team/junit5","slug":"resourcelocktarget-children-is-not-supported-for","errorCode":null,"errorMessage":"'ResourceLockTarget.CHILDREN' is not supported for methods. Invalid method: <method>","messagePattern":"'ResourceLockTarget\\.CHILDREN' is not supported for methods\\. Invalid method: <method>","errorType":"exception","errorClass":"JUnitException","httpStatus":null,"severity":"error","filePath":"junit-jupiter-engine/src/main/java/org/junit/jupiter/engine/descriptor/MethodBasedTestDescriptor.java","lineNumber":133,"sourceCode":"\t\tValidatable.reportAndClear(this.methodInfo.discoveryIssues, reporter);\n\t\tDisplayNameUtils.validateAnnotation(getTestMethod(), //\n\t\t\t() -> \"method '%s'\".formatted(getTestMethod().toGenericString()), //\n\t\t\t// Use _declaring_ class here because that's where the `@DisplayName` annotation is declared\n\t\t\t() -> MethodSource.from(getTestMethod()), //\n\t\t\treporter);\n\t}\n\n\t// --- Node ----------------------------------------------------------------\n\n\t@Override\n\tpublic ExclusiveResourceCollector getExclusiveResourceCollector() {\n\t\t// There's no need to cache this as this method should only be called once\n\t\tExclusiveResourceCollector collector = ExclusiveResourceCollector.from(getTestMethod());\n\n\t\tif (collector.getStaticResourcesFor(CHILDREN).findAny().isPresent()) {\n\t\t\tString message = \"'ResourceLockTarget.CHILDREN' is not supported for methods.\" + //\n\t\t\t\t\t\" Invalid method: \" + getTestMethod();\n\t\t\tthrow new JUnitException(message);\n\t\t}\n\n\t\treturn collector;\n\t}\n\n\t@Override\n\tpublic Function<ResourceLocksProvider, Set<ResourceLocksProvider.Lock>> getResourceLocksProviderEvaluator() {\n\t\treturn enclosingInstanceTypesDependentResourceLocksProviderEvaluator(this::getEnclosingTestClasses,\n\t\t\t(provider, enclosingInstanceTypes) -> provider.provideForMethod(enclosingInstanceTypes, getTestClass(),\n\t\t\t\tgetTestMethod()));\n\t}\n\n\t@Override\n\tprotected Optional<ExecutionMode> getExplicitExecutionMode() {\n\t\treturn getExecutionModeFromAnnotation(getTestMethod());\n\t}\n\n\t/**","sourceCodeStart":115,"sourceCodeEnd":151,"githubUrl":"https://github.com/junit-team/junit5/blob/956246301e03d757539f7b76dd5a91f298637563/junit-jupiter-engine/src/main/java/org/junit/jupiter/engine/descriptor/MethodBasedTestDescriptor.java#L115-L151","documentation":"Thrown by MethodBasedTestDescriptor.getExclusiveResourceCollector() when a test method is annotated with @ResourceLock whose target is ResourceLockTarget.CHILDREN. CHILDREN only makes sense on a container (class-level) descriptor because a method has no child tests, so the engine rejects it as a JUnitException.","triggerScenarios":"Annotating a @Test, @TestFactory, @RepeatedTest, @ParameterizedTest, or lifecycle method with @ResourceLock(value = \"...\", target = ResourceLockTarget.CHILDREN).","commonSituations":"Copy-pasting a class-level @ResourceLock(target = CHILDREN) annotation onto a test method; refactoring a @ClassOrderContext/@ResourceLocks block from the class onto individual methods without changing the target.","solutions":["Move the @ResourceLock(target = CHILDREN) annotation from the method to the enclosing test class.","If the lock applies to the method itself, use the default target (or ResourceLockTarget.SELF).","Search the codebase for @ResourceLock(.*CHILDREN on method-level annotations and remove target = CHILDREN there."],"exampleFix":"// before\n@Test\n@org.junit.jupiter.api.parallel.ResourceLock(value = \"db\", target = ResourceLockTarget.CHILDREN)\nvoid myTest() {}\n// after\n@org.junit.jupiter.api.parallel.ResourceLock(value = \"db\", target = ResourceLockTarget.CHILDREN)\nclass MyTest {\n    @Test void myTest() {}\n}","handlingStrategy":"validation","validationCode":"// Scan test methods for the unsupported annotation shape\nfor (Method m : testClass.getDeclaredMethods()) {\n    ResourceLock rl = m.getAnnotation(ResourceLock.class);\n    if (rl != null && rl.target() == ResourceLockTarget.CHILDREN) {\n        throw new IllegalStateException(\"Method \" + m + \" uses CHILDREN target\");\n    }\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Use ResourceLockTarget.CHILDREN only on class-level annotations.","When copying a @ResourceLock from a class to a method, drop target = CHILDREN.","Review parallel-execution annotations during code review for target misuse."],"tags":["junit-jupiter","parallel-execution","resource-lock","annotation"],"analyzedSha":"956246301e03d757539f7b76dd5a91f298637563","analyzedAt":"2026-08-04T19:25:17.049Z","schemaVersion":2}