{"record":{"id":"33a340af071ac83f","repo":"lysine-dev/retrofit","slug":"error-null","errorCode":null,"errorMessage":"error == null","messagePattern":"error == null","errorType":"exception","errorClass":"NullPointerException","httpStatus":null,"severity":"error","filePath":"retrofit-adapters/rxjava/src/main/java/retrofit2/adapter/rxjava/Result.java","lineNumber":26,"sourceCode":" *      http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\npackage retrofit2.adapter.rxjava;\n\nimport java.io.IOException;\nimport javax.annotation.Nullable;\nimport retrofit2.Response;\n\n/** The result of executing an HTTP request. */\npublic final class Result<T> {\n  @SuppressWarnings(\"ConstantConditions\") // Guarding public API nullability.\n  public static <T> Result<T> error(Throwable error) {\n    if (error == null) throw new NullPointerException(\"error == null\");\n    return new Result<>(null, error);\n  }\n\n  @SuppressWarnings(\"ConstantConditions\") // Guarding public API nullability.\n  public static <T> Result<T> response(Response<T> response) {\n    if (response == null) throw new NullPointerException(\"response == null\");\n    return new Result<>(response, null);\n  }\n\n  private final @Nullable Response<T> response;\n  private final @Nullable Throwable error;\n\n  private Result(@Nullable Response<T> response, @Nullable Throwable error) {\n    this.response = response;\n    this.error = error;\n  }\n\n  /**","sourceCodeStart":8,"sourceCodeEnd":44,"githubUrl":"https://github.com/lysine-dev/retrofit/blob/d0b112dad073b7fe49c953ebc46ff1b424cb1e51/retrofit-adapters/rxjava/src/main/java/retrofit2/adapter/rxjava/Result.java#L8-L44","documentation":"Result.error(Throwable) is the public factory for building an error-valued Result, used by the rxjava adapter to deliver network failures inside a reactive stream as data. It explicitly rejects null because a Result must carry a definite error or a definite response — a null error would make the Result semantically empty and break the error()/response() accessor invariants. It throws NullPointerException ('error == null') guarded behind a ConstantConditions suppression so the check is not stripped by static analysis.","triggerScenarios":"Calling Result.error(null) — most often inside a custom Operator/Transformer that re-wraps a caught Throwable reference that resolved to null, or in test/mocking code. Thrown immediately at the top of Result.error(Throwable).","commonSituations":"Writing custom RxJava operators that wrap caught exceptions; mock/test setup; defensive catch blocks where the throwable variable is unexpectedly null; Future.get() wrapping where the cause is null.","solutions":["Null-check the argument first: `if (cause != null) Result.error(cause) else ...`.","If the call should produce a success, use Result.response(...) instead.","Validate upstream so the throwable reference is never null (e.g. Future.get() can return a null cause on certain ExecutionException shapes)."],"exampleFix":"// before\nResult<User> r = Result.error(caught);\n// after\nif (caught == null) throw new IllegalArgumentException(\"cause must not be null\");\nResult<User> r = Result.error(caught);","handlingStrategy":"validation","validationCode":"Throwable cause = resolveCause();\nif (cause == null) throw new IllegalArgumentException(\"cause required\");\nResult<User> result = Result.error(cause);","typeGuard":null,"tryCatchPattern":"try {\n  Result<User> r = Result.error(cause);\n} catch (NullPointerException e) {\n  // cause was null; supply a fallback or rethrow with context\n  throw new IllegalArgumentException(\"Result.error requires a non-null cause\", e);\n}","preventionTips":["Wrap nullable throwables with Objects.requireNonNull(cause, \"cause\") before calling Result.error.","Prefer Optional/onError paths over manually constructing error Results.","In tests, never pass null to Result.error; use a real Exception instance."],"tags":["retrofit","rxjava","null-safety","java","api-contract","result"],"backgroundTag":null,"analyzedSha":"d0b112dad073b7fe49c953ebc46ff1b424cb1e51","analyzedAt":"2026-08-13T23:49:47.955Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}