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.
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) -------------------------------------------------------------------------
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.
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.
BTW this test passes for 7.3 (changeset 1f77a08481ab in http://hg.netbeans.org/main)
Stanislav, let's leave this bug opened (as P4), because attached test can help someone to fix introduced data race in implementation.