Bug 105635 - incorrect parsing of field declarations with generic types
Summary: incorrect parsing of field declarations with generic types
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.1   Edit
Hardware: PC Windows XP
: P3 major (vote)
Target Milestone: 3.1.1   Edit
Assignee: Olivier Thomann CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2005-07-30 13:02 EDT by David Cok CLA
Modified: 2005-09-26 12:17 EDT (History)
1 user (show)

See Also:


Attachments
Proposed fix (1.88 KB, patch)
2005-08-02 16:20 EDT, Olivier Thomann CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description David Cok CLA 2005-07-30 13:02:05 EDT
A field declaration with a generic type and trailing brackets and multiple
fragements does not parse correctly:

e.g.: public java.util.List<Integer> i[],j,k;
or    public java.util.List<Integer> i,j[];


class T { 
public java.util.List<Integer> i,j[],k;
void m() {
  i[0] = null; // OK but should not be
  j[0] = null;
  k[0] = null; // OK but should not be
}
}

The parser considers the type common to all the fragments to be an array type.
This does not happen if the common type is a primitive type or a non-generic
reference type.  It does happen no matter which fragment the brackets are on.
One can see the error by looking at the resulting AST as well, though 
interestingly, the AST appears correct for the case above, but is clearly wrong
for the case where the brackets are on j.  

I would try to debug this further, but the parser is table driven and I do not
know where the files that create the tables are.

Here is what I get from printing
out the AST for some examples:

TREES FOR class T { public java.util.List<Integer> i,j[]; }
ECLIPSE AST
0) class org.eclipse.jdt.core.dom.CompilationUnit 0 49 
 1) class org.eclipse.jdt.core.dom.TypeDeclaration 0 49 
  2) class org.eclipse.jdt.core.dom.SimpleName 6 1 
  3) class org.eclipse.jdt.core.dom.FieldDeclaration 10 37 
   4) class org.eclipse.jdt.core.dom.Modifier 10 6 
   5) class org.eclipse.jdt.core.dom.ArrayType 17 23 <--- should not be an 
array of parameterized type
    6) class org.eclipse.jdt.core.dom.ParameterizedType 17 23 
     7) class org.eclipse.jdt.core.dom.SimpleType 17 14 
      8) class org.eclipse.jdt.core.dom.QualifiedName 17 14 
       9) class org.eclipse.jdt.core.dom.QualifiedName 17 9 
        10) class org.eclipse.jdt.core.dom.SimpleName 17 4 
        11) class org.eclipse.jdt.core.dom.SimpleName 22 4 
       12) class org.eclipse.jdt.core.dom.SimpleName 27 4 
     13) class org.eclipse.jdt.core.dom.SimpleType 32 7 
      14) class org.eclipse.jdt.core.dom.SimpleName 32 7 
   15) class org.eclipse.jdt.core.dom.VariableDeclarationFragment 41 1 
    16) class org.eclipse.jdt.core.dom.SimpleName 41 1 
   17) class org.eclipse.jdt.core.dom.VariableDeclarationFragment 43 3 
    18) class org.eclipse.jdt.core.dom.SimpleName 43 1 

This one looks ok, but the type for j is still incorrectly an array type.

TREES FOR class T { public java.util.List<Integer> i[],j; }
ECLIPSE AST
0) class org.eclipse.jdt.core.dom.CompilationUnit 0 49 
 1) class org.eclipse.jdt.core.dom.TypeDeclaration 0 49 
  2) class org.eclipse.jdt.core.dom.SimpleName 6 1 
  3) class org.eclipse.jdt.core.dom.FieldDeclaration 10 37 
   4) class org.eclipse.jdt.core.dom.Modifier 10 6 
   5) class org.eclipse.jdt.core.dom.ParameterizedType 17 23 
    6) class org.eclipse.jdt.core.dom.SimpleType 17 14 
     7) class org.eclipse.jdt.core.dom.QualifiedName 17 14 
      8) class org.eclipse.jdt.core.dom.QualifiedName 17 9 
       9) class org.eclipse.jdt.core.dom.SimpleName 17 4 
       10) class org.eclipse.jdt.core.dom.SimpleName 22 4 
      11) class org.eclipse.jdt.core.dom.SimpleName 27 4 
    12) class org.eclipse.jdt.core.dom.SimpleType 32 7 
     13) class org.eclipse.jdt.core.dom.SimpleName 32 7 
   14) class org.eclipse.jdt.core.dom.VariableDeclarationFragment 41 3 
    15) class org.eclipse.jdt.core.dom.SimpleName 41 1 
   16) class org.eclipse.jdt.core.dom.VariableDeclarationFragment 45 1 
    17) class org.eclipse.jdt.core.dom.SimpleName 45 1 


- David
Comment 1 Olivier Thomann CLA 2005-08-02 15:18:58 EDT
The fix is simple.
We wrongly shared the type reference in the copyDims(int) method on the
parameterized single type reference and parameterized qualified type reference.
Philippe, I believe this is a must fix for 3.1.1.
Comment 2 Olivier Thomann CLA 2005-08-02 16:16:53 EDT
Fixed and released in HEAD.
Regression tests added in GenericTypeTest.test793/794
Comment 3 Olivier Thomann CLA 2005-08-02 16:20:03 EDT
Created attachment 25583 [details]
Proposed fix
Comment 4 Philipe Mulet CLA 2005-08-08 08:51:22 EDT
+1 for 3.1.1
Comment 5 Olivier Thomann CLA 2005-08-08 11:09:26 EDT
Backported to 3.1 maintenance stream.
Regression tests added in GenericTypeTest.test793/794
Comment 6 Jerome Lanneluc CLA 2005-08-11 10:37:27 EDT
Verified with 3.2 M1
Comment 7 Maxime Daniel CLA 2005-09-21 08:43:13 EDT
Verified for 3.2 M2 on build Build id: I20050920-0010.
Comment 8 David Audel CLA 2005-09-26 12:17:56 EDT
Verified using M20050923-1430 for 3.1.1