{"record":{"id":"dcc962edc862dbdc","repo":"junit-team/junit5","slug":"s-must-not-be-null","errorCode":null,"errorMessage":"%s must not be null","messagePattern":"(.+?) must not be null","errorType":"exception","errorClass":"JUnitException","httpStatus":null,"severity":"error","filePath":"junit-platform-commons/src/main/java/org/junit/platform/commons/function/Try.java","lineNumber":91,"sourceCode":"\t}\n\n\t/**\n\t * Convert the supplied exception into a failed {@code Try}.\n\t *\n\t * @param cause the exception to wrap; must not be {@code null}\n\t * @return a failed {@code Try} that contains the supplied value; never\n\t * {@code null}\n\t */\n\tpublic static <V> Try<V> failure(Exception cause) {\n\t\treturn new Failure<>(checkNotNull(cause, \"cause\"));\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\t// Cannot use PreconditionViolationException due to package cycle\n\t\t\tthrow new JUnitException(title + \" must not be null\");\n\t\t}\n\t\treturn input;\n\t}\n\n\tprivate static <V> Try<V> of(Callable<Try<V>> action) {\n\t\ttry {\n\t\t\treturn action.call();\n\t\t}\n\t\tcatch (Exception e) {\n\t\t\treturn failure(e);\n\t\t}\n\t}\n\n\tprivate Try() {\n\t\t/* no-op */\n\t}\n\n\t/**","sourceCodeStart":73,"sourceCodeEnd":109,"githubUrl":"https://github.com/junit-team/junit5/blob/f070c699a08b5d8393df9afd147af5c5e90bb21b/junit-platform-commons/src/main/java/org/junit/platform/commons/function/Try.java#L73-L109","documentation":"Thrown by the private checkNotNull in Try when Try.failure(cause) is called with a null cause. Because Try lives in a low-level package that cannot depend on Preconditions (package cycle), it does its own null check and raises JUnitException '<title> must not be null'. The title is 'cause', so the message reads 'cause must not be null'.","triggerScenarios":"Calling Try.failure(null) directly or via code paths that pass a null exception into failure(). The checkNotNull guard in failure() trips before a Failure is constructed.","commonSituations":"Library/extension code constructing a Try from a possibly-null exception without null-checking first. Misuse of Try APIs in custom extensions. Unlikely to be hit by end users directly; more common in framework-adjacent code.","solutions":["Ensure a non-null Exception is passed to Try.failure().","Null-check the cause before calling Try.failure(), or use Try.success/Try.of instead when there is no error.","If the cause is genuinely absent, raise an explicit JUnitException with a descriptive message instead of null."],"exampleFix":"// before\nTry<V> result = Try.failure(someThrowable); // someThrowable may be null\n\n// after\nTry<V> result = (someThrowable instanceof Exception e)\n  ? Try.failure(e)\n  : Try.failure(new JUnitException(\"underlying error was not an Exception\"));","handlingStrategy":"validation","validationCode":"// Never pass a null cause to Try.failure()\nException cause = resolveCause();\nif (cause == null) throw new JUnitException(\"cause must not be null\");\nTry<V> t = Try.failure(cause);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Guarantee non-null Exception when constructing a failed Try.","Prefer Try.of(Callable) to avoid manual failure construction.","Add a null check at API boundaries that produce Try results."],"tags":["junit-platform","try","null-check","internal"],"backgroundTag":null,"analyzedSha":"f070c699a08b5d8393df9afd147af5c5e90bb21b","analyzedAt":"2026-08-11T20:31:00.530Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}