Bug 23048

Summary: DOM - lazy initialization of empty loop bodies causes binding resolution to fail
Product: [Eclipse Project] JDT Reporter: mark_dixon
Component: CoreAssignee: Olivier Thomann <Olivier_Thomann>
Status: VERIFIED FIXED QA Contact:
Severity: normal    
Priority: P3    
Version: 2.0   
Target Milestone: 2.1 M1   
Hardware: PC   
OS: Windows 2000   
Whiteboard:

Description mark_dixon CLA 2002-08-30 15:54:10 EDT
Using build I200208270833

Running this code

IWorkspace ws = testcasesPlugin.getWorkspace();
IWorkspaceRoot root = ws.getRoot();
IProject project = root.getProjects()[0];
IJavaProject jp = JavaCore.create(project);
		
CompilationUnit cu = AST.parseCompilationUnit(
   "public class Class {void theMethod() {for (int i = 0; i < 5; ++i); theMethod
();}}".toCharArray(),
   "Class", jp);
cu.accept(new ASTVisitor() {
   public boolean visit(SimpleName node) {
      IBinding binding = node.resolveBinding();
      if (null == binding) {
         System.out.println("Null binding for SimpleName " + node.getIdentifier
());
      }
      return true;
   }
});

produces the output
Null binding for SimpleName i
Null binding for SimpleName theMethod

The null binding for 'i' is, I assume, bug 11529.  The null binding for the 
invocation of theMethod is caused by the call to ForStatement.getBody() in 
ForStatement.accept0().  This calls ForStatement.setBody() because the for 
statement had an empty body.  The call to setBody changes the modification 
count on the AST which causes all further attempts at binding resolution to 
return null.  I think the lazy initialization has to go :-)  Similarly for 
other loops.

Thanks
Mark
Comment 1 Olivier Thomann CLA 2002-09-03 11:07:21 EDT
The body of the forStatement should be set during the conversion. I will
investigate.
Comment 2 Olivier Thomann CLA 2002-09-03 12:47:35 EDT
This is an issue related to the empty statement. I am looking into it. Other
statements are broken and I'd like to fix all of them at the same time.
Comment 3 Olivier Thomann CLA 2002-09-03 14:45:47 EDT
Fixed and released in 2.1 stream.
Comment 4 David Audel CLA 2002-09-19 04:49:05 EDT
Verified.
Comment 5 Olivier Thomann CLA 2002-09-19 11:08:23 EDT
Regression tests added (test0371, test0372)