@@ -149,25 +149,26 @@ private List<MergedAnnotation<A>> findParameterAnnotations(Parameter current) {
149
149
}
150
150
Executable executable = current .getDeclaringExecutable ();
151
151
if (executable instanceof Method method ) {
152
- Class <?> clazz = method .getDeclaringClass ();
153
- Set <Class <?>> visited = new HashSet <>();
154
- while (clazz != null && clazz != Object .class ) {
155
- directAnnotations = findClosestParameterAnnotations (method , clazz , current , visited );
156
- if (!directAnnotations .isEmpty ()) {
157
- return directAnnotations ;
158
- }
159
- clazz = clazz .getSuperclass ();
152
+ directAnnotations = findClosestParameterAnnotations (method , method .getDeclaringClass (), current ,
153
+ new HashSet <>());
154
+ if (!directAnnotations .isEmpty ()) {
155
+ return directAnnotations ;
160
156
}
161
157
}
162
158
return Collections .emptyList ();
163
159
}
164
160
165
161
private List <MergedAnnotation <A >> findClosestParameterAnnotations (Method method , Class <?> clazz , Parameter current ,
166
162
Set <Class <?>> visited ) {
167
- if (!visited .add (clazz )) {
163
+ if (clazz == null || clazz == Object . class || !visited .add (clazz )) {
168
164
return Collections .emptyList ();
169
165
}
170
- List <MergedAnnotation <A >> annotations = new ArrayList <>(findDirectParameterAnnotations (method , clazz , current ));
166
+ List <MergedAnnotation <A >> directAnnotations = findDirectParameterAnnotations (method , clazz , current );
167
+ if (!directAnnotations .isEmpty ()) {
168
+ return directAnnotations ;
169
+ }
170
+ List <MergedAnnotation <A >> annotations = new ArrayList <>(
171
+ findClosestParameterAnnotations (method , clazz .getSuperclass (), current , visited ));
171
172
for (Class <?> ifc : clazz .getInterfaces ()) {
172
173
annotations .addAll (findClosestParameterAnnotations (method , ifc , current , visited ));
173
174
}
0 commit comments