{"record":{"id":"1184f3c443b25f75","repo":"junit-team/junit5","slug":"s-must-not-be-null-1184f3","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/DefaultResource.java","lineNumber":63,"sourceCode":"\t\t\treturn true;\n\t\t}\n\t\tif (obj instanceof org.junit.platform.commons.io.Resource that) {\n\t\t\treturn this.name.equals(that.getName()) //\n\t\t\t\t\t&& this.uri.equals(that.getUri());\n\t\t}\n\t\treturn false;\n\t}\n\n\t@Override\n\tpublic int hashCode() {\n\t\treturn Objects.hash(name, uri);\n\t}\n\n\t// Cannot use Preconditions due to package cycle\n\t@Contract(\"null, _ -> fail; !null, _ -> param1\")\n\tprivate static <T> void 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}\n\n}\n","sourceCodeStart":45,"sourceCodeEnd":68,"githubUrl":"https://github.com/junit-team/junit5/blob/f070c699a08b5d8393df9afd147af5c5e90bb21b/junit-platform-commons/src/main/java/org/junit/platform/commons/io/DefaultResource.java#L45-L68","documentation":"Thrown by the private checkNotNull in DefaultResource when a null value is supplied to a constructor/state field that must be non-null. DefaultResource cannot use Preconditions (package cycle), so it performs its own null check and raises PreconditionViolationException '<title> must not be null'. The guard is a generic @Contract-annotated helper used for name/uri inputs.","triggerScenarios":"Constructing or invoking a DefaultResource method with a null name or uri argument. The checkNotNull guard fires on the offending argument.","commonSituations":"Custom code in the platform-commons-io area creating DefaultResource with null inputs. Resource lookup returning null name/uri being passed through. Internal misuse of the resource abstraction.","solutions":["Pass non-null name and uri when constructing a DefaultResource.","Null-check inputs before creating the resource and reject with a clearer message.","Use a higher-level resource factory rather than constructing DefaultResource directly."],"exampleFix":"// before\nResource r = new DefaultResource(null, someUri);\n\n// after\nResource r = new DefaultResource(Objects.requireNonNull(name, \"name\"), Objects.requireNonNull(uri, \"uri\"));","handlingStrategy":"validation","validationCode":"// Null-check name/uri before constructing DefaultResource\nString name = Objects.requireNonNull(resource.getName(), \"name\");\nURI uri = Objects.requireNonNull(resource.getUri(), \"uri\");\nnew DefaultResource(name, uri);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Never construct DefaultResource with null name or uri.","Use factory methods that validate inputs.","Keep resource producers from emitting null fields."],"tags":["junit-platform","resource","null-check","internal"],"backgroundTag":null,"analyzedSha":"f070c699a08b5d8393df9afd147af5c5e90bb21b","analyzedAt":"2026-08-11T20:31:00.530Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}