Community
Participate
Working Groups
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
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 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.