{"id":"1f768b71dd03200c","repo":"square/retrofit","slug":"response-must-be-parameterized-as-response-foo-or-1f768b","errorCode":null,"errorMessage":"Response must be parameterized as Response<Foo> or Response<? extends Foo>","messagePattern":"Response must be parameterized as Response<Foo> or Response<\\? extends Foo>","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"retrofit-adapters/rxjava/src/main/java/retrofit2/adapter/rxjava/RxJavaCallAdapterFactory.java","lineNumber":128,"sourceCode":"    boolean isBody = false;\n    Type responseType;\n    if (!(returnType instanceof ParameterizedType)) {\n      String name = isSingle ? \"Single\" : \"Observable\";\n      throw new IllegalStateException(\n          name\n              + \" return type must be parameterized\"\n              + \" as \"\n              + name\n              + \"<Foo> or \"\n              + name\n              + \"<? extends Foo>\");\n    }\n\n    Type observableType = getParameterUpperBound(0, (ParameterizedType) returnType);\n    Class<?> rawObservableType = getRawType(observableType);\n    if (rawObservableType == Response.class) {\n      if (!(observableType instanceof ParameterizedType)) {\n        throw new IllegalStateException(\n            \"Response must be parameterized\" + \" as Response<Foo> or Response<? extends Foo>\");\n      }\n      responseType = getParameterUpperBound(0, (ParameterizedType) observableType);\n    } else if (rawObservableType == Result.class) {\n      if (!(observableType instanceof ParameterizedType)) {\n        throw new IllegalStateException(\n            \"Result must be parameterized\" + \" as Result<Foo> or Result<? extends Foo>\");\n      }\n      responseType = getParameterUpperBound(0, (ParameterizedType) observableType);\n      isResult = true;\n    } else {\n      responseType = observableType;\n      isBody = true;\n    }\n\n    return new RxJavaCallAdapter(\n        responseType, scheduler, isAsync, isResult, isBody, isSingle, false);\n  }","sourceCodeStart":110,"sourceCodeEnd":146,"githubUrl":"https://github.com/square/retrofit/blob/d0b112dad073b7fe49c953ebc46ff1b424cb1e51/retrofit-adapters/rxjava/src/main/java/retrofit2/adapter/rxjava/RxJavaCallAdapterFactory.java#L110-L146","documentation":"Thrown by RxJavaCallAdapterFactory when the outer reactive type is parameterized but its argument is raw `Response`. The factory needs `Response<T>` to extract the body type T; raw Response fails the check at RxJavaCallAdapterFactory.java:127. The same rule applies whether the outer type is Observable or Single.","triggerScenarios":"A service method returns `Observable<Response>` or `Single<Response>` (raw Response) rather than `Observable<Response<User>>`.","commonSituations":"Switching from a body return to a Response-wrapped return and forgetting the inner generic; or autocompleting Response without its type argument.","solutions":["Parameterize Response: `Observable<Response<User>> getUser();`.","Or drop the wrapper: `Observable<User> getUser();`.","If you want both body and error handling in one stream, use `Observable<Result<User>>`."],"exampleFix":"// before\n@GET(\"users/{id}\")\nObservable<Response> getUser(@Path(\"id\") String id);\n\n// after\n@GET(\"users/{id}\")\nObservable<Response<User>> getUser(@Path(\"id\") String id);","handlingStrategy":"validation","validationCode":"for (Method m : MyService.class.getDeclaredMethods()) {\n    Type rt = m.getGenericReturnType();\n    if (rt instanceof ParameterizedType\n            && ((ParameterizedType) rt).getActualTypeArguments()[0] == retrofit2.Response.class) {\n        throw new IllegalStateException(m + \" uses raw Response inside an RxJava type.\");\n    }\n}","typeGuard":null,"tryCatchPattern":"// Fail fast in a wiring test:\ntry {\n    retrofit.create(MyService.class).getUser(\"1\");\n} catch (IllegalStateException e) {\n    if (e.getMessage().contains(\"Response must be parameterized\")) {\n        throw new IllegalStateException(\"Fix raw Response<> inside RxJava return in MyService.\", e);\n    }\n    throw e;\n}","preventionTips":["Always carry the body type into Response<>.","Let the IDE flag raw inner types.","Keep a per-service smoke test in CI."],"tags":["retrofit","rxjava","java","reflection","response-wrapper"],"analyzedSha":"d0b112dad073b7fe49c953ebc46ff1b424cb1e51","analyzedAt":"2026-08-04T19:12:59.096Z","schemaVersion":2}