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

AnnotationTypeMappings does not filter repeatable annotations #25483

Closed
wants to merge 4 commits into from

Conversation

yilianhuaixiao
Copy link
Contributor

since
if (!isMappable(source, metaAnnotation)) { continue; }
is called before and 'source' ,'metaAnnotation' did not changed.
The code should be deleted.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Jul 28, 2020
@@ -91,9 +91,6 @@ private void addMetaAnnotationsToQueue(Deque<AnnotationTypeMapping> queue, Annot
.findRepeatedAnnotations(metaAnnotation);
if (repeatedAnnotations != null) {
for (Annotation repeatedAnnotation : repeatedAnnotations) {
if (!isMappable(source, metaAnnotation)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm wondering if that was perhaps a copy-and-paste error and if it should rather be:

if (!isMappable(source, repeatedAnnotation)) {
    continue;
}

@philwebb, what are your thoughts on the matter?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@philwebb, I'm assuming my above assumption is correct. (I know: a lot of assuming).

In light of that, we'll go forward with the change in this PR.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it was a typo. A little concerning that no test covered it.

@sbrannen sbrannen requested a review from philwebb July 28, 2020 08:37
@sbrannen sbrannen self-assigned this Jul 28, 2020
@sbrannen sbrannen added in: core Issues in core modules (aop, beans, core, context, expression) status: waiting-for-feedback We need additional information before we can continue labels Jul 28, 2020
@sbrannen sbrannen marked this pull request as draft July 28, 2020 08:38
@sbrannen sbrannen changed the title code optimized Optimize code in AnnotationTypeMappings Jul 28, 2020
@yilianhuaixiao
Copy link
Contributor Author

@sbrannen Yes, I think you are right

@spring-projects-issues spring-projects-issues added status: feedback-provided Feedback has been provided and removed status: waiting-for-feedback We need additional information before we can continue labels Jul 28, 2020
@yilianhuaixiao yilianhuaixiao marked this pull request as ready for review July 28, 2020 08:50
@sbrannen
Copy link
Member

@yilianhuaixiao with your latest commit that fixes the issue, please introduce a test that fails before the fix and passes after the fix.

@sbrannen sbrannen added status: waiting-for-feedback We need additional information before we can continue and removed status: feedback-provided Feedback has been provided labels Jul 28, 2020
@yilianhuaixiao
Copy link
Contributor Author

@sbrannen I added the testcase which can be passed after changing.

@spring-projects-issues spring-projects-issues added status: feedback-provided Feedback has been provided and removed status: waiting-for-feedback We need additional information before we can continue labels Jul 29, 2020
@sbrannen sbrannen added type: bug A general bug and removed status: waiting-for-triage An issue we've not yet triaged or decided on labels Jul 29, 2020
@sbrannen sbrannen added this to the 5.2.9 milestone Jul 29, 2020
@sbrannen sbrannen changed the title Optimize code in AnnotationTypeMappings AnnotationTypeMappings does not filter repeated annotations Jul 29, 2020
void forAnnotationTypeWhenRepeatableMetaAnnotationFilterd() {
AnnotationTypeMappings mappings = AnnotationTypeMappings.forAnnotationType(WithRepeatedMetaAnnotations.class,
annotationType ->
ObjectUtils.nullSafeEquals(annotationType, Repeating.class.getName()));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You omitted the import for ObjectUtils, but don't worry about it. I'll add it before merging.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For future reference, I was able to simplify the annotation filter in that test method as follows.

@Test
void forAnnotationTypeWhenRepeatableMetaAnnotationIsFiltered() {
	AnnotationTypeMappings mappings = AnnotationTypeMappings.forAnnotationType(WithRepeatedMetaAnnotations.class,
			Repeating.class.getName()::equals);
	assertThat(getAll(mappings)).flatExtracting(AnnotationTypeMapping::getAnnotationType)
			.containsExactly(WithRepeatedMetaAnnotations.class);
}

However, I won't be merging that change due to reasons I'll explain later.

@sbrannen sbrannen added type: task A general task and removed type: bug A general bug status: feedback-provided Feedback has been provided labels Jul 29, 2020
@sbrannen sbrannen marked this pull request as draft July 29, 2020 11:54
@sbrannen
Copy link
Member

@yilianhuaixiao, thanks again for the PR and the test case!

It turns out that AnnotationTypeMappings.forAnnotationType(Class<? extends Annotation>, AnnotationFilter) is not invoked outside of the AnnotationTypeMappings class itself.

It is only invoked from AnnotationTypeMappings.forAnnotationType(Class<? extends Annotation>), with AnnotationFilter.PLAIN as the supplied annotation filter, which filters out annotations from the java.lang and org.springframework.lang packages.

Since none of the annotations from the java.lang and org.springframework.lang packages is repeatable, the filtering of repeatable annotations is unnecessary.

In light of that, I am changing this from a "bug" to a "task" issue in order to remove the method from the package-private API and to remove the filtering of repeatable annotations altogether.

@sbrannen sbrannen changed the title AnnotationTypeMappings does not filter repeated annotations AnnotationTypeMappings does not filter repeatable annotations Jul 29, 2020
@sbrannen
Copy link
Member

It turns out that AnnotationTypeMappings.forAnnotationType(Class<? extends Annotation>, AnnotationFilter) is not invoked outside of the AnnotationTypeMappings class itself.

Actually, I made a mistake while analyzing this in my IDE. An AnnotationFilter can be supplied to AnnotationTypeMappings via the from factory methods in TypeMappedAnnotations via the from factory methods in MergedAnnotations which are part of the public API.

Thus, we will merge this PR as a bug fix.

@sbrannen sbrannen added type: bug A general bug and removed type: task A general task labels Jul 29, 2020
@yilianhuaixiao yilianhuaixiao marked this pull request as ready for review July 30, 2020 01:22
sbrannen added a commit that referenced this pull request Jul 30, 2020
@sbrannen sbrannen closed this in 83a9583 Jul 30, 2020
@sbrannen
Copy link
Member

This has been merged into 5.2.x and master.

Thanks

FelixFly pushed a commit to FelixFly/spring-framework that referenced this pull request Aug 16, 2020
Prior to this commit, AnnotationTypeMappings did not filter repeatable
annotations with the supplied annotation filter.

Closes spring-projectsgh-25483
FelixFly pushed a commit to FelixFly/spring-framework that referenced this pull request Aug 16, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: core Issues in core modules (aop, beans, core, context, expression) type: bug A general bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants