Bug 177863

Summary: [compiler][null] Spurious null pointer warning in finally block (involving def. unknown)
Product: [Eclipse Project] JDT Reporter: Ian Robertson <ianbrobertson>
Component: CoreAssignee: Maxime Daniel <maxime_daniel>
Status: VERIFIED FIXED QA Contact:
Severity: normal    
Priority: P3    
Version: 3.2.2   
Target Milestone: 3.3 M7   
Hardware: PC   
OS: Linux   
Whiteboard:
Attachments:
Description Flags
Fix + test case none

Description Ian Robertson CLA 2007-03-16 20:33:25 EDT
If a previously null variable is set in a finally block, the compiler's null reference check remains convinced that the variable is null:

public class NullBugTest {

  public void foo() {
    Object object = null;
    try {
    }
    finally {
      object = Object.class.getClass();
      // The following line of code warns:
      //   The variable object can only be null; it was either set to null or checked for null when last used
      object.getClass();
    }
  }
}
Comment 1 Ian Robertson CLA 2007-03-16 20:34:02 EDT
This may be releated to bug 176472, but without rooting through eclipse code, it's hard to say.
Comment 2 Maxime Daniel CLA 2007-03-19 03:22:19 EDT
Released (inactive) test NullReferenceTest#532 in HEAD.
Comment 3 Maxime Daniel CLA 2007-03-23 04:02:04 EDT
FinallyFlowContext#recordUsingNullReference missed an early return on definitely unknown variables.
Comment 4 Maxime Daniel CLA 2007-03-23 04:02:35 EDT
Created attachment 61787 [details]
Fix + test case
Comment 5 Maxime Daniel CLA 2007-03-27 01:58:39 EDT
Released for 3.3 M7.
Comment 6 Olivier Thomann CLA 2007-04-27 10:12:48 EDT
Verified for 3.3M7 using I20070427-0010