[326467] NPE when removing an EAR reference with no archiveName attribute defined
diff --git a/plugins/org.eclipse.jst.j2ee/earproject/org/eclipse/jst/j2ee/application/internal/operations/RemoveComponentFromEnterpriseApplicationOperation.java b/plugins/org.eclipse.jst.j2ee/earproject/org/eclipse/jst/j2ee/application/internal/operations/RemoveComponentFromEnterpriseApplicationOperation.java index 12c313d..302a4c2 100644 --- a/plugins/org.eclipse.jst.j2ee/earproject/org/eclipse/jst/j2ee/application/internal/operations/RemoveComponentFromEnterpriseApplicationOperation.java +++ b/plugins/org.eclipse.jst.j2ee/earproject/org/eclipse/jst/j2ee/application/internal/operations/RemoveComponentFromEnterpriseApplicationOperation.java
@@ -16,7 +16,6 @@ import org.eclipse.core.resources.IFile; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IAdaptable; -import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.Path; @@ -99,15 +98,7 @@ } if(moduleURI != null) { - IPath path1 = new Path(ref.getArchiveName()); - IPath path2 = new Path(moduleURI); - boolean removed = false; - if(path1.lastSegment().equals(path2.lastSegment())) { - if(removeModule(application, module)){ - removed = true; - } - } - if(!removed) { + if(!removeModule(application, module)){ module = null; moduleURI = null; } @@ -116,7 +107,7 @@ } if(module == null) { - if(ref != null) + if(ref != null && ref.getArchiveName() != null) module = getModuleFromURI(earModel, ref.getArchiveName()); else { String uri = getModuleURI(earModel, wc); @@ -200,6 +191,17 @@ protected Object getModule(final IEARModelProvider earModel, final ReferencedComponent refComp) { Object app = earModel.getModelObject(); Object moduleObj = refComp.getDependentObject(); + if(moduleObj != null){ + String id = null; + if(moduleObj instanceof org.eclipse.jst.j2ee.application.internal.impl.ModuleImpl) { + id = ((org.eclipse.jst.j2ee.application.internal.impl.ModuleImpl)moduleObj).getId(); + } else if (moduleObj instanceof ModuleImpl) { + id = ((Module)moduleObj).getId(); + } + if(id == null || id.length() == 0) { + return null; + } + } if(app instanceof Application){ List<Module> modules = ((Application)app).getModules(); if(moduleObj != null){ @@ -228,7 +230,7 @@ } } } - return moduleObj; + return null; } protected Object getModuleFromURI(final IEARModelProvider earModel, String uri) {