{"record":{"id":"e0fd10e071a5cd1c","repo":"junit-team/junit5","slug":"resourcelocktarget-children-is-not-supported-for","errorCode":null,"errorMessage":"'ResourceLockTarget.CHILDREN' is not supported for methods. Invalid method: %s","messagePattern":"'ResourceLockTarget\\.CHILDREN' is not supported for methods\\. Invalid 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/f070c699a08b5d8393df9afd147af5c5e90bb21b/junit-jupiter-engine/src/main/java/org/junit/jupiter/engine/descriptor/MethodBasedTestDescriptor.java#L115-L151","documentation":"Thrown as JUnitException when a method-level @ResourceLock annotation uses ResourceLockTarget.CHILDREN. CHILDREN only makes sense on a class (it applies to nested/contained tests), so applying it to a @Test/@TestFactory/@RepeatedTest/etc. method is a misuse that the MethodBasedTestDescriptor rejects at exclusive-resource collection time.","triggerScenarios":"Annotating a method with @ResourceLock(value=\"...\", target=ResourceLockTarget.CHILDREN); ExclusiveResourceCollector.from(getTestMethod()) then finds static resources scoped to CHILDREN and the descriptor throws in getExclusiveResourceCollector().","commonSituations":"Copy-paste from a class-level @ResourceLock that used CHILDREN, misunderstanding the CHILDREN semantics, or a custom composed annotation that hardcodes CHILDREN.","solutions":["Remove target=ResourceLockTarget.CHILDREN from the method annotation - omit it (defaults to CURRENT).","If you really need to lock child resources, move the @ResourceLock to the enclosing @Test class instead.","Switch to a custom @ResourceLocksProvider via provideForMethod rather than annotation-based locks if child scoping is genuinely required."],"exampleFix":"// before\n@Test\n@ResourceLock(value=\"db\", target=ResourceLockTarget.CHILDREN)\nvoid usesDb() { }\n// after\n@Test\n@ResourceLock(value=\"db\") // target defaults to CURRENT\nvoid usesDb() { }","handlingStrategy":"validation","validationCode":"for (Method m : MyTest.class.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 illegally\");\n    }\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Reserve ResourceLockTarget.CHILDREN for class-level annotations only.","Use the default (CURRENT) target on method-level @ResourceLock.","Move child-scoped locks to the enclosing class."],"tags":["resource-lock","parallel-execution","annotation","method-descriptor"],"backgroundTag":null,"analyzedSha":"f070c699a08b5d8393df9afd147af5c5e90bb21b","analyzedAt":"2026-08-11T20:31:00.530Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}