Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 498726

Summary: final @Nullable fields require an extra local variable, even though they can't change?
Product: [Eclipse Project] JDT Reporter: Phil Schwan <phils>
Component: CoreAssignee: JDT-Core-Inbox <jdt-core-inbox>
Status: CLOSED DUPLICATE QA Contact:
Severity: normal    
Priority: P3 CC: register.eclipse
Version: 4.5.2   
Target Milestone: ---   
Hardware: PC   
OS: Linux   
Whiteboard:

Description Phil Schwan CLA 2016-07-27 22:29:00 EDT
I apologise for filing what almost certainly must be a duplicate.  But I've done so many searches, read dozens of bugs, and can't find it.  All I want to do is get on the CC list for updates in the hope that it will some day be fixed...

I'm interested in the very specific case of final fields needing to be retrieved into an extraneous local variable.

The closest thing I found was in bug 237236 comment 17, which I'll simplify even further:

class NullFun {
    private final @Nullable String test = getTest();

    public void doStuff() {
        if (test != null) {
            test.toString();
        }
    }
}

As we all know, Eclipse currently requires this, instead:

    public void doStuff() {
        String localTest = test;
        if (localTest != null) {
            localTest.toString();
        }
    }

This of course would make perfect sense if "test" were *not* final.  But can it not treat "test" the same as "localTest" for the purpose of this check, given that it *is* final?

bug 237236 comment 20 tried to bring some order to the bug 237236 chaos, but comment 17 was seemingly overlooked.

Can anyone shed any light on where this issue now resides?
Comment 1 Till Brychcy CLA 2016-12-16 14:21:03 EST

*** This bug has been marked as a duplicate of bug 509039 ***