| Summary: | [null] null-free map is not null-free | ||
|---|---|---|---|
| Product: | [Eclipse Project] JDT | Reporter: | Ed Willink <ed> |
| Component: | Core | Assignee: | JDT-Core-Inbox <jdt-core-inbox> |
| Status: | CLOSED WONTFIX | QA Contact: | |
| Severity: | normal | ||
| Priority: | P3 | ||
| Version: | 4.5 | ||
| Target Milestone: | --- | ||
| Hardware: | PC | ||
| OS: | Windows NT | ||
| Whiteboard: | stalebug | ||
This bug hasn't had any activity in quite some time. Maybe the problem got resolved, was a duplicate of something else, or became less pressing for some reason - or maybe it's still relevant but just hasn't been looked at yet. If you have further information on the current state of the bug, please add it. The information can be, for example, that the problem still occurs, that you still want the feature, that more information is needed, or that the bug is (for whatever reason) no longer relevant. -- The automated Eclipse Genie. |
The example below demonstrates a rather evil misdiagnosis that a variable cannot be null, when it can. If the diagnostic is exploited by the priogrammer to eliminate the "redundant null check" the program becomes buggy. The problem is that the call to initializeStrings is not diagnosed as unsafe. IMHO passing an @NonNull template parameter to undeclared-null must be at least a warning and quite probably an error. import java.util.HashMap; import java.util.Map; import org.eclipse.jdt.annotation.NonNull; public class Test { public static void main(String[] args) { Map<@NonNull String, @NonNull String> nonNullString2nonNullString = new HashMap<@NonNull String, @NonNull String>(); initializeStrings(nonNullString2nonNullString); // There should be a warning/error here for (Map.Entry<@NonNull String, @NonNull String> entry : nonNullString2nonNullString.entrySet()) { String value = entry.getValue(); if (value != null) { // "Redundant null check: The variable value cannot be null at this location" value.toString(); } } } private static void initializeStrings(Map<String, String> bindings) { bindings.put(null, null); } }