-
Notifications
You must be signed in to change notification settings - Fork 49
Fixed ClassCastException when adding module file #453
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fixed ClassCastException when adding module file #453
Conversation
* GWT Maven project will have a short name | ||
* @return the short name for module | ||
*/ | ||
private String getShortName() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This method fails when the plugin is scanning classpath for manifest files in dependencies, which are in jar files.
Returning an empty string should be the right thing to do, as there's some maven related logic which makes sense only for manifests contained in the source, and not in dependencies
.../com.gwtplugins.gwt.eclipse.core/src/com/google/gwt/eclipse/core/modules/AbstractModule.java
Show resolved
Hide resolved
.../com.gwtplugins.gwt.eclipse.core/src/com/google/gwt/eclipse/core/modules/AbstractModule.java
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From what I can tell, there are two AbstractModule
subtypes:
ModuleFile
, which always uses an IFile storage (the "correct" case according to the old code)ModuleJarResource
, which is always anIJarEntryResource
storage (presumably the "wrong" one, since it is the only other case, and doesn't inherit fromIFile
).
Each of these respective AbstractModule types limits what type it takes in its constructor, so we can be certain that storage
is always the expected type. In turn, each type knows what storage it has, so can avoid an instanceof
check. In fact, I'd go so far as to say that the storage instanceof IFile
check is actually a this instanceof ModuleFile
check..
As such, I think a better fix than branching on the type of storage is to make these methods abstract, and correctly implement them in their subtypes. That is, ModuleJarResource
will return ""
for each of these, and ModuleFile
will return the old logic.
Note that we could also use isBinary()
as a "is it a file" check, since that is overridden by each type in this way, to return true/false.
To make things a bit more bulletproof along the way, AbstractModule
could be made generic on <S extends IStorage>
, and then each type could avoid a cast to read its own storage (there are comments, such as ModuleFile.getFile()
that would go away, since this would become obvious)...
return moduleName; | ||
} | ||
|
||
private String getGWtMaven2ModuleName() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fix typo in this method name while you're changing this?
private String getGWtMaven2ModuleName() { | |
private String getGwtMaven2ModuleName() { |
} | ||
|
||
} | ||
/******************************************************************************* |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
note that you're changing line endings
Image image = null; | ||
|
||
IModule module = (IModule) element; | ||
if (module instanceof ModuleFile) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, while technically true, is this better? I think it might be, but wanted your opinion.
The first thing each block does is to cast it, so that might be right.
@Override | ||
protected Comparator<?> getItemsComparator() { | ||
return (Object o1, Object o2) -> { | ||
Collator collator = Collator.getInstance(); | ||
IModule module1 = (IModule) o1; | ||
IModule module2 = (IModule) o2; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While you're at it, change this to specify the right type, so a cast isn't even needed?
@Override | |
protected Comparator<?> getItemsComparator() { | |
return (Object o1, Object o2) -> { | |
Collator collator = Collator.getInstance(); | |
IModule module1 = (IModule) o1; | |
IModule module2 = (IModule) o2; | |
@Override | |
protected Comparator<IModule> getItemsComparator() { | |
return (Object module1, Object module2) -> { | |
Collator collator = Collator.getInstance(); | |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok!
protected AbstractModule(IStorage storage) { | ||
assert (storage != null); | ||
this.storage = storage; | ||
protected AbstractModule() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
shouldnt even be necessary, the class is already abstract and has no other ctors
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok
* @return module name | ||
*/ | ||
private String getGwtMaven2ModuleName() { | ||
IFile file = storage; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is silly to have, and the moduleName variable isnt needed either. Probably should just inline it (but the code is so much better I'd be okay with leaving it).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Approved, a few thoughts, up to you if we address now or not.
gwtModuleDtd = "<!DOCTYPE module PUBLIC \"-//Google Inc.//DTD Google Web Toolkit " + versionNum | ||
+ "//EN\" \"http://google-web-toolkit.googlecode.com/svn/tags/" + versionNum | ||
+ "/distro-source/core/src/gwt-module.dtd\">"; | ||
+ "//EN\" \"http://gwtproject.org/doctype/" + versionNum |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Defer this to a followup patch, since it isn't related to this other work?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixes the bug (and possibly other latent bugs), cleans up the code, net decrease in code, great work!
Modified AbstractModule.getShortName and AbstractModule.getGWtMaven2ModuleName to return an empty string
when Module is not stored in an IFile
I'm just curing the symptoms, as I'm not clear what the code should do.
But it's better than nothing...
Fixes #452