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 228583 - Incorrect hint "unnecessary test for null" for member fields of non-null instance
Summary: Incorrect hint "unnecessary test for null" for member fields of non-null inst...
Status: RESOLVED FIXED
Alias: None
Product: java
Classification: Unclassified
Component: Hints (show other bugs)
Version: 7.3
Hardware: PC Windows 7
: P3 normal (vote)
Assignee: Jan Lahoda
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2013-04-15 23:10 UTC by 280Z28
Modified: 2013-04-16 14:20 UTC (History)
1 user (show)

See Also:
Issue Type: DEFECT
Exception Reporter:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description 280Z28 2013-04-15 23:10:45 UTC
In the following code:

@NotNull Foo s = new Foo();
if (s.fieldName == null) {
    ...
}

The expression `s.fieldName == null` is given the incorrect hint "Unnecessary test for null - the expression is never null".

The class Foo is defined as follows:

public class Foo {
    @Nullable
    public Object fieldName;
}

The @NotNull and @Nullable interfaces are defined in the same package as follows.

@java.lang.annotation.Documented
@java.lang.annotation.Retention(java.lang.annotation.RetentionPolicy.CLASS)
@java.lang.annotation.Target({java.lang.annotation.ElementType.FIELD, java.lang.annotation.ElementType.METHOD, java.lang.annotation.ElementType.PARAMETER, java.lang.annotation.ElementType.LOCAL_VARIABLE})
public @interface NotNull {
}

@java.lang.annotation.Documented
@java.lang.annotation.Retention(java.lang.annotation.RetentionPolicy.CLASS)
@java.lang.annotation.Target({java.lang.annotation.ElementType.FIELD, java.lang.annotation.ElementType.METHOD, java.lang.annotation.ElementType.PARAMETER, java.lang.annotation.ElementType.LOCAL_VARIABLE})
public @interface Nullable {
}
Comment 1 Jan Pirek 2013-04-16 07:13:49 UTC
*** Bug 228590 has been marked as a duplicate of this bug. ***
Comment 2 Jan Lahoda 2013-04-16 14:20:03 UTC
Same as bug #228239, as far as I can tell.