GWT "The type XXX is already defined" error on package-private classes with NO previous definition.

211 views
Skip to first unread message

magic

unread,
Apr 21, 2011, 3:26:49 AM4/21/11
to Google Web Toolkit
I am getting several ""The type XXX is already defined" errors when I
compile my web application.

These all occur with package-private classes (those in the Java file
of another class but not nested in that class) in a module that is
inherited by my web application. I have not been able to determine the
difference between those package-private classes for which an error is
emitted and those for which no error appears. There is one case, where
the classes are essentially identical and the use of the those classes
throughout my project is identical yet one works, the other does not.
To add to the mystery, the module compiles without error when
compiling one inheriting web application but not when compiling
another.

The package-private classes for which the error is emitted are
sometimes but not always used as the type of an instance variable or
method parameter in the class that "owns" its .java file.

The only workaround I have found is to move the offending classes into
their own .java files.

I have become convinced that this is a bug in the GWT compiler but
since I can't identify the trigger, I have been unable to create a
small test case. Otherwise I would file a bug report. To provide the
case that is currently failing would require providing source of one
of our products in its entirety.

The GWT compiler only prints the location of the purported second
definition. Would the compiler developers please change the error
message to print out the locations of the second *and* original
definitions.

None of the forums threads that I have found on this topic present any
useful solution.

Darek kay

unread,
Apr 24, 2012, 11:50:07 AM4/24/12
to google-we...@googlegroups.com
Since I spent some time searching for a solution, here it is. Don't put top level classes like this:

public class1{
}

class2{
}

Although it's a valid java syntax, GWT doesn't seem to handle this very well. That's what it should look like:

public class1{
 static class2{
 }
}
Reply all
Reply to author
Forward
0 new messages