{"record":{"id":"93d19520abb6953f","repo":"junit-team/junit5","slug":"s-must-not-be-null-93d195","errorCode":null,"errorMessage":"%s must not be null","messagePattern":"(.+?) must not be null","errorType":"exception","errorClass":"PreconditionViolationException","httpStatus":null,"severity":"error","filePath":"junit-platform-commons/src/main/java/org/junit/platform/commons/io/ResourceFilter.java","lineNumber":62,"sourceCode":"\t\tthis.predicate = predicate;\n\t}\n\n\t/**\n\t * Test whether the given resource matches this filter.\n\t *\n\t * @param resource the resource to test; never {@code null}\n\t * @return {@code true} if the resource matches this filter, otherwise\n\t * {@code false}\n\t */\n\tpublic boolean match(Resource resource) {\n\t\treturn predicate.test(checkNotNull(resource, \"resource\"));\n\t}\n\n\t// Cannot use Preconditions due to package cycle\n\t@Contract(\"null, _ -> fail; !null, _ -> param1\")\n\tprivate static <T> T checkNotNull(@Nullable T input, String title) {\n\t\tif (input == null) {\n\t\t\tthrow new PreconditionViolationException(title + \" must not be null\");\n\t\t}\n\t\treturn input;\n\t}\n\n}\n","sourceCodeStart":44,"sourceCodeEnd":68,"githubUrl":"https://github.com/junit-team/junit5/blob/f070c699a08b5d8393df9afd147af5c5e90bb21b/junit-platform-commons/src/main/java/org/junit/platform/commons/io/ResourceFilter.java#L44-L68","documentation":"Thrown by the private checkNotNull in ResourceFilter when match(resource) is called with a null resource. Because ResourceFilter cannot use Preconditions (package cycle), it guards directly and raises PreconditionViolationException 'resource must not be null' before applying the predicate.","triggerScenarios":"Calling resourceFilter.match(null). The checkNotNull(resource, \"resource\") guard fires before predicate.test.","commonSituations":"Filtering a stream of resources where some elements are null. Passing a resource reference that was not resolved (e.g. lookup returned null) into the filter.","solutions":["Filter out null resources before calling match(): stream.filter(Objects::nonNull).","Ensure the resource source never yields null.","Null-check the resource before invoking match() and handle the missing case explicitly."],"exampleFix":"// before\nboolean ok = filter.match(maybeNullResource);\n\n// after\nboolean ok = maybeNullResource != null && filter.match(maybeNullResource);","handlingStrategy":"type-guard","validationCode":"// Filter nulls before applying the ResourceFilter\nStream<Resource> safe = resources.filter(Objects::nonNull);\nsafe.forEach(r -> filter.match(r));","typeGuard":"static boolean isNonNullOrginal(Resource r) { return r != null; }","tryCatchPattern":null,"preventionTips":["Pre-filter null resources from streams before calling match().","Ensure resource sources never return null.","Null-check resources at the call site of match()."],"tags":["junit-platform","resource","null-check","filter"],"backgroundTag":null,"analyzedSha":"f070c699a08b5d8393df9afd147af5c5e90bb21b","analyzedAt":"2026-08-11T20:31:00.530Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}