Bug 242961

Summary: [DOM] ITypeBinding.getDeclaredFields returns empty results if any field has undefined type
Product: [Eclipse Project] JDT Reporter: Alan Bram <alan.bram>
Component: CoreAssignee: Olivier Thomann <Olivier_Thomann>
Status: VERIFIED FIXED QA Contact:
Severity: normal    
Priority: P3 CC: daniel_megert, markus.kell.r, Olivier_Thomann, philippe_mulet
Version: 3.4   
Target Milestone: 3.5 M1   
Hardware: PC   
OS: All   
Whiteboard:
Attachments:
Description Flags
Proposed fix
none
Regression test none

Description Alan Bram CLA 2008-08-02 14:01:09 EDT
Build ID: I20080617-2000

Steps To Reproduce:
in a plug-in which supplies an extension to the org.eclipse.core.resources.builders extension point, parse a Java compilation unit called "A.java", containing code like this:

    class A {
        int k;
        B b;
    }

Note: there is no such class named B.

in the plug-in, run some code like this:

parser = ASTParser.newParser(AST.JLS3);

// in the delta visitor of my IncrementalProjectBuilder ...

visit(IResourceDelta d) {
  IResource r = d.getResource();
  IJavaElement je = JavaCore.create(r);
  icu0 = je.getAdapter(ICompilationUnit.class);
  // icu0 != null
  icu = (ICompilationUnit)icu0;
  parser.setSource(icu);
  parser.setResolveBindings(true);
  compilationUnit = (CompilationUnit)parser.createAST(null)
  compilationUnit.accept(new ASTVisitor() {
    public boolean visit(TypeDeclaration typeDeclaration) {
      typeBinding = typeDeclaration.resolveBinding();
      // typeBinding != null
      fields = typeBinding.getDeclaredFields();
      // fields.length == 0

More information:
There is no such class named "B".  However, I expect that getDeclaredFields() should return information about field "k".

This used to work in Eclipse 3.3; it seems to have changed in 3.4.
Comment 1 Olivier Thomann CLA 2008-08-06 10:13:09 EDT
Reproduced.
Comment 2 Olivier Thomann CLA 2008-08-06 10:14:18 EDT
Created attachment 109304 [details]
Proposed fix
Comment 3 Olivier Thomann CLA 2008-08-06 10:23:33 EDT
Philippe,

This is a regression since 3.3.2 as in 3.3.2 we used to return the field 'k'.
I would backport the fix to the 3.4 maintenance stream for inclusion in 3.4.1.
Comment 4 Olivier Thomann CLA 2008-08-06 10:24:51 EDT
Created attachment 109307 [details]
Regression test
Comment 5 Olivier Thomann CLA 2008-08-06 20:41:31 EDT
Released for 3.5M1.
Regression test added in org.eclipse.jdt.core.tests.dom.ASTConverterTestAST3_2#test0692.

Philippe, +1 for 3.4.1?
Comment 6 Olivier Thomann CLA 2008-08-07 11:02:06 EDT
Verified for 3.5M1 using I20080807-0100.
We might reopen later for inclusion into 3.4.1.