This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

Bug 252816 - Add null checker annotations for methods that check for null
Summary: Add null checker annotations for methods that check for null
Status: NEW
Alias: None
Product: java
Classification: Unclassified
Component: Hints (show other bugs)
Version: 8.0.2
Hardware: All All
: P3 normal with 1 vote (vote)
Assignee: Svata Dedic
URL:
Keywords:
Depends on: 249320
Blocks:
  Show dependency tree
 
Reported: 2015-06-04 20:38 UTC by SirIntellegence
Modified: 2015-09-11 14:13 UTC (History)
0 users

See Also:
Issue Type: ENHANCEMENT
Exception Reporter:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description SirIntellegence 2015-06-04 20:38:16 UTC
Say you have a method called ArgCheck.notNull(Object param, String paramName) that checks to see if a parameter is not null and throws an exception with paramName if it is. It would be great if one could annotate param in such a way that the ide knows that param cannot be null after this method is invoked or something like that. Another example:
boolean foo(String bar){
    if (StringUtilities.isBlank(bar)){
        return false;
    }
    //logic
    int thing = bar.length(); //<- no null warning
    //more stuff
}
Comment 1 SirIntellegence 2015-07-31 19:01:34 UTC
I have an idea. You could add annotations for parameters. For example, with a method that returns a boolean and takes an object, you could annotate the argument with:
@NullTrue
or
@NullFalse
To tell the IDE what value gets returned when null is passed in. You could also add @NullException to indicate that an exception will be thrown if the item is null.
Comment 2 Svata Dedic 2015-07-31 19:16:17 UTC
Yes, this would be useful. I plan, in the future, some metadata (perhaps distilled from annotations, but also should be specified in text files for e.g. 3rd party libraries). There's a lot what a method can do -- param may be known to be null, or nullable (sometimes null), the method may throw an exception, return a non-null or nullable ...