Bug 191739 - "Duplicate nested type" bogus error on static class of abstract class or interface
Summary: "Duplicate nested type" bogus error on static class of abstract class or inte...
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.3   Edit
Hardware: All All
: P1 normal with 1 vote (vote)
Target Milestone: 3.3.1   Edit
Assignee: Kent Johnson CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2007-06-08 12:39 EDT by Zorzella Mising name CLA
Modified: 2007-09-17 10:37 EDT (History)
5 users (show)

See Also:
philippe_mulet: review+


Attachments
testcase (594 bytes, application/x-gzip)
2007-08-21 18:48 EDT, Francis Kung CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Zorzella Mising name CLA 2007-06-08 12:39:05 EDT
Build ID: I20070601-1539

Steps To Reproduce:

I'm having a strange problem in a large project of mine. It manifests in code that looks like the code below, where a static class is defined in either an abstract class or an interface. Sometimes, when I sync my client, and get the system to refresh, it will start getting a few errors that reads (adjusted for the example below):

Duplicate nested type MyException

Now, if I come to the Foo class and "touch" it (say add and remove a space), save and re-compile, the error(s) in that file is(are) gone.

This happens consistently in several clients on several computers, but, interestingly, always happens when I use a particular set of eclipse inclusion globs. With a different set of inclusions, those errors never happen (even if the inclusions include some of the files with "problematic pattern").

I don't know if this is relevant at all, but 3 out of the 4 errors are where MyException extends some exception. The 4th is in a file where there is another error already from a class that extends some exception. 3 of the classes are abstract classes, and 1 is an interface.

public abstract class Foo {
  public static class MyException extends Exception {} 
}

public class Bar extends Foo {}
Comment 1 Kent Johnson CLA 2007-06-08 13:14:21 EDT
Any chance we can get a hold of the entire project to find the problem ?

Or at least enough of the classes to reproduce it ?
Comment 2 Zorzella Mising name CLA 2007-06-08 17:25:12 EDT
Sorry, closed source. And very large. I don't know exactly what's the minimum amount of code to reproduce, and, as I said, reproducing itself is affected by refreshes/recompiling and inclusion globs...

I know it sucks to get a report that you can't reproduce, and I avoid filing those... but this is consistently coming back, so I know it's not totally non-derterministic.
Comment 3 Kent Johnson CLA 2007-06-11 10:46:16 EDT
I accept that your seeing a problem, but we'll need a reproduceable case.

Please try to narrow it down to a few class definitions (no methods are needed).

Also can you count how many source files are in your project.
Comment 4 Zorzella Mising name CLA 2007-06-11 11:47:50 EDT
There are tens of thousands of files in my "src" directory, but about 70% of these are not considered "sources" by Eclipse, for we use an elaborate set of inclusion globs. And as I mentioned, changing the globs causes the errors to go away, even if they still include files that had that error in them before.
Comment 5 Kent Johnson CLA 2007-06-12 14:04:52 EDT
Does every full/clean build produce the same 4 duplicate errors?

Please paste in the type declarations from each duplicate file.
Comment 6 Kent Johnson CLA 2007-06-20 12:18:23 EDT
We'll need more info to track this down.

If any other users encounter this problem, PLEASE attach a reproduceable testcase.

thx
Comment 7 Zorzella Mising name CLA 2007-07-03 12:37:50 EDT
Is there any way I can trace/debug something in my env? Is there any way to have the message list where the other one of these "duplicates" is defined? 
Comment 8 Steven Tamm CLA 2007-07-05 18:07:28 EDT
The way we've been able to reproduce it is a little more convoluted.  You need to have a JAR file that references the inner class static class/enum, but doesn't contain that class.  We have an ANTLR built jar file that does this.  A full rebuild will cause the error to happen, probably because it's referenced from the main project and the jar file as well.  It doesn't matter where I reference these inner classes/enum from, as long as they are inner, and referenced from that Jar file

I just did this with the sample below and it caused it to happen.  Use the sample code below, and compile a file like this

package test;

public class Other {
   public void test() throws MyException {
   }
}

Into a jar file (test.jar), making sure that Foo and Bar aren't included.  Then create a project including Foo, Bar, and the jar file.  I was able to reproduce it.  
Comment 9 Kent Johnson CLA 2007-07-09 13:53:06 EDT
Sorry Steven your example is not very clear.

What is the source for Foo and Bar ?

And since the jar file is built using a different builder/compiler, I fail to see how it could impact the JavaBuilder as it compiles your source files... but I'm more than willing to walk thru any example you can provide.


Zorzella, if you could describe who/where the "duplicate nested types" are defined, it would help us narrow down where we could add tracing. Then we'll definitely give you a jdt_core jar replacement.
Comment 10 Dick Wall CLA 2007-07-24 13:44:36 EDT
(In reply to comment #8)

I am also seeing this problem now, and it reminds me of a similar problem I have seen in the past, again related to the use of a class that the source in the eclipse project defines, but which is used from a jar file. I know this might sound a little unusual, but if you are working on a large enough code base (we are) and just want to work on a small corner of it, making jars dependent on classes in the source code happens a lot.

Anyway - the problem has surfaced a couple of times in the last year or so of using 3.2, but is clearly much more of an issue in 3.3 (since I upgraded, on the same codebase, I now see 13 of these compile errors linked to duplicate nested types). When I saw the problem in 3.2 I tried to create a small example to demonstrate but was unable to do so (and I can't send you the sources I am working on unfortunately :-) ), but perhaps it will be easier to re-create now since it seems to be more common.

Thanks


> The way we've been able to reproduce it is a little more convoluted.  You need
> to have a JAR file that references the inner class static class/enum, but
> doesn't contain that class.  We have an ANTLR built jar file that does this.  A
> full rebuild will cause the error to happen, probably because it's referenced
> from the main project and the jar file as well.  It doesn't matter where I
> reference these inner classes/enum from, as long as they are inner, and
> referenced from that Jar file
> 
> I just did this with the sample below and it caused it to happen.  Use the
> sample code below, and compile a file like this
> 
> package test;
> 
> public class Other {
>    public void test() throws MyException {
>    }
> }
> 
> Into a jar file (test.jar), making sure that Foo and Bar aren't included.  Then
> create a project including Foo, Bar, and the jar file.  I was able to reproduce
> it.  
> 
Comment 11 Francis Kung CLA 2007-08-21 18:48:19 EDT
Created attachment 76591 [details]
testcase

I've hit this bug as well, trying to build IcedTea (a fully opensource derivate of Sun's OpenJDK) with ecj 3.3.

Attached is a testcase reproducing the bug - I've simplified it as much as possible.  They key seems to be the use of the inner class/enum in the NoSource class, and the order of the imports in the Test class.
Comment 12 Kent Johnson CLA 2007-08-22 11:59:52 EDT
Francis - I think that's a different problem since its outside the IDE.

Is everyone else building their project & seeing this problem inside the IDE ?
Comment 13 Steven Tamm CLA 2007-08-22 12:06:13 EDT
(In reply to comment #12)
> Francis - I think that's a different problem since its outside the IDE.
> 
> Is everyone else building their project & seeing this problem inside the IDE ?
> 

That's the exact same problem I've been seeing.
Comment 14 Kent Johnson CLA 2007-08-22 13:40:22 EDT
Sorry Steve - are you seeing the problem inside the IDE or outside using ecj ?
Comment 15 Steven Tamm CLA 2007-08-22 14:05:17 EDT
I see it through the IDE (as do the other commenters on the bug).  I run ecj on src2, put that in a jar, include the jar in an IDE with the src1 package.  If you put them both in the IDE it doesn't work, because they have a circular dependency.  If you put Foo.java in both projects it figured it out.  If it's reading it from a .class or .jar file it dies.   
Comment 16 Kent Johnson CLA 2007-08-22 14:16:44 EDT
There is still a circular dependency between the jar & the remaining source files.

The types in the jar need to see the .class files for the types in the source folder AND the types in the source folder need to see jar.

BTW I still have not reproduced the 'Duplicate nested type error' inside the IDE using the jar file.

I have produced another error that says it cannot find the nested type, which is referenced from the jar file.
Comment 17 Kent Johnson CLA 2007-08-22 15:09:32 EDT
OK - I take it back.

I have now reproduced the problem inside the IDE.
Comment 18 Kent Johnson CLA 2007-08-22 15:47:21 EDT
Released a fix to ClassScope into HEAD.

Can each of you please try a nightly build (dated later than Aug 22/07) to see if it fixes your problem in the IDE & let us know.

I think this will do the trick and we'll backport it to 3.3.1 if that's the case.
Comment 19 Francis Kung CLA 2007-08-23 10:25:25 EDT
Thanks for the quick turnaround!  The nightly build works for me.
Comment 20 Kent Johnson CLA 2007-08-23 14:55:08 EDT
Added IncrementalBuildTests testMemberTypeCollisionWithBinary2()

Fix released into HEAD for 3.4M2
Comment 21 Steven Tamm CLA 2007-08-23 15:55:19 EDT
(In reply to comment #20)
> Added IncrementalBuildTests testMemberTypeCollisionWithBinary2()
> 
> Fix released into HEAD for 3.4M2
> 

Solved all of our problems as well.  Thanks!

Will it be backported to 3.3.1?
Comment 22 Kent Johnson CLA 2007-08-24 10:15:06 EDT
Yep - just needed to finish running some tests.

Released into 3.3.1 stream
Comment 23 Philipe Mulet CLA 2007-08-29 06:16:55 EDT
+1 for 3.3.1
Comment 24 Maxime Daniel CLA 2007-09-03 07:33:09 EDT
The test case is org.eclipse.jdt.core.tests.builder.IncrementalTests (#testMemberTypeCollisionWithBinary2) indeed - wrong class name.

Verified for 3.3.1 using build M20070831-2000.
Comment 25 Jerome Lanneluc CLA 2007-09-17 10:36:32 EDT
Verified for 3.4M2 using I20070917-0010.