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

Bug 312738

Summary: Index out of bounds exception on startup
Product: [WebTools] WTP Common Tools Reporter: Chuck Bridgham <cbridgha>
Component: wst.commonAssignee: Chuck Bridgham <cbridgha>
Status: RESOLVED FIXED QA Contact: Carl Anderson <ccc>
Severity: normal    
Priority: P3 CC: david_williams, resendes
Version: 3.2Flags: david_williams: pmc_approved+
cbridgha: pmc_approved? (raghunathan.srinivasan)
cbridgha: pmc_approved? (naci.dai)
cbridgha: pmc_approved? (deboer)
cbridgha: pmc_approved? (neil.hauge)
cbridgha: pmc_approved? (kaloyan)
ccc: review+
Target Milestone: 3.2 RC1   
Hardware: PC   
OS: Windows 7   
Whiteboard: PMC_approved
Attachments:
Description Flags
patch none

Description Chuck Bridgham CLA 2010-05-12 21:18:49 EDT
This exception is thrown on startup

!ENTRY org.eclipse.core.jobs 4 2 2010-05-06 10:15:51.640
!MESSAGE An internal error occurred during: "Initializing Java Tooling".
!STACK 0
java.lang.ArrayIndexOutOfBoundsExcep tion: Array index out of range: 2
    at java.lang.System.arraycopy(Native Method)
    at org.eclipse.emf.common.util.BasicEList.gr ow(BasicEList.java:736)
  &n bsp; at org.eclipse.emf.common.util.BasicEList.ad dUnique(BasicEList.java:422)
 &nb sp;  at org.eclipse.emf.common.util.AbstractEList. add(AbstractEList.java:307)
 &nbs p;  at org.eclipse.emf.common.notify.impl.BasicN otifierImpl$EAdapterList.add(BasicNotifierImpl. java:199)
    at org.eclipse.wst.common.componentcore.internal. StructureEdit.getEclipseResource(StructureEdit. java:252)
    at org.eclipse.wst.common.componentcore.internal. impl.ResourceTreeNode.findMatchingVirtual PathsSet(ResourceTreeNode.java:195)

This exposes a race condition where the adapter List is not synchronized.
Comment 1 Chuck Bridgham CLA 2010-05-12 21:24:26 EDT
Created attachment 168309 [details]
patch
Comment 2 Chuck Bridgham CLA 2010-05-12 21:26:15 EDT
Using pattern used many times - adding the synchronized adapter class to utilities for repeated use...

EMF adapter class is NOT thread safe, and doesn't protect internal collection.
This class does.
Comment 3 Carl Anderson CLA 2010-05-12 22:18:05 EDT
I approve of this patch
Comment 4 Chuck Bridgham CLA 2010-05-12 22:25:54 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.
Thrown exceptions on startup - adopter product deems this as major

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

- How has the fix been tested? Is there a test case attached to the bugzilla record? Has a JUnit Test been added?
Existing junit bucket run - no new test needed

- Give a brief technical overview. Who has reviewed this fix?
The same code has been in place on ReferencedXMIResourceImpl for a couple years with success(no regressions)  This will protect (lock) the adapter collection during any access to its internal collection

- What is the risk associated with this fix?
no risk of deadlock because there is no outside call from the synchronized methods
Comment 5 Carl Anderson CLA 2010-05-13 00:05:05 EDT
Committed to HEAD for WTP 3.2 RC1
Comment 6 Carl Anderson CLA 2010-09-07 22:18:41 EDT
*** Bug 322339 has been marked as a duplicate of this bug. ***