From 9d2b20018fb9f16d4104183d8f551544914d2220 Mon Sep 17 00:00:00 2001 From: Chengyu Yang Date: Mon, 31 Oct 2022 13:46:26 -0700 Subject: [PATCH] fix: check existence of superclass before access its name --- .../org/springdoc/core/MethodParameterPojoExtractor.java | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/springdoc-openapi-common/src/main/java/org/springdoc/core/MethodParameterPojoExtractor.java b/springdoc-openapi-common/src/main/java/org/springdoc/core/MethodParameterPojoExtractor.java index 8edfdd6b2..8b97c4cbd 100644 --- a/springdoc-openapi-common/src/main/java/org/springdoc/core/MethodParameterPojoExtractor.java +++ b/springdoc-openapi-common/src/main/java/org/springdoc/core/MethodParameterPojoExtractor.java @@ -174,9 +174,8 @@ private static Stream fromSimpleClass(Class paramClass, Fiel try { Parameter parameter = field.getAnnotation(Parameter.class); boolean isNotRequired = parameter == null || !parameter.required(); - Annotation[] finalFieldAnnotations = fieldAnnotations; - if ("java.lang.Record".equals(paramClass.getSuperclass().getName())) { + if (paramClass.getSuperclass() != null && "java.lang.Record".equals(paramClass.getSuperclass().getName())) { Method classGetRecordComponents = Class.class.getMethod("getRecordComponents"); Object[] components = (Object[]) classGetRecordComponents.invoke(paramClass); @@ -191,7 +190,7 @@ private static Stream fromSimpleClass(Class paramClass, Fiel .filter(method -> method.getName().equals(field.getName())) .map(method -> new MethodParameter(method, -1)) .map(methodParameter -> DelegatingMethodParameter.changeContainingClass(methodParameter, paramClass)) - .map(param -> new DelegatingMethodParameter(param, fieldNamePrefix + field.getName(), finalFieldAnnotations, true, isNotRequired)); + .map(param -> new DelegatingMethodParameter(param, fieldNamePrefix + field.getName(), fieldAnnotations, true, isNotRequired)); } else @@ -201,7 +200,7 @@ private static Stream fromSimpleClass(Class paramClass, Fiel .filter(Objects::nonNull) .map(method -> new MethodParameter(method, -1)) .map(methodParameter -> DelegatingMethodParameter.changeContainingClass(methodParameter, paramClass)) - .map(param -> new DelegatingMethodParameter(param, fieldNamePrefix + field.getName(), finalFieldAnnotations, true, isNotRequired)); + .map(param -> new DelegatingMethodParameter(param, fieldNamePrefix + field.getName(), fieldAnnotations, true, isNotRequired)); } catch (IntrospectionException | NoSuchMethodException | InvocationTargetException | IllegalAccessException |