Skip to content

AnnotationUtils.isAnnotationMetaPresent(…) no longer considers javax.annotation.Nonnull #22685

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

Closed
Tracked by #22560
mp911de opened this issue Mar 26, 2019 · 3 comments
Assignees
Labels
type: regression A bug that is also a regression
Milestone

Comments

@mp911de
Copy link
Member

mp911de commented Mar 26, 2019

Consider the following code in which a package is annotated with @NonNullApi:

package-info.java

@NonNullApi
package foo;

import org.springframework.lang.NonNullApi;

Reproducer

package foo;

import javax.annotation.Nonnull;

import org.junit.Test;

import org.springframework.core.annotation.AnnotationUtils;
import org.springframework.lang.NonNullApi;

import static org.junit.Assert.*;

public class ReproducerTest {

	@Test
	public void shouldFindMetaAnnotation() {

		NonNullApi annotation = getClass().getPackage().getAnnotation(NonNullApi.class);

		assertTrue(AnnotationUtils.isAnnotationMetaPresent(annotation, javax.annotation.Nonnull.class));
	}
}

Using AnnotationUtils.isAnnotationMetaPresent(…) for annotation discovery fails to report that NonNullApi is a meta-annotation for javax.annotation.Nonnull.

Spring Data uses JSR 305-based nullability inference for repository method arguments and return value inspection

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Mar 26, 2019
@jhoeller jhoeller self-assigned this Mar 26, 2019
@jhoeller jhoeller added type: regression A bug that is also a regression and removed status: waiting-for-triage An issue we've not yet triaged or decided on labels Mar 26, 2019
@jhoeller jhoeller added this to the 5.2 M1 milestone Mar 26, 2019
@mp911de
Copy link
Member Author

mp911de commented Mar 27, 2019

We have the same issue for meta-annotations originating from JSR305, e.g. javax.annotation.ParametersAreNonnullByDefault. This is a meta-annotation for javax.annotation.Nonnull. Do you want to fix the issue with the same ticket or should we create a new ticket?

@jhoeller
Copy link
Contributor

Let's use the same ticket. It seems we need to apply the same code path to meta-annotated javax.annotation types.

@jhoeller jhoeller reopened this Mar 27, 2019
@jhoeller jhoeller changed the title AnnotationUtils.isAnnotationMetaPresent(…) no longer considers NonNullApi as meta annotation for javax.annotation.Nonnull AnnotationUtils.isAnnotationMetaPresent(…) no longer considers javax.annotation.Nonnull Mar 27, 2019
@jhoeller
Copy link
Contributor

A quick note: AnnotationUtils.isAnnotationMetaPresent is deprecated as of 5.2, along with several other too-specific utility methods. Alternatively, for a unified method, AnnotatedElementUtils.isAnnotated (which covers meta-annotations as well) remains non-deprecated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: regression A bug that is also a regression
Projects
None yet
Development

No branches or pull requests

3 participants