How to use @Nullable and @Nonnull annotations more effectively?

后端 未结 9 443
你的背包
你的背包 2020-12-12 12:01

I can see that @Nullable and @Nonnull annotations could be helpful in preventing NullPointerExceptions but they do not propag

9条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-12 12:45

    What I do in my projects is to activate the following option in the "Constant conditions & exceptions" code inspection:
    Suggest @Nullable annotation for methods that may possibly return null and report nullable values passed to non-annotated parameters

    When activated, all non-annotated parameters will be treated as non-null and thus you will also see a warning on your indirect call:

    clazz.indirectPathToA(null); 
    

    For even stronger checks the Checker Framework may be a good choice (see this nice tutorial.
    Note: I have not used that yet and there may be problems with the Jack compiler: see this bugreport

提交回复
热议问题