Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Language IDEs » Java Development Tools (JDT) » ECJ: Class names not verified for package-scope?(Compiler does not verify all class names to file names)
ECJ: Class names not verified for package-scope? [message #894789] Tue, 10 July 2012 14:26 Go to next message
Chris S is currently offline Chris SFriend
Messages: 20
Registered: November 2011
Junior Member
Hi,

I've run into something that to me looks like a bug, but may be intended, so before I make a bug report, I'd like to ask if this is as it should.

If I create a new class in Eclipse, e.g. "public ClassA", it will (of course) put it in a file called ClassA.java, and when I try to change the name of the class to ClassB manually (not using refactoring), I get an error because the file name and the class name do not match.

But, if I remove "public" so I have a package-internal class, then suddenly this verification doesn't happen. "protected" has the same behavior as "public". So it looks like this may be intentional. But if so, it is seriously annoying, we just had to spend a lot of time tracking down a strange behavior which turned out to be caused by someone changing a class name without changing the file name. I'd really like to have the compiler react to this for all top-level classes.

Anyone knows if this is intentional, or should I file a bug report?
Re: ECJ: Class names not verified for package-scope? [message #894798 is a reply to message #894789] Tue, 10 July 2012 14:44 Go to previous messageGo to next message
Olivier Thomann is currently offline Olivier ThomannFriend
Messages: 518
Registered: July 2009
Senior Member
There is no requirement to match the class name and the file name when the class defines a secondary type. You can define secondary types in any compilation unit. Secondary types (package visible type) are evil and should be avoided as much as possible.

Olivier
Re: ECJ: Class names not verified for package-scope? [message #894919 is a reply to message #894798] Wed, 11 July 2012 06:05 Go to previous message
Chris S is currently offline Chris SFriend
Messages: 20
Registered: November 2011
Junior Member
Thanks for the reply, I didn't even in my dreams consider that Java allowed something as silly as that; you learn something new every day.
This would perhaps be a nice addition to ECJ to have a custom compiler warning/error to disallow secondary types and also also ban it if it is only one class in the file and that one doesn't match the file name. I.e. a new option configurable from Preferences->Java->Compiler->Warnings. I think I might add a feature request for that somewhere.
Previous Topic:TypeBinding for expected type in JavaContentAssistInvocationContext
Next Topic:Java EE 6 SDK for Mac
Goto Forum:
  


Current Time: Thu Sep 19 19:30:54 GMT 2024

Powered by FUDForum. Page generated in 0.03471 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top