-
Notifications
You must be signed in to change notification settings - Fork 38
Description
TLDR; JSpecify might need more java.lang.annotation.Targets then just TYPE_USE for compatibility or some documented work around for annotation processors.
While playing with JSpecify and Eclipse null annotations which both are only TYPE_USE I found the rather disturbing possible bug with the JDK APT framework in that TYPE_USE annotations appear to be stripped from already compiled classes. I stress "appear" because the data is definitely in the class file it just the APT framework does not make it visible.
Let us say we have module ModuleA (aka jar artifact ModuleA) that has a class ClassA. ClassA has a nullable TYPE_USE annotations on some method return type we will call ReturnTypeA:
public class ClassA {
@Nullable ReturnTypeA someMethod() { return null; }
}If we compile ClassA with an annotation processor enabled and somehow navigate to the method someMethod and get the TypeMirror for ReturnTypeA and call TypeMirror.getAnnotationMirrors() the @Nullable will be there. Good. The type is preserved.
Now let us say we have ModuleB that has ClassB like:
public class ClassB {
public ClassA a;
}And again if we compile ModuleB (and thus ClassB) with an annotation processor enabled and navigate to ClassA method someMethod and get the TypeMirror for ReturnTypeA and call TypeMirror.getAnnotationMirrors() the @Nullable WILL BE MISSING regardless of Retention Policy.
This is pretty darn problematic for annotation processors like MapStruct (see mapstruct/mapstruct#1243) or my own library JStachio where we want to know if the type allows nulls or not.
To be honest this seems like a JDK issue because almost all other information is available with TypeElement or TypeMirror as well as you can reflectively get access to the annotations with java.lang.Method.getAnnotatedReturnType(). Furthermore all other annotations that are NOT TYPE_USE are available. Perhaps this is one of the reasons Checkers target basically everything?
@kevinb9n have you guys ran across this at all?