Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check all superclasses for parameter annotations of the given method #4002

Closed
j-wrensch opened this issue Aug 19, 2021 · 1 comment
Closed

Comments

@j-wrensch
Copy link
Contributor

Currently getParameterAnnotations(Method method) of the ReflectionUtils only checks the direct superclass for futher parameter annotations. If the method is overridden more than once, annotations wont be found if they are not declared in the declaring class of the method or its direct superclass.

Current Implementation:

 public static Annotation[][] getParameterAnnotations(Method method) {
        Annotation[][] methodAnnotations = method.getParameterAnnotations();
        Method overriddenmethod = getOverriddenMethod(method);

        if (overriddenmethod != null) {
            Annotation[][] overriddenAnnotations = overriddenmethod
                    .getParameterAnnotations();

            for (int i = 0; i < methodAnnotations.length; i++) {
                List<Type> types = new ArrayList<>();
                for (int j = 0; j < methodAnnotations[i].length; j++) {
                    types.add(methodAnnotations[i][j].annotationType());
                }
                for (int j = 0; j < overriddenAnnotations[i].length; j++) {
                    if (!types.contains(overriddenAnnotations[i][j]
                            .annotationType())) {
                        methodAnnotations[i] = ArrayUtils.add(
                                methodAnnotations[i],
                                overriddenAnnotations[i][j]);
                    }
                }

            }
        }
        return methodAnnotations;
    }

I will link a pull request that can solve this issue.

j-wrensch added a commit to j-wrensch/swagger-core that referenced this issue Aug 19, 2021
frantuma pushed a commit that referenced this issue Aug 19, 2021
@frantuma
Copy link
Member

Thanks for looking into this and for the fix. Fixed in #4003

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants