-
Notifications
You must be signed in to change notification settings - Fork 48
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
Remove redundant targets from Nullability-annotations #37
Comments
This may cause source incompatibility, in particular with qualified class names. E.g.: @NotNull Outer.Inner getInner(); Now, this is compilable (because NotNull has METHOD target) and interpreted as Another problem is Groovy. AFAIK it doesn't support type annotations at all. Now, it's possible to use java-annotations package in mixed Groovy-Java projects and annotate Groovy method parameters, return types, and fields. It would be problematic if we remove redundant targets. I see the JavaDoc problem but I believe it should be fixed in JavaDoc tool. So consider reporting it there. Probably at some day this change will be implemented, so I'm not closing this. Still, I think it's too early now to do this. |
I've had created a test class with both multi-target and single-target annotations and now it looks like Javadoc's behaviour is correct from point of classfile info: Test classimport java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import java.lang.reflect.Method;
import java.util.Arrays;
class Scratch {
public static void main(String[] args) throws NoSuchMethodException {
final Method method = Scratch.class.getDeclaredMethod("foo", Object.class);
System.out.println(" PARAMETER: " + Arrays.deepToString(method.getParameterAnnotations()));
System.out.println(" METHOD: " + Arrays.toString(method.getAnnotations()));
System.out.println(" TYPE_USE(Method): " + method.getAnnotatedReturnType());
System.out.println("TYPE_USE(Parameter): " + Arrays.toString(method.getAnnotatedParameterTypes()));
}
private static @Wide @Specific Object foo(final @Wide @Specific Object param) {
return param;
}
@Retention(RetentionPolicy.RUNTIME)
@Target({
ElementType.METHOD, ElementType.FIELD, ElementType.PARAMETER,
ElementType.LOCAL_VARIABLE, ElementType.TYPE_USE
})
public @interface Wide {}
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE_USE)
public @interface Specific {}
} Output
As can be seen, at it is correct that from classfile point both
As of this, it actually is a problem, I agree, but I fell like it is worth implementing this change (probably, under a major version bump) as at current state its backwards compatibility causing issues for latest stable users.
As an option, those clients who currently have forward-incompatible changes would simply have an ability to stick to current version (e.g. 20.1.0) while letting up-to-date users move to something like 21.0.0 with these target limitations. As for me it is also a moral question of supporting the |
Any news about this? maybe im wrong but this is related to #35 not? existing https://bugs.openjdk.org/browse/JDK-8278592 with not so many comments for a fix sorry for answer a old issue if maybe im wrong. |
No, no news. As it was stated above, removing old targets would pose a source compatibility problem. There's no clean deprecation path available in this case. And we are not responsible for fixing Javadoc tool bugs. |
At current both
@NotNull
and@Nullable
have quite broad scopes which commonly overlap:java-annotations/common/src/main/java/org/jetbrains/annotations/Nullable.java
Line 39 in d7c469b
java-annotations/common/src/main/java/org/jetbrains/annotations/NotNull.java
Line 29 in d7c469b
While this is required for java5 (which obviously does not have
ElementType.TYPE_USE
) it is more of an issue rather than a feature on java 8+. I.e. overlapping scopes lead to tools such as Javadoc recognizing both targets as matched thus leading to issues such as duplication of the annotation in documentation in case of the latter.Thus I suggest keeping only
ElementType.TYPE_USE
on these annotations in java8 version of the project, and keeping only{ElementType.METHOD, ElementType.FIELD, ElementType.PARAMETER, ElementType.LOCAL_VARIABLE}
on java5 version.If this gets approved I am ready to create the corresponding PR.
The text was updated successfully, but these errors were encountered: