{"record":{"id":"f1e7480b04584f50","repo":"ReactiveX/RxJava","slug":"unsafecreate-maybe-should-be-upgraded","errorCode":null,"errorMessage":"unsafeCreate(Maybe) should be upgraded","messagePattern":"unsafeCreate\\(Maybe\\) should be upgraded","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"src/main/java/io/reactivex/rxjava4/core/Maybe.java","lineNumber":1533,"sourceCode":"     * any safeguards by using a callback that is called with a {@link MaybeObserver}.\n     * <p>\n     * <img width=\"640\" height=\"262\" src=\"https://raw.github.com/wiki/ReactiveX/RxJava/images/rx-operators/Maybe.unsafeCreate.png\" alt=\"\">\n     * <dl>\n     * <dt><b>Scheduler:</b></dt>\n     * <dd>{@code unsafeCreate} does not operate by default on a particular {@link Scheduler}.</dd>\n     * </dl>\n     * @param <T> the value type\n     * @param onSubscribe the function that is called with the subscribing {@code MaybeObserver}\n     * @return the new {@code Maybe} instance\n     * @throws IllegalArgumentException if {@code onSubscribe} is a {@code Maybe}\n     * @throws NullPointerException if {@code onSubscribe} is {@code null}\n     */\n    @CheckReturnValue\n    @NonNull\n    @SchedulerSupport(SchedulerSupport.NONE)\n    public static <@NonNull T> Maybe<T> unsafeCreate(@NonNull MaybeSource<T> onSubscribe) {\n        if (onSubscribe instanceof Maybe) {\n            throw new IllegalArgumentException(\"unsafeCreate(Maybe) should be upgraded\");\n        }\n        Objects.requireNonNull(onSubscribe, \"onSubscribe is null\");\n        return RxJavaPlugins.onAssembly(new MaybeUnsafeCreate<>(onSubscribe));\n    }\n\n    /**\n     * Constructs a {@code Maybe} that creates a dependent resource object which is disposed of when the\n     * generated {@link MaybeSource} terminates or the downstream calls dispose().\n     * <p>\n     * <img width=\"640\" height=\"378\" src=\"https://raw.github.com/wiki/ReactiveX/RxJava/images/rx-operators/Maybe.using.png\" alt=\"\">\n     * <dl>\n     *  <dt><b>Scheduler:</b></dt>\n     *  <dd>{@code using} does not operate by default on a particular {@link Scheduler}.</dd>\n     * </dl>\n     *\n     * @param <T> the element type of the generated {@code MaybeSource}\n     * @param <D> the type of the resource associated with the output sequence\n     * @param resourceSupplier","sourceCodeStart":1515,"sourceCodeEnd":1551,"githubUrl":"https://github.com/ReactiveX/RxJava/blob/a8ab5356143f37a8f1dd6d76c79191bec5fa343b/src/main/java/io/reactivex/rxjava4/core/Maybe.java#L1515-L1551","documentation":"Thrown by Maybe.unsafeCreate when the argument is already a Maybe instance. unsafeCreate is meant to bridge foreign MaybeSource implementations; wrapping a real Maybe is redundant and almost always a migration remnant. Note the NPE check runs after this guard, so a null Maybe is fine but a non-null Maybe triggers this error.","triggerScenarios":"Calling Maybe.unsafeCreate(someMaybe) where the runtime type is Maybe. Common when an upstream operator or helper returns Maybe and the caller unconditionally wraps it.","commonSituations":"RxJava 1.x porting where Observable.unsafeCreate patterns were common; generic adapters that wrap any source without checking identity.","solutions":["Use the Maybe directly instead of wrapping: drop unsafeCreate.","If you need to hide identity, call source.hide().","Restrict the call site so unsafeCreate only receives non-Maybe MaybeSource instances."],"exampleFix":"// before\nMaybe<String> src = loadMaybe();\nMaybe<String> wrapped = Maybe.unsafeCreate(src);\n\n// after\nMaybe<String> wrapped = src;\n// or:\nMaybe<String> hidden = src.hide();","handlingStrategy":"type-guard","validationCode":"MaybeSource<T> source = loadSource();\nif (source instanceof Maybe) {\n    // unsafeCreate would throw; use directly or hide()\n    return;\n}","typeGuard":"static <T> boolean needsUnsafeCreate(MaybeSource<T> s) {\n    return s != null && !(s instanceof Maybe);\n}","tryCatchPattern":"try {\n    return Maybe.unsafeCreate(source);\n} catch (IllegalArgumentException e) {\n    return source instanceof Maybe ? (Maybe<T>) source : Maybe.error(e);\n}","preventionTips":["Use unsafeCreate only for foreign MaybeSource implementations, not for Maybe.","Prefer hide() when you need to obscure Maybe identity.","Type-guard generic adapters that accept MaybeSource."],"tags":["rxjava","maybe","unsafe-create","api-misuse","argument-validation"],"backgroundTag":null,"analyzedSha":"a8ab5356143f37a8f1dd6d76c79191bec5fa343b","analyzedAt":"2026-08-13T23:25:30.069Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}