Bug 330328

Summary: "[].length" attribute has null getDeclaringClass()
Product: [Eclipse Project] JDT Reporter: Nicolas Anquetil <anquetil.nicolas>
Component: CoreAssignee: Srikanth Sankaran <srikanth_sankaran>
Status: VERIFIED INVALID QA Contact:
Severity: normal    
Priority: P3 CC: amj87.iitr, Olivier_Thomann, srikanth_sankaran
Version: 3.7   
Target Milestone: 3.7 M4   
Hardware: Macintosh   
OS: Linux   
Whiteboard:
Attachments:
Description Flags
An Eclipse Java Project exemplifying the bug none

Description Nicolas Anquetil CLA 2010-11-16 05:13:16 EST
Build Identifier: I20100608-0911

[also reported in JDT Forum, message #639249]

I am using JDT in batch mode as a parser that resolves bindings (thank for it).

In the resulting AST built by the JDT Parser, accesses to the "length" attribute of an array is a FieldAccess ASTNode (which is perfectly ok)

If I get the binding of this node (node.resolveFieldBinding()) I get an IVariableBinding. Now if I do a getDeclaringClass() on this binding, the result is null.

The problem is, how do I know that the 'null' does not come from a missing binding (some problem in the parsing), but from the fact that this is an array's attribute?



Reproducible: Always

Steps to Reproduce:
1.Import the project attached to this bug report
2.Run the class BugParser on itself (inside eclipse or outside it: "java BugParser BugParser")
3.A message appears on the console when the bug is discovered in the AST Visitor
Comment 1 Nicolas Anquetil CLA 2010-11-16 05:19:05 EST
Created attachment 183206 [details]
An Eclipse Java Project exemplifying the bug

As explained in the bug report, this is a Java project that exemplifies the bug.

The sole class is a JDT batch parser that when run on itself (when analyzing its own code) shows that the "length" attribute used in the method "performCompilation()" results in a IVariableBinding that has no DeclaringClass
Comment 2 Nicolas Anquetil CLA 2010-11-16 05:20:24 EST
Probably not significant, but the bug was found on a MacBook Pro (a Macintosh therefore) but running Ubuntu 10.10, not MacOS
Comment 3 Ayushman Jain CLA 2010-11-16 05:43:12 EST
The compiler usually returns a ProblemBinding in cases where there was a parsing error / invalid construct, etc. It definitely wont return null in such cases. Also, in this case, I'm not sure what else can the compiler return as a binding from getDeclaringClass().

Srikanth, whats your take?
Comment 4 Srikanth Sankaran CLA 2010-11-16 08:03:33 EST
This is the expected behavior. See the javadoc on org.eclipse.jdt.core.dom.IVariableBinding.getDeclaringClass()

Also see https://bugs.eclipse.org/bugs/show_bug.cgi?id=14322#c3
and https://bugs.eclipse.org/bugs/show_bug.cgi?id=9016#c2
Comment 5 Olivier Thomann CLA 2010-11-16 08:39:48 EST
I would also add that you should not use internal code inside your own code. That code can change from release to release. You can easily use DOM/AST API without referring to internal compiler code.