Added null annotations for Field#235
Conversation
smillst
left a comment
There was a problem hiding this comment.
Because passing null to these methods may result in a NPE, these parameters cannot be annotated with @Nullable. See https://checkerframework.org/manual/#nullness-jdk-conservative for a more detailed explanation. We would accept these in the stub file https://github.com/typetools/checker-framework/blob/master/checker/src/main/java/org/checkerframework/checker/nullness/sometimes-nullable.astub.
Thanks!
|
@smillst would I need to copy over all the other annotations on those function signatures? or is that sometimes file additive? |
| @CallerSensitive | ||
| @ForceInline // to ensure Reflection.getCallerClass optimization | ||
| public @Nullable Object get(@GuardSatisfied Field this, @GuardSatisfied Object obj) | ||
| public @Nullable Object get(@GuardSatisfied Field this, @GuardSatisfied @Nullable Object obj) |
There was a problem hiding this comment.
I just ran into this in some of my code. Is there a better way to get a static field in a null-safe way? Or is the best advice to suppress nullness warnings at the point where we call Field.get(null) ?
I've kept these changes in a separate PR, for one thing since I saw that in
AccessibleObject::canAccess@cpovirk in aadd76c added a comment about this, so this might be something where you want to be stricter?As in, you can pass in a null if you're doing reflection to static fields/methods, but I guess it's more common that you intend to use it with an object instance?