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

Summary: Add null checker annotations for methods that check for null
Product: java Reporter: SirIntellegence
Component: HintsAssignee: Svata Dedic <sdedic>
Status: NEW ---    
Severity: normal    
Priority: P3    
Version: 8.0.2   
Hardware: All   
OS: All   
Issue Type: ENHANCEMENT Exception Reporter:
Bug Depends on: 249320    
Bug Blocks:    

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 ...