Community
Participate
Working Groups
// Compile this import java.util.Date; public class WrongRedundantNullCheck { private static void occasionallyThrowException() throws Exception { if ((System.currentTimeMillis() & 1L) != 0L) throw new Exception(); } private static Date createDate() throws Exception { occasionallyThrowException(); return new Date(); } public static void main(String s[]) { Date d = null; try { d = createDate(); System.out.println(d.toString()); try { occasionallyThrowException(); } catch (Exception exc) { } } catch (Exception exc) { if (d != null) // Wrong warning in this line System.out.println(d.toString()); } } }
Thanks also for this report. Similar to bug 401088 we have a problem with propagating effects from nested structures to their enclosing. Here information was propagated as definite, where effects only potentially affected the outer. Specifically, the information that after "d.toString()" 'd' is known to be non-null was unconditionally propagated into the catch block. This was wrong because because the catch block could also be entered before reaching that expression. I have a simple fix currently being tested.
Released for 4.3 M6 via commit cb53e8ef7dbddd81476e4e3730055f3778cd8c71
Verified for 4.3 M6 using Build id: I20130310-2000