From abcc1dfc6cb851b35ad163e29212560519affcb2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Nicoll?= Date: Thu, 2 May 2024 16:53:59 +0200 Subject: [PATCH] Review usage of BindingReflectionHintsRegistrar#registerReflectionHints Closes gh-32753 --- .../aot/hint/BindingReflectionHintsRegistrar.java | 2 +- .../MessageMappingReflectiveProcessor.java | 7 +++++-- .../ControllerMappingReflectiveProcessor.java | 12 +++++++++--- 3 files changed, 15 insertions(+), 6 deletions(-) diff --git a/spring-core/src/main/java/org/springframework/aot/hint/BindingReflectionHintsRegistrar.java b/spring-core/src/main/java/org/springframework/aot/hint/BindingReflectionHintsRegistrar.java index f31cb20df6d1..d4951f15141f 100644 --- a/spring-core/src/main/java/org/springframework/aot/hint/BindingReflectionHintsRegistrar.java +++ b/spring-core/src/main/java/org/springframework/aot/hint/BindingReflectionHintsRegistrar.java @@ -62,7 +62,7 @@ public class BindingReflectionHintsRegistrar { * @param hints the hints instance to use * @param types the types to register */ - public void registerReflectionHints(ReflectionHints hints, @Nullable Type... types) { + public void registerReflectionHints(ReflectionHints hints, Type... types) { Set seen = new LinkedHashSet<>(); for (Type type : types) { registerReflectionHints(hints, seen, type); diff --git a/spring-messaging/src/main/java/org/springframework/messaging/handler/annotation/MessageMappingReflectiveProcessor.java b/spring-messaging/src/main/java/org/springframework/messaging/handler/annotation/MessageMappingReflectiveProcessor.java index c19126ae6282..94b592f067ba 100644 --- a/spring-messaging/src/main/java/org/springframework/messaging/handler/annotation/MessageMappingReflectiveProcessor.java +++ b/spring-messaging/src/main/java/org/springframework/messaging/handler/annotation/MessageMappingReflectiveProcessor.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2023 the original author or authors. + * Copyright 2002-2024 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -83,7 +83,10 @@ protected void registerParameterHints(ReflectionHints hints, Method method) { for (Parameter parameter : method.getParameters()) { MethodParameter methodParameter = MethodParameter.forParameter(parameter); if (Message.class.isAssignableFrom(methodParameter.getParameterType())) { - this.bindingRegistrar.registerReflectionHints(hints, getMessageType(methodParameter)); + Type messageType = getMessageType(methodParameter); + if (messageType != null) { + this.bindingRegistrar.registerReflectionHints(hints, messageType); + } } else if (couldBePayload(methodParameter)) { this.bindingRegistrar.registerReflectionHints(hints, methodParameter.getGenericParameterType()); diff --git a/spring-web/src/main/java/org/springframework/web/bind/annotation/ControllerMappingReflectiveProcessor.java b/spring-web/src/main/java/org/springframework/web/bind/annotation/ControllerMappingReflectiveProcessor.java index 5095fb8e8f89..9124b8c23caf 100644 --- a/spring-web/src/main/java/org/springframework/web/bind/annotation/ControllerMappingReflectiveProcessor.java +++ b/spring-web/src/main/java/org/springframework/web/bind/annotation/ControllerMappingReflectiveProcessor.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2023 the original author or authors. + * Copyright 2002-2024 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -84,7 +84,10 @@ protected void registerParameterTypeHints(ReflectionHints hints, MethodParameter this.bindingRegistrar.registerReflectionHints(hints, methodParameter.getGenericParameterType()); } else if (HttpEntity.class.isAssignableFrom(methodParameter.getParameterType())) { - this.bindingRegistrar.registerReflectionHints(hints, getHttpEntityType(methodParameter)); + Type httpEntityType = getHttpEntityType(methodParameter); + if (httpEntityType != null) { + this.bindingRegistrar.registerReflectionHints(hints, httpEntityType); + } } } @@ -94,7 +97,10 @@ protected void registerReturnTypeHints(ReflectionHints hints, MethodParameter re this.bindingRegistrar.registerReflectionHints(hints, returnTypeParameter.getGenericParameterType()); } else if (HttpEntity.class.isAssignableFrom(returnTypeParameter.getParameterType())) { - this.bindingRegistrar.registerReflectionHints(hints, getHttpEntityType(returnTypeParameter)); + Type httpEntityType = getHttpEntityType(returnTypeParameter); + if (httpEntityType != null) { + this.bindingRegistrar.registerReflectionHints(hints, httpEntityType); + } } }