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 244345

Summary: False hint - possible null (ignoring equals test)
Product: java Reporter: PavelCibulka
Component: HintsAssignee: Svata Dedic <sdedic>
Status: RESOLVED DUPLICATE    
Severity: normal    
Priority: P3    
Version: 8.0   
Hardware: All   
OS: All   
Issue Type: DEFECT Exception Reporter:

Description PavelCibulka 2014-05-07 07:37:11 UTC
Hints engine ignore equals method tests. Equals method return false, if argument is null. This method can be considered for possible null hint.

Example code:

    @Nonnull
    public static String test(@Nullable String value){
        if(!"test".equals(value)){
            return "something";
        }
        return value;
    }

Netbeans report possible null on "return value;". But this is not possible, because of equals test.

It is easy to understand for programmer. I'm not sure, if it would be possible to include this in hints engine.
Comment 1 Svata Dedic 2014-06-06 21:21:11 UTC

*** This bug has been marked as a duplicate of bug 226083 ***
Comment 2 Svata Dedic 2014-06-06 21:24:04 UTC
We can assume that if a.equals(b), then b != null - otherwise equals contract would be severely broken for a.