{"record":{"id":"f3a13de941ae2553","repo":"lysine-dev/retrofit","slug":"scheduler-null","errorCode":null,"errorMessage":"scheduler == null","messagePattern":"scheduler == null","errorType":"exception","errorClass":"NullPointerException","httpStatus":null,"severity":"error","filePath":"retrofit-adapters/rxjava/src/main/java/retrofit2/adapter/rxjava/RxJavaCallAdapterFactory.java","lineNumber":83,"sourceCode":"   * Returns an instance which creates synchronous observables that do not operate on any scheduler\n   * by default.\n   */\n  public static RxJavaCallAdapterFactory create() {\n    return new RxJavaCallAdapterFactory(null, false);\n  }\n\n  /** Returns an instance which creates asynchronous observables. */\n  public static RxJavaCallAdapterFactory createAsync() {\n    return new RxJavaCallAdapterFactory(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 RxJavaCallAdapterFactory createWithScheduler(Scheduler scheduler) {\n    if (scheduler == null) throw new NullPointerException(\"scheduler == null\");\n    return new RxJavaCallAdapterFactory(scheduler, false);\n  }\n\n  private final @Nullable Scheduler scheduler;\n  private final boolean isAsync;\n\n  private RxJavaCallAdapterFactory(@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    boolean isSingle = rawType == Single.class;\n    boolean isCompletable = rawType == Completable.class;\n    if (rawType != Observable.class && !isSingle && !isCompletable) {","sourceCodeStart":65,"sourceCodeEnd":101,"githubUrl":"https://github.com/lysine-dev/retrofit/blob/d0b112dad073b7fe49c953ebc46ff1b424cb1e51/retrofit-adapters/rxjava/src/main/java/retrofit2/adapter/rxjava/RxJavaCallAdapterFactory.java#L65-L101","documentation":"RxJavaCallAdapterFactory.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 RxJavaCallAdapterFactory.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: RxJavaCallAdapterFactory.create()() or RxJavaCallAdapterFactory.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 = RxJavaCallAdapterFactory.createWithScheduler(configScheduler);\n// after\nRxJavaCallAdapterFactory factory = configScheduler != null\n    ? RxJavaCallAdapterFactory.createWithScheduler(configScheduler)\n    : RxJavaCallAdapterFactory.createAsync();","handlingStrategy":"validation","validationCode":"Scheduler s = resolveScheduler(); // may be null when unconfigured\nRxJavaCallAdapterFactory factory =\n    s != null\n      ? RxJavaCallAdapterFactory.createWithScheduler(s)\n      : RxJavaCallAdapterFactory.createAsync();","typeGuard":null,"tryCatchPattern":"try {\n  factory = RxJavaCallAdapterFactory.createWithScheduler(s);\n} catch (NullPointerException e) {\n  // s was null; fall back to the async factory\n  factory = RxJavaCallAdapterFactory.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","rxjava","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"}