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 192420

Summary: [70cat] ArrayIndexOutOfBoundsException: -1
Product: platform Reporter: pcdinh <pcdinh>
Component: ProgressAssignee: apireviews <apireviews>
Status: RESOLVED FIXED    
Severity: normal CC: aldobrucale, Chiana, exceptions_reporter, hmichel, jglick, mmirilovic, musilt2, myururdurmaz, scanti, simpatico
Priority: P2 Keywords: API_REVIEW_FAST, THREAD
Version: 7.0   
Hardware: All   
OS: All   
Issue Type: DEFECT Exception Reporter: 171061
Attachments: stacktrace
stacktrace
Synchronization in TaskModel
Patch for API_REVIEW

Description pcdinh 2010-11-24 17:00:42 UTC
Build: NetBeans IDE 7.0 Beta (Build 201011152355)
VM: Java HotSpot(TM) Client VM, 17.0-b15, Java(TM) SE Runtime Environment, 1.6.0_21-ea-b05
OS: Windows XP

User Comments:
pcdinh: Tried to run a J2ME project




Stacktrace: 
java.lang.ArrayIndexOutOfBoundsException: -1
   at java.util.Vector.elementAt(Vector.java:430)
   at javax.swing.DefaultListModel.getElementAt(DefaultListModel.java:70)
   at org.netbeans.modules.progress.spi.TaskModel.getSelectedHandle(TaskModel.java:154)
   at org.netbeans.modules.progress.spi.TaskModel.updateSelection(TaskModel.java:91)
   at org.netbeans.modules.progress.spi.TaskModel.addHandle(TaskModel.java:72)
   at org.netbeans.modules.progress.spi.Controller.runNow(Controller.java:282)
Comment 1 pcdinh 2010-11-24 17:00:46 UTC
Created attachment 103298 [details]
stacktrace
Comment 2 aldobrucale 2011-06-16 17:11:59 UTC
Created attachment 108932 [details]
stacktrace
Comment 3 Jan Peska 2011-08-09 12:31:11 UTC
*** Bug 200057 has been marked as a duplicate of this bug. ***
Comment 4 Exceptions Reporter 2011-10-06 10:20:47 UTC
This bug already has 20 duplicates 
see http://statistics.netbeans.org/exceptions/detail.do?id=171061
Comment 5 Jan Peska 2011-10-06 12:10:35 UTC
Created attachment 111595 [details]
Synchronization in TaskModel

Possible fix for this issue
Comment 6 Jan Peska 2011-10-06 12:59:58 UTC
Bug description: Occurrence of this issue is random. It is caused by leak of synchronization within progress API (usage of TaskModel.java). Two or more threads are accessing TaskModel's fields at the same time.

Waiver justification:  Patch is ready to use (see bugzilla) but it could affect other module that are using this API. This API is widely used in NB so I would like to apply these changes in the next version and solve eventual regressions then.

User impact: Exception dialog is shown. This issue was reported 6x in last three months (during different scenarios).

-> Keywords: 7.1_WAIVER_REQUEST
Comment 7 Jan Peska 2011-11-23 10:43:31 UTC
*** Bug 188999 has been marked as a duplicate of this bug. ***
Comment 8 Jan Peska 2011-11-23 11:06:22 UTC
Created attachment 113454 [details]
Patch for API_REVIEW

This is a final patch, ready to be reviewed. Sync blocks were added for every access to "model" and "selectionModel" fields. Attached listeners (ListDataListener, ListSelectionListener) are added to lists and they are called in another thread after an event is fired to prevent performing listener's actions in sync blocks.
Comment 9 Jan Peska 2011-11-23 11:08:40 UTC
Please review last attached patch.
Comment 10 Jesse Glick 2011-11-23 14:23:12 UTC
I do not think this need to go through API review; org.netbeans.modules.progress.spi is not a public SPI. (The NB module system is incapable of expressing that this package should be visible only to o.n.m.progress.ui whereas the API should be public, but that is the intent.)

Anyway it does not look like you are changing even the SPI, just its implementation; am I missing something?


BTW the following diff:

-    public void addListSelectionListener(ListSelectionListener listener) {
-        selectionModel.addListSelectionListener(listener);
+    public void addListSelectionListener(ListSelectionListener listener) {        
+        synchronized (selectionListeners) {
+            selectionListeners.add(listener);
+        }

shows you adding whitespace to the end of a line but otherwise not changing it. (1) Diffs, especially for review, should avoid formatting changes. (2) When working on any NB code please set Tools > Options > Editor > General > Remove Trailing Whitespace to "From Modified Lines Only" so sources are not polluted by trailing whitespace. (ml-hgext [1] promises to deal with it before commit but I have not found it reliable yet.)


[1] https://bitbucket.org/marcusl/ml-hgext/overview
Comment 11 Jan Peska 2011-11-24 13:21:44 UTC
I was not sure if changes in threading have to be reviewed or not. But thanks for tip, that whitespace
Comment 12 Jan Peska 2011-11-28 14:28:24 UTC
*** Bug 193861 has been marked as a duplicate of this bug. ***
Comment 13 Jan Peska 2011-11-28 14:31:09 UTC
fix: http://hg.netbeans.org/core-main/rev/284b651d4b71
Comment 14 Jesse Glick 2011-11-28 17:39:08 UTC
Do not forget to set Target Milestone when closing an issue as FIXED.

(In reply to comment #11)
> I was not sure if changes in threading have to be reviewed or not.

If the changes affect how clients may or should call the API, then this aspect of the contract should be mentioned in Javadoc and changes deserve a review. In this case my impression was that the threading was an internal implementation detail.
Comment 15 Quality Engineering 2011-11-29 15:56:28 UTC
Integrated into 'main-golden'
Changeset: http://hg.netbeans.org/main-golden/rev/284b651d4b71
User: Jan Peska <jpeska@netbeans.org>
Log: Issue #192420 - [70cat] ArrayIndexOutOfBoundsException: -1
Synchronization added. See issue comments
Comment 16 Jan Peska 2012-09-20 07:57:51 UTC
*** Bug 215228 has been marked as a duplicate of this bug. ***
Comment 17 Jan Peska 2013-08-12 08:13:52 UTC
*** Bug 229393 has been marked as a duplicate of this bug. ***
Comment 18 Ondrej Vrabec 2015-03-06 12:25:53 UTC
*** Bug 244997 has been marked as a duplicate of this bug. ***