{"record":{"id":"698bb097bfa30aa1","repo":"lysine-dev/retrofit","slug":"scheduler-null-698bb0","errorCode":null,"errorMessage":"scheduler == null","messagePattern":"scheduler == null","errorType":"exception","errorClass":"NullPointerException","httpStatus":null,"severity":"error","filePath":"retrofit-adapters/rxjava2/src/main/java/retrofit2/adapter/rxjava2/RxJava2CallAdapterFactory.java","lineNumber":81,"sourceCode":"   * Returns an instance which creates synchronous observables that do not operate on any scheduler\n   * by default.\n   */\n  public static RxJava2CallAdapterFactory create() {\n    return new RxJava2CallAdapterFactory(null, false);\n  }\n\n  /** Returns an instance which creates asynchronous observables. */\n  public static RxJava2CallAdapterFactory createAsync() {\n    return new RxJava2CallAdapterFactory(null, true);\n  }\n\n  /**\n   * Returns an instance which creates synchronous observables that {@linkplain\n   * Observable#subscribeOn(Scheduler) subscribe on} {@code scheduler} by default.\n   */\n  @SuppressWarnings(\"ConstantConditions\") // Guarding public API nullability.\n  public static RxJava2CallAdapterFactory createWithScheduler(Scheduler scheduler) {\n    if (scheduler == null) throw new NullPointerException(\"scheduler == null\");\n    return new RxJava2CallAdapterFactory(scheduler, false);\n  }\n\n  private final @Nullable Scheduler scheduler;\n  private final boolean isAsync;\n\n  private RxJava2CallAdapterFactory(@Nullable Scheduler scheduler, boolean isAsync) {\n    this.scheduler = scheduler;\n    this.isAsync = isAsync;\n  }\n\n  @Override\n  public @Nullable CallAdapter<?, ?> get(\n      Type returnType, Annotation[] annotations, Retrofit retrofit) {\n    Class<?> rawType = getRawType(returnType);\n\n    if (rawType == Completable.class) {\n      // Completable is not parameterized (which is what the rest of this method deals with) so it","sourceCodeStart":63,"sourceCodeEnd":99,"githubUrl":"https://github.com/lysine-dev/retrofit/blob/d0b112dad073b7fe49c953ebc46ff1b424cb1e51/retrofit-adapters/rxjava2/src/main/java/retrofit2/adapter/rxjava2/RxJava2CallAdapterFactory.java#L63-L99","documentation":"RxJava2CallAdapterFactory.createWithScheduler(Scheduler) builds an adapter factory that subscribeOn's the supplied scheduler by default. Passing null is rejected because the factory would then hold no scheduler to apply; for the no-scheduler case the library provides dedicated factory methods (create() for synchronous, createAsync() for asynchronous). It throws NullPointerException ('scheduler == null') behind a ConstantConditions suppression.","triggerScenarios":"Calling RxJava2CallAdapterFactory.createWithScheduler(null), most often when the scheduler is read from DI/configuration/env that was not bound and resolved to null. Thrown immediately at the top of createWithScheduler.","commonSituations":"Reading a Scheduler from a DI graph or config property that resolved to null; conditional scheduler selection that falls through to null; copy-paste of createWithScheduler without choosing the right base factory method; environment differences (e.g. Android main thread scheduler absent in unit tests).","solutions":["If you want no custom scheduler, use the dedicated factory: RxJava2CallAdapterFactory.create()() or RxJava2CallAdapterFactory.createAsync().","Otherwise supply a real Scheduler such as Schedulers.io(), Schedulers.computation(), or AndroidSchedulers.mainThread().","Resolve the null at its source (DI binding / config property) rather than passing it through."],"exampleFix":"// before\nRxJavaCallAdapterFactory factory = RxJava2CallAdapterFactory.createWithScheduler(configScheduler);\n// after\nRxJava2CallAdapterFactory factory = configScheduler != null\n    ? RxJava2CallAdapterFactory.createWithScheduler(configScheduler)\n    : RxJava2CallAdapterFactory.createAsync();","handlingStrategy":"validation","validationCode":"Scheduler s = resolveScheduler(); // may be null when unconfigured\nRxJava2CallAdapterFactory factory =\n    s != null\n      ? RxJava2CallAdapterFactory.createWithScheduler(s)\n      : RxJava2CallAdapterFactory.createAsync();","typeGuard":null,"tryCatchPattern":"try {\n  factory = RxJava2CallAdapterFactory.createWithScheduler(s);\n} catch (NullPointerException e) {\n  // s was null; fall back to the async factory\n  factory = RxJava2CallAdapterFactory.createAsync();\n}","preventionTips":["Prefer the no-arg factory methods (createAsync / create()) unless you specifically need subscribeOn.","Bind a non-null Scheduler in DI and fail fast at startup if it is missing.","In tests, inject Schedulers.trampoline() rather than null."],"tags":["retrofit","rxjava2","null-safety","java","scheduling","scheduler"],"backgroundTag":null,"analyzedSha":"d0b112dad073b7fe49c953ebc46ff1b424cb1e51","analyzedAt":"2026-08-13T23:49:47.955Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}