Bug 13807 - null binding returned for fully qualified array declaration
Summary: null binding returned for fully qualified array declaration
Status: RESOLVED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 2.0   Edit
Hardware: Other other
: P3 normal (vote)
Target Milestone: 2.0 M6   Edit
Assignee: Olivier Thomann CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2002-04-15 12:28 EDT by Jared Burns CLA
Modified: 2002-04-23 15:40 EDT (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Jared Burns CLA 2002-04-15 12:28:53 EDT
We pass the following code in to AST.parseCompilationUnit(char[], String,
IJavaProject):

public class Hello{
static void ___run(java.lang.String[] args) throws Throwable {
java.lang.Object[] obj= new Object[10];
}
public static void main (String[] args){
}
}

We get an AST returned with no errors, however, when we visit the node
corresponding to the java.lang.Object[] declaraction (ArrayType node), calling
node.getElementType().resolveBinding() returns null.

We debugged this a little bit. The first sign of trouble is in the following method:
/*
 * Method declared on BindingResolver.
 */
ITypeBinding resolveType(Type type) {
  if (this.checkModificationCount && this.modificationCount !=
type.getAST().modificationCount()) {
    return null;
  }
  // retrieve the old ast node
  AstNode node = (AstNode) this.newAstToOldAst.get(type);
  if (node != null) {
    ...
  }
  return null;
}
The call to retrieve the old ast node is returning null.
Comment 1 Jared Burns CLA 2002-04-15 12:33:39 EDT
For clarification, the method above is defined in DefaultBindingResolver.
Comment 2 Olivier Thomann CLA 2002-04-15 13:45:42 EDT
I will check that as soon as I finish the performance tests.
Comment 3 Olivier Thomann CLA 2002-04-16 18:32:19 EDT
Fix and released in HEAD.
Comment 4 Jared Burns CLA 2002-04-22 09:28:35 EDT
I'm still getting a null binding returned.

Some info from debugging the method DefaultBindingResolver.resolveType(Type):

1. The method is called with an org.eclipse.jdt.core.dom.ArrayType
2. The parentType is an org.eclipse.jdt.core.dom.ArrayCreation
3. The while loop is never entered
4. The index is 0, so the method falls into the old code: "node = (ASTNode)
this.newAstToOldAst.get(type)
5. The node is null after this call, so null is returned
It looks like the problem stems from the fact that the ArrayType's parent is an
ArrayCreation, which isn't an array type.
Comment 5 Olivier Thomann CLA 2002-04-22 09:33:01 EDT
I will investigate.
Comment 6 Olivier Thomann CLA 2002-04-22 11:19:43 EDT
The firs problem has been fixed, but now you are referring to the 
java.lang.Object[10] part of the source. On my point of view, this is a 
different bug. It might look the same for you, but it is another bug. However 
this one is fixed now and should be released in the next integration build. I 
will double-check the way we resolve ArrayReference and ArrayInitializer.
Comment 7 Jared Burns CLA 2002-04-23 11:29:04 EDT
For the code "java.lang.Object[] obj= new Object[10]", we get three requests to
resolveBinding(Type).

It looks like the first two binding requests are now working properly, but
there's a third request that's failing now.

Just evaluating the code "new Object[10]" is the simplest test case now. When we
visit the AST, we first visit an ArrayCreation node and then an ArrayType node.
This results in two binding resolution requests from us. The first is an
ArrayType with an ArrayCreation parent. This works. The second is a SimpleType
with an ArrayType parent. This fails.

Some info gleaned while debugging:
In the first pass, it falls into your new code ("if (parent instanceof
ArrayCreation)") and it appears to return a good binding.

In the second pass, it falls into the while loop for one iteration, setting
index to 1, parentType to an ArrayCreation, and arrayType to an ArrayType

It then falls into this code:
if (index != 0) {
  node = (AstNode) this.newAstToOldAst.get(arrayType);
}
which returns null node.
Comment 8 Olivier Thomann CLA 2002-04-23 11:37:12 EDT
For the simple type request, I guess you expected the element type binding of the array binding to 
be returned?
Comment 9 Olivier Thomann CLA 2002-04-23 15:40:42 EDT
Hopefully this is finally fixed.