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

Bug 311542

Summary: WebComponentArchiveSaveAdapter may throw StringIndexOutOfBoundsException
Product: [WebTools] WTP Java EE Tools Reporter: Larry Isaacs <larryisaacs>
Component: jst.j2eeAssignee: Jason Sholl <jsholl>
Status: CLOSED FIXED QA Contact: Chuck Bridgham <cbridgha>
Severity: normal    
Priority: P3 CC: ccc, david_williams
Version: 3.2Flags: david_williams: pmc_approved+
jsholl: pmc_approved? (raghunathan.srinivasan)
jsholl: pmc_approved? (naci.dai)
jsholl: pmc_approved? (deboer)
jsholl: pmc_approved? (neil.hauge)
jsholl: pmc_approved? (kaloyan)
cbridgha: review+
jsholl: review+
Target Milestone: 3.2 RC1   
Hardware: All   
OS: All   
Whiteboard: PMC_approved
Bug Depends on:    
Bug Blocks: 312129    
Attachments:
Description Flags
Patch to avoid use of a length as an index, plus update to copyright year jsholl: iplog+

Description Larry Isaacs CLA 2010-05-04 09:16:57 EDT
Created attachment 166949 [details]
Patch to avoid use of a length as an index, plus update to copyright year

The zip downloaded by http://sourceforge.net/projects/php-java-bridge/files/Binary%20package/php-java-bridge_6.1.2.1_documentation.zip/download contains a JavaBridge.war which will trigger the StringIndexOutOfBoundsException if you try to import this war, i.e.

Caused by: java.lang.StringIndexOutOfBoundsException: String index out of range: 16
	at java.lang.String.charAt(String.java:686)
	at org.eclipse.jst.j2ee.internal.archive.WebComponentArchiveSaveAdapter.isClassWithoutSource(WebComponentArchiveSaveAdapter.java:94)
	at org.eclipse.jst.j2ee.internal.archive.J2EEComponentArchiveSaveAdapter.shouldSave(J2EEComponentArchiveSaveAdapter.java:78)
	at org.eclipse.jst.jee.archive.AbstractArchiveSaveAdapter.save(AbstractArchiveSaveAdapter.java:71)
	... 18 more

The war contains a "TestInstallation.class" file in the root of the webapp, whose base name is the "magic" 16 characters long (the same length as "WEB-INF/classes/") that invokes the bug, which is also present in WTP 3.1.x.  Since the user doesn't have much chance of telling what it is about the war that triggers this symptom, it might be worth fixing in WTP 3.2RC1.
Comment 1 Carl Anderson CLA 2010-05-04 10:09:56 EDT
Assigning to Jason - can you review Larry's patch?  If it is good, let's get it through PMC approval.
Comment 2 Chuck Bridgham CLA 2010-05-04 15:03:25 EDT
approved
Comment 3 Jason Sholl CLA 2010-05-05 10:07:45 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. 

This exception causes WAR import to fail for this particular WAR.

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

No workaround to make WAR import work with this WAR.

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

This has been tested with the UI.  Regression testing will be run against the existing JUnits.  A new JUnit has not yet been added, Larry, could you do this?

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

Larry Isaacs created the patch, Chuck Bridgham and Jason Sholl have reviewed it.  Jason also tested it.

    * What is the risk associated with this fix? 

Minimal risk to WAR import only.
Comment 4 Larry Isaacs CLA 2010-05-05 10:20:09 EDT
I can give creating a JUnit a shot.  I assume this would mean adding an additional test method to the DefectVerificationTests.
Comment 5 Jason Sholl CLA 2010-05-05 11:46:58 EDT
For the JUnit, I think you may be able to simply augment one of the existing tests (perhaps WebImportOperationTest or DefectVerificationTests) to import an example WAR with the problem.
Comment 6 David Williams CLA 2010-05-05 15:26:50 EDT
good catch. How old is this code? Has this bug existed a long time? 

I do think should be fixed ... can't imagine a downside ... but this kind of rare-path, non-regression bugs will be the type we'll want to start to think about. 

remember to mark IP Log for patches ... if appropriate.
Comment 7 Jason Sholl CLA 2010-05-05 16:17:28 EDT
code checked into HEAD for 32 RC1
Comment 8 Larry Isaacs CLA 2010-05-05 16:21:17 EDT
I believe this issue was introduced in WTP 2.0.5 and 3.0.  I'm working on a test.  It's taking me a little longer because of other distractions and the verification classes aren't happy with a class file in the "webcontent" portion of the war.  I'll open a separate bug for the JUnit test once it's ready.
Comment 9 Larry Isaacs CLA 2010-05-07 16:48:37 EDT
Linking Bug 312129 which contains the JUnit test that verifies the fix.
Comment 10 Larry Isaacs CLA 2010-05-11 15:57:40 EDT
Verified the problem war file attached to Bug 312129 imports correctly without encountering the StringIndexOutOfBoundsException using WTP I-3.2.0-20100511060448 build.
Comment 11 Jason Sholl CLA 2010-05-17 09:34:53 EDT
closing