Community
Participate
Working Groups
HEAD public class Snippet { public static void main(String[] args) { String test = null; test += "... some text"; if (test != null) { System.out.println("It worked!"); } } } Above case gives a bogus "null comparison always yields false" warning.
Note that: test = test + "... some text"; removes the dead code warning properly. So there is a missing reset of null info for the org.eclipse.jdt.internal.compiler.ast.CompoundAssignment.
See also: bug #339276
Created attachment 190734 [details] possible fix I observed that this kind of behaviour can only occur in the case of a String. This is because anything can be added to a null String, even the null literal itself. So, test = null; // test is null test += null; // test has a nonnull value i.e. "nullnull" test += "abc"; // test has a value "nullnullabc" For base types, such as int, float, etc. we dont need the null info, and for Integer,Float, etc, the null info will never change in a compound assignment operator. Hence, this fix takes care of compound assign. for a String variable, and makes it definitely non null.
Created attachment 190741 [details] proposed fix v1.0 + tests Same fix with added tests Olivier, please review. Thanks!
Looks ok. Since it works fine, I would be tempted to release this as part of M6. Ayushman, what do you think ?
*** Bug 339276 has been marked as a duplicate of this bug. ***
Released for 3.7M6 on the behalf of Ayushman.
Verified for 3.7M6.