From 77575e1dff92612cd4344d10dad5bbef4bd2b97a Mon Sep 17 00:00:00 2001 From: lbilger Date: Thu, 3 Feb 2022 14:08:45 +0100 Subject: [PATCH] Fix ClassCastException if expected type is Object The currently generated code will throw a `ClassCastException` if `type` is `Object`. I'm not quite sure why `isAssignableFrom` is used here but I tried to keep the change minimal - in my understanding, the result would be the same if the line was ``` if(Types.getRawType(type).equals(ApiResponse.class)) { ``` because the `ApiResponse` only extends `Object` and implements no interfaces. Maybe it was meant to be `ApiResponse.class.isAssignableFrom(Types.getRawType(type))`? This would also permit subclasses of `ApiResponse`, but then it would be more complicated to determine the actual type parameter (because `type` itself may not be parameterized) and to create the object to return (because it would have to be an instance of the subclass). --- .../Java/libraries/feign/ApiResponseDecoder.mustache | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/openapi-generator/src/main/resources/Java/libraries/feign/ApiResponseDecoder.mustache b/modules/openapi-generator/src/main/resources/Java/libraries/feign/ApiResponseDecoder.mustache index ef171de94300..2ff7a3243c06 100644 --- a/modules/openapi-generator/src/main/resources/Java/libraries/feign/ApiResponseDecoder.mustache +++ b/modules/openapi-generator/src/main/resources/Java/libraries/feign/ApiResponseDecoder.mustache @@ -25,7 +25,7 @@ public class ApiResponseDecoder extends JacksonDecoder { Map> responseHeaders = Collections.unmodifiableMap(response.headers()); //Detects if the type is an instance of the parameterized class ApiResponse Type responseBodyType; - if (Types.getRawType(type).isAssignableFrom(ApiResponse.class)) { + if (type instanceof ParameterizedType && Types.getRawType(type).isAssignableFrom(ApiResponse.class)) { //The ApiResponse class has a single type parameter, the Dto class itself responseBodyType = ((ParameterizedType) type).getActualTypeArguments()[0]; Object body = super.decode(response, responseBodyType); @@ -35,4 +35,4 @@ public class ApiResponseDecoder extends JacksonDecoder { return super.decode(response, type); } } -} \ No newline at end of file +}