Bug 401017 - [compiler][null] casted reference to @Nullable field lacks a warning
Summary: [compiler][null] casted reference to @Nullable field lacks a warning
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 4.3   Edit
Hardware: All All
: P3 normal (vote)
Target Milestone: 4.3 M6   Edit
Assignee: Stephan Herrmann CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2013-02-17 13:53 EST by Stephan Herrmann CLA
Modified: 2013-03-12 01:52 EDT (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Stephan Herrmann CLA 2013-02-17 13:53:48 EST
From bug 378724 comment 15:

----
Cast obscures nullness of a field:

class NPEonCast {

    @Nullable
    private Object nullable;

    public void test() {
        if (nullable instanceof Number) {
            ((Number)nullable).intValue(); // A
        }
        if (nullable != null) {
            nullable.toString(); // B
        }
        nullable.toString(); // C
    }

}

Error missing for A (while correct for B and C)
----

While the result would be correct when syntactic analysis for fields is enabled (because the instanceof provides protection), without syntactic analysis we should see a warning, which we don't.
Comment 1 Stephan Herrmann CLA 2013-02-18 09:45:54 EST
Trivial fix has been released for 4.3 M6 via commit 78e5ed0e34672db495ea2a17471c36349086fcd0
Comment 2 Srikanth Sankaran CLA 2013-03-12 01:52:42 EDT
Verified for 4.3 M6 using Build id: I20130310-2000