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

Bug 484735

Summary: [1.8][compiler][null] Incorrect analysis of nullability concerning a type variable in a loop.
Product: [Eclipse Project] JDT Reporter: Sergey Olefir <solf.gm>
Component: CoreAssignee: Stephan Herrmann <stephan.herrmann>
Status: CLOSED DUPLICATE QA Contact:
Severity: normal    
Priority: P3 CC: register.eclipse, stephan.herrmann
Version: 4.5.1   
Target Milestone: 4.6 M5   
Hardware: PC   
OS: Windows 7   
Whiteboard:
Attachments:
Description Flags
Eclipse project demonstrating the problem none

Description Sergey Olefir CLA 2015-12-20 12:34:08 EST
Created attachment 258816 [details]
Eclipse project demonstrating the problem

Analysis appears to ignore assignments to variable value in the loop and therefore complains that the variable is always null (including 'dead code' warning).


Steps:
Eclipse eclipse-jee-mars-1-win32-x86_64.zip

Help->About:
Version: Mars.1 Release (4.5.1)
Build id: 20150924-1200

JDT core
org.eclipse.jdt.core_3.11.1.v20150902-1521.jar

java -version
java version "1.8.0_20"
Java(TM) SE Runtime Environment (build 1.8.0_20-b26)
Java HotSpot(TM) 64-Bit Server VM (build 25.20-b23, mixed mode)


Project is attached with all relevant settings set at project level.

Use "Import existing project into workspace" functionality.

See NullabilityLoopBug.java (in case no warnings are reported, make trivial change (e.g. add space) and re-save).
Comment 1 Stephan Herrmann CLA 2015-12-20 13:12:09 EST
Thanks, I can reproduce on 4.5.1 as well as on 4.6M4.

The problem relates to the type variable K, if you replace all occurrences of K with String (in getKeyByValue()), no warning is reported.
Comment 2 Till Brychcy CLA 2015-12-21 02:45:11 EST
This is a variation of the problem reported by me in bug 467482 (and the patch for that bug fixes it)
Comment 3 Stephan Herrmann CLA 2015-12-22 12:49:20 EST
(In reply to Till Brychcy from comment #2)
> This is a variation of the problem reported by me in bug 467482 (and the
> patch for that bug fixes it)

You're right!

To document the relevance of type variables: the 'K' type of 'entry.getKey()' has unknown nullness, because its a free type variable. By replacing K with concrete type String it would get affected by @NNBD, but 'K' itself is not affected.

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