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.
Sorry to have this bug in core/code, but there is no category for registry (or did I just miss it?). The problem is in the class ContextBindings: the trick with lastAtomicAction does not work when the operation is invoked from some atomic action. I have found this problem when my code was called from ExplorerActions.DeleteActionsPerformer.doDestroy. Of course I could replan the manipulation with registry to another thread, but I suspect that I would have to replan *all* calls to registry to separate thread to make sure that the events are fired from the core/registry implementation. It would be good if the events were fired even when invoked from atomic action since I am not able to tell whether my code was already part of some atomic action. I was trying to supply a test for you but the tests for registry were not migrated to the new xtests (they did not work at least for me).
changed version to promo-d. registry is not part of 3.6
#40499 was fixed. So, please provide the test.
The test is here and it indeed fails: Checking in EventsTest.java; /cvs/openide/registry/test/unit/src/org/netbeans/api/registry/EventsTest.java,v <-- EventsTest.java new revision: 1.9; previous revision: 1.8 done But there are 5 more tests from openide/registry that also fail for me. Should I file separate bug reports?
Investigation: In ContextBindings.bindObject line 192 lastAtomicAction = null; is performed before the FileSystemListener.fileDeleted is performed. But this method assumes that lastAtomicAction returned on line FileSystemListener:140 from ctx.getContextBindings().getLastAtomicAction() is not null and contains the value assigned there on line ContextBinding:180. The reason for this is that when the whole code is invoked from another atomic action the notification to FileSystemListener is done from that another atomic action. The test should demonstrate the problem.
Created attachment 13679 [details] Test this patch after you fix testFromAtomicAction.
After applying your test the behaviour in real life (called from my module seems to be fixed). But I don't know how to fix the test. Seems like your fix is ok - should I commit it? Any idea why the test still fails on the first line here testFromAtomicAction: junit.framework.AssertionFailedError: Number of events does not match at junit.framework.Assert.fail(Assert.java:47) at junit.framework.Assert.assertTrue(Assert.java:20) at org.netbeans.api.registry.EventsTest.implTestEvents(EventsTest.java:127) at org.netbeans.api.registry.EventsTest.testEvents(EventsTest.java:57) at org.netbeans.api.registry.EventsTest$1.run(EventsTest.java:82) at org.openide.filesystems.EventControl.runAtomicAction(EventControl.java:89) at org.openide.filesystems.FileSystem.runAtomicAction(FileSystem.java:417) at org.netbeans.api.registry.EventsTest.testFromAtomicAction(EventsTest.java:78)
#40498 - is a real issue . But this test testFromAtomicAction is completely wrong. You can modify contexts and bindings in AtomicAction, but you must test events after atomic block because events from filesystems are postponed. So, please rewrite it to be more correct. Registry can't be never fixed to satisfy this test.
Created attachment 13698 [details] Modified test -but fails for merged contexts
Before this patch is commited there should be at least evaluated why this test fails for merged contexts. I'm not sure if I find enough time to evaluate it today.
Maybe there should be also documented that in current implementation (based on filesystems) of Registry events are postponed if inside of atomic block (similarly like events from filesystems) - you can fill it.
Aha, as you can see I did not understand how to write such a test. But as I mentioned before from my point of view you can commit your fix since it solved the problem for my module at least. Now it is clear what to do with the test. You are attaching somehow garbled diffs - your lines are wrapped and also using context diff (cvs diff -c) is usually more readable. I had to manually apply your patches ;-(
Fixed. Filed new issue #40578 - REGISTRY: MergedContexts - fails test testFromAtomicAction1 /cvs/openide/registry/test/unit/src/org/netbeans/api/registry/EventsTest.java,v <-- EventsTest.java new revision: 1.10; previous revision: 1.9 /cvs/core/registry/src/org/netbeans/core/registry/ContextBindings.java,v <-- ContextBindings.java new revision: 1.10; previous revision: 1.9 /cvs/core/registry/src/org/netbeans/core/registry/FileSystemListener.java,v <--FileSystemListener.java new revision: 1.5; previous revision: 1.4
David (any ;), could you please verify. Thanks.
x