Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 312728

Summary: Java EE import fails if zip entries contain leading slashes
Product: [WebTools] WTP Java EE Tools Reporter: Jason Sholl <jsholl>
Component: jst.j2eeAssignee: Jason Sholl <jsholl>
Status: RESOLVED FIXED QA Contact: Chuck Bridgham <cbridgha>
Severity: major    
Priority: P3 CC: ccc, raghunathan.srinivasan
Version: 3.2Flags: jsholl: pmc_approved? (david_williams)
raghunathan.srinivasan: pmc_approved+
jsholl: pmc_approved? (naci.dai)
jsholl: pmc_approved? (deboer)
jsholl: pmc_approved? (neil.hauge)
jsholl: pmc_approved? (kaloyan)
ccc: review+
Target Milestone: 3.2 RC1   
Hardware: PC   
OS: Windows XP   
Whiteboard: PMC_approved
Bug Depends on:    
Bug Blocks: 313181    
Attachments:
Description Flags
patch none

Description Jason Sholl CLA 2010-05-12 18:04:57 EDT
Importing any EE artifact will fail if any of the zip entries contain leading slashes, e.g "/foo.txt" instead of "foo.txt".  It's not clear to me how the exmple ear archive was created, but it fails with an exception like the following:

java.lang.RuntimeException: /com/ibm/websphere/csi/ must be relative.
	at org.eclipse.jst.jee.archive.AbstractArchiveLoadAdapter.verifyRelative(Unknown Source)
	at org.eclipse.jst.jee.archive.AbstractArchiveLoadAdapter.createDirectory(Unknown Source)
	at org.eclipse.jst.jee.archive.internal.ZipFileArchiveLoadAdapterImpl.createFile(Unknown Source)
	at org.eclipse.jst.jee.archive.internal.ZipFileArchiveLoadAdapterImpl.getArchiveResources(Unknown Source)
	at org.eclipse.jst.j2ee.internal.archive.JavaEEArchiveUtilities$JavaEEWrappingLoadAdapter.getArchiveResources(Unknown Source)
	at org.eclipse.jst.jee.archive.internal.ArchiveImpl.getArchiveResources(Unknown Source)
	at org.eclipse.jst.j2ee.internal.archive.ArchiveWrapper.getSize(Unknown Source)
	at org.eclipse.jst.j2ee.internal.archive.operations.EARComponentImportOperation.computeTotalWork(Unknown Source)
	at org.eclipse.jst.j2ee.internal.archive.operations.J2EEArtifactImportOperation.execute(Unknown Source)
	at org.eclipse.wst.common.frameworks.internal.datamodel.DataModelPausibleOperationImpl$1.run(Unknown Source)
	at org.eclipse.core.internal.resources.Workspace.run(Unknown Source)
	at org.eclipse.wst.common.frameworks.internal.datamodel.DataModelPausibleOperationImpl.runOperation(Unknown Source)
	at org.eclipse.wst.common.frameworks.internal.datamodel.DataModelPausibleOperationImpl.runOperation(Unknown Source)
	at org.eclipse.wst.common.frameworks.internal.datamodel.DataModelPausibleOperationImpl.doExecute(Unknown Source)
	at org.eclipse.wst.common.frameworks.internal.datamodel.DataModelPausibleOperationImpl.executeImpl(Unknown Source)
	at org.eclipse.wst.common.frameworks.internal.datamodel.DataModelPausibleOperationImpl.cacheThreadAndContinue(Unknown Source)
	at org.eclipse.wst.common.frameworks.internal.datamodel.DataModelPausibleOperationImpl.execute(Unknown Source)
	at org.eclipse.wst.common.frameworks.internal.datamodel.ui.DataModelWizard$1CatchThrowableRunnableWithProgress.run(Unknown Source)
	at org.eclipse.jface.operation.ModalContext$ModalContextThread.run(Unknown Source)


The fix is very simple and safe which is to ensure the paths are relative by calling Path.makeRelative().  This method will return itself if it is already relative so will not have performance implications.
Comment 1 Jason Sholl CLA 2010-05-12 18:07:05 EDT
Created attachment 168286 [details]
patch
Comment 2 Carl Anderson CLA 2010-05-12 18:08:42 EDT
I approve of this fix.
Comment 3 Jason Sholl CLA 2010-05-12 18:31:47 EDT
    * Explain why you believe this is a stop-ship defect. Or, if it is a "hotbug" (requested by an adopter) please document it as such. 

Import fails with exceptions

    * Is there a work-around? If so, why do you believe the work-around is insufficient? 

No

    * How has the fix been tested? Is there a test case attached to the bugzilla record? Has a JUnit Test been added? 

UI

    * Give a brief technical overview. Who has reviewed this fix? 

See description

    * What is the risk associated with this fix? 

No
Comment 4 Jason Sholl CLA 2010-05-12 18:52:41 EDT
code checked into head for wtp 32 rc1