| 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: | Core | Assignee: | 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: |
|
||||||
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. This is a variation of the problem reported by me in bug 467482 (and the patch for that bug fixes it) (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 *** |
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).