Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 369559 - ArrayIndexOutOfBoundsException caused by concurrent threads
Summary: ArrayIndexOutOfBoundsException caused by concurrent threads
Status: NEW
Alias: None
Product: WTP Source Editing
Classification: WebTools
Component: wst.sse (show other bugs)
Version: unspecified   Edit
Hardware: PC Windows 7
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: wst.sse CLA
QA Contact: Nick Sandonato CLA
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2012-01-24 12:37 EST by Natalia Bartol CLA
Modified: 2013-06-19 11:13 EDT (History)
0 users

See Also:


Attachments
ArrayIndexOutOfBoundsException catched in DirtyRegionProcessor (1.01 KB, patch)
2012-01-24 12:46 EST, Natalia Bartol CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Natalia Bartol CLA 2012-01-24 12:37:54 EST
Build Identifier: HEAD

Concurrent threads' access may cause ArrayIndexOutOfBoundsException being thrown by StructuredRegionProcessor.process().

It is not easy to reproduce but when number of background threads accessing structured document grows up the probability of concurrent access grows up as well. Example scenario:
User edits large php file (>25k lines of code). User pastes 10 new lines of code at the end of document. DirtyRegionProcessor$BackgroundThread.run() starts reconciling document. At this moment user removes 10 lines that he recently added.  
Main thread executes StructuredDocumentTextStore.replace changing content length. At the same time DirtyRegionProcessor$BackgroundThread tries to get characters at the offset that no longer exists because 10 lines have just been removed. 
ArrayIndexOutOfBoundsException is thrown. As a result php syntax colouring is completely broken. 

Exception in thread "org.eclipse.wst.sse.ui.internal.reconcile.StructuredRegionProcessor" java.lang.ArrayIndexOutOfBoundsException
	at java.lang.System.arraycopy(Native Method)
	at java.lang.AbstractStringBuilder.append(AbstractStringBuilder.java:516)
	at java.lang.StringBuffer.append(StringBuffer.java:306)
	at org.eclipse.jface.text.GapTextStore.get(GapTextStore.java:164)
	at org.eclipse.wst.sse.core.internal.text.StructuredDocumentTextStore.get(StructuredDocumentTextStore.java:65)
	at org.eclipse.wst.sse.core.internal.text.BasicStructuredDocument.get(BasicStructuredDocument.java:1250)
	at org.eclipse.wst.sse.ui.internal.reconcile.DirtyRegionProcessor.createDirtyRegion(DirtyRegionProcessor.java:401)
	at org.eclipse.wst.sse.ui.internal.reconcile.StructuredRegionProcessor.process(StructuredRegionProcessor.java:258)
	at org.eclipse.wst.sse.ui.internal.reconcile.DirtyRegionProcessor$BackgroundThread.run(DirtyRegionProcessor.java:700)


Reproducible: Sometimes
Comment 1 Natalia Bartol CLA 2012-01-24 12:46:47 EST
Created attachment 209987 [details]
ArrayIndexOutOfBoundsException catched in DirtyRegionProcessor

I was trying to add synchronization on StructuredDocumentTextStore replace() and get() methods but this badly affects editor's performance.

I came up with the idea that maybe it is enough to catch ArrayIndexOutOfBoundsException in DirtyRegionProcessor so it will not stop processing of all remaining regions in case when one region cannot be reconciled properly. 

When working with big php file, having this patch applied, in case of concurrent access nothing bad happens. Syntax colouring for changed region is reconciled just after the next modification of file and no exception is reported so user experience is much better.
Comment 2 Nick Sandonato CLA 2012-04-12 14:47:21 EDT
Comment on attachment 209987 [details]
ArrayIndexOutOfBoundsException catched in DirtyRegionProcessor

Hi, Natalia. Thank you again for the patch. For now though, I would really like to try to get to the root of the problem instead of mitigating the exception. Thank you very much for the detailed analysis of the problem. Hopefully we can use that as a starting point.