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