This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

Bug 71563 - AbstractBlocksFinder's blocks variable is not thread-safe
Summary: AbstractBlocksFinder's blocks variable is not thread-safe
Status: RESOLVED FIXED
Alias: None
Product: editor
Classification: Unclassified
Component: Search (show other bugs)
Version: 4.x
Hardware: All All
: P3 blocker with 1 vote (vote)
Assignee: issues@editor
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2006-01-18 20:04 UTC by cahrens
Modified: 2008-02-13 23:12 UTC (History)
0 users

See Also:
Issue Type: DEFECT
Exception Reporter:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description cahrens 2006-01-18 20:04:21 UTC
I have gotton some reports (non-reproducible) of the following exception. 
Looking at the code, it would appear that the problem is that a different thread
(presumambly the AWT-Event thread) modifies the blocks variable (through
setBlocks?) at the same time that the Text-Layout thread is calling addBlock.

Exception in thread "Text-Layout" java.lang.ArrayIndexOutOfBoundsException: 2
at
org.netbeans.editor.DocumentFinder$AbstractBlocksFinder.addBlock(DocumentFinder.java:359)
at
org.netbeans.editor.DocumentFinder$AbstractBlocksFinder.closeBlocks(DocumentFinder.java:365)
at
org.netbeans.editor.DocumentFinder$AbstractBlocksFinder.getBlocks(DocumentFinder.java:342)
at org.netbeans.editor.DocumentFinder.findBlocks(DocumentFinder.java:276)
at org.netbeans.editor.FindSupport.getBlocks(FindSupport.java:149)
at
org.netbeans.editor.DrawLayerFactory$HighlightSearchLayer.init(DrawLayerFactory.java:274)
at org.netbeans.editor.DrawEngine.initInfo(DrawEngine.java:175)
at org.netbeans.editor.DrawEngine.draw(DrawEngine.java:1099)
at
org.netbeans.editor.DrawEngineLineView.getModel2ViewRect(DrawEngineLineView.java:284)
at org.netbeans.editor.DrawEngineLineView.modelToView(DrawEngineLineView.java:308)
at
org.netbeans.editor.DrawEngineLineView.getPreferredSpan(DrawEngineLineView.java:260)
at
org.netbeans.editor.DrawEngineLineView.minorAxisUpdateLayout(DrawEngineLineView.java:554)
at org.netbeans.editor.DrawEngineLineView.updateLayout(DrawEngineLineView.java:509)
at
org.netbeans.lib.editor.view.GapDocumentView$ChildrenUpdateTask.updateView(GapDocumentView.java:458)
at
org.netbeans.lib.editor.view.GapDocumentView$ChildrenUpdateTask.run(GapDocumentView.java:413)
at
org.netbeans.editor.view.spi.ViewLayoutQueue$LayoutThread.run(ViewLayoutQueue.java:184)
Comment 1 Miloslav Metelka 2006-01-24 16:32:05 UTC
I see, it's likely a threading issue.
 BTW we should stop using the o.n.e.Finder (and its extensions) completely and
scan the document's chars either through a segment or better as character sequence.
Comment 2 cahrens 2006-03-23 16:42:18 UTC
We keep getting reports of this bug.  Is it possible to get it fixed in the next
release?  Thanks-- Christina
Comment 3 cahrens 2006-05-30 19:28:54 UTC
I am proposing the following change in DocumentFinder's findBlocks method:

public static int[] findBlocks(BaseDocument doc, int startOffset, int 
endOffset, Map props, int blocks[]) throws BadLocationException{

        BlocksFinder finder =(BlocksFinder) getFinder(doc, props, false, true);
        if (finder == null){
            return blocks;
        }

        // CLA moved this out and added synchronized below for issue 71563.
        CharSequence cs = doc.getText(startOffset, endOffset - startOffset);
        if (cs==null){
            return null;
        }
        synchronized (finder) {
            finder.reset();
            finder.setBlocks(blocks);

            finder.find(startOffset, cs);
            int ret [] = finder.getBlocks();
            return ret;
        }
    }
Comment 4 Jan Becicka 2008-02-13 14:24:27 UTC
pls evaluate.
Comment 5 Miloslav Metelka 2008-02-13 23:12:47 UTC
I have integrated the fix, sorry for delay.
Fixed: db4968ace27a