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 240218 - Data Race in PropertiesStructure [regression from 7.3]
Summary: Data Race in PropertiesStructure [regression from 7.3]
Status: REOPENED
Alias: None
Product: platform
Classification: Unclassified
Component: Property Editors (show other bugs)
Version: 7.4
Hardware: PC All
: P4 normal (vote)
Assignee: Stanislav Aubrecht
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2014-01-10 12:59 UTC by sealexer
Modified: 2014-01-15 04:40 UTC (History)
1 user (show)

See Also:
Issue Type: DEFECT
Exception Reporter:


Attachments
Unit test for the described case (1.60 KB, text/x-java)
2014-01-10 12:59 UTC, sealexer
Details

Note You need to log in before you can comment on or make changes to this bug.
Description sealexer 2014-01-10 12:59:05 UTC
Created attachment 143795 [details]
Unit test for the described case

Class org.netbeans.modules.properties.PropertiesStructure has the following apis:

- boolean addItem(String,String,String)
- Iterator<Element.ItemElem> allItems()

It is reasonable to assume that if one invokes addItem N times in a single-threaded app and iterates over them on the next step, the iterating code should observe those N items. However it is not the case with current implementation.

The attached test produces the following output (NB-7.4):
-------------------------------------------------------------------------
Testcase: testAddGetItems(org.netbeans.modules.properties.PropertiesStructureConsistencyTest):	FAILED
Unexpected number of elements in PropertiesStructure! expected:<100> but was:<99>
junit.framework.AssertionFailedError: Unexpected number of elements in PropertiesStructure! expected:<100> but was:<99>
	at org.netbeans.modules.properties.PropertiesStructureConsistencyTest.testAddGetItems(PropertiesStructureConsistencyTest.java:26)
	at org.netbeans.junit.NbTestCase.access$200(NbTestCase.java:97)
	at org.netbeans.junit.NbTestCase$2.doSomething(NbTestCase.java:431)
	at org.netbeans.junit.NbTestCase$1Guard.run(NbTestCase.java:357)
	at java.lang.Thread.run(Thread.java:722)
-------------------------------------------------------------------------
Comment 1 sealexer 2014-01-10 13:27:18 UTC
PropertiesStructure.addItem(String,String,String) performs two things:

- explicitly adds the new item to the internal structure;
- implicitly submits asynchronous job which "re-parses" the property file and invokes PropertiesStructure.update(PropertiesStructure). This updating code might be connected with the cause of the described inconsistent behavior.
Comment 2 Stanislav Aubrecht 2014-01-13 13:28:12 UTC
The API in Properties module is friends-only so I don't see any need to provide a fix that might introduce regressions.

A short Thread.sleep() before counting the items makes the test passs. Every change in the PropertiesStructure triggers a reparse so the test fails because it sees the reparse result of the last but one modification. The final reparse is already scheduled at the time of the count check.
Comment 3 sealexer 2014-01-14 16:48:50 UTC
BTW this test passes for 7.3 (changeset 1f77a08481ab in http://hg.netbeans.org/main)
Comment 4 Vladimir Voskresensky 2014-01-15 04:40:43 UTC
Stanislav, let's leave this bug opened (as P4), because attached test can help someone to fix introduced data race in implementation.