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.
Build: NetBeans IDE Dev (Build 201002240200) VM: Java HotSpot(TM) 64-Bit Server VM, 14.3-b01-101, Java(TM) SE Runtime Environment, 1.6.0_17-b04-248-10M3025 OS: Mac OS X User Comments: mmocnak: Adding maven dependency: org.apache.felix.http.jetty stopd: I was adding a dependency from a Maven Repositories search result. GUEST: Added a new library (JMF) to an existing maven project. Stacktrace: java.lang.IllegalStateException: attempted model write without invoking startTransaction at org.netbeans.modules.xml.xam.AbstractModel.validateWrite(AbstractModel.java:418) at org.netbeans.modules.xml.xam.AbstractModel.rollbackTransaction(AbstractModel.java:379) at org.netbeans.modules.maven.model.Utilities.performPOMModelOperations(Utilities.java:343) at org.netbeans.modules.maven.api.ModelUtils.addDependency(ModelUtils.java:105) at org.netbeans.modules.maven.nodes.DependenciesNode$AddDependencyAction.actionPerformed(DependenciesNode.java:368) at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:2028)
Created attachment 94566 [details] stacktrace
Created attachment 95284 [details] stacktrace removed a dependency from a maven2 pom.xml ...
This bug already has 10 duplicates see http://statistics.netbeans.org/exceptions/detail.do?id=163791
Created attachment 97312 [details] stacktrace Adding dependency to nb platform application (maven) via "Libraries" nore/ add
Created attachment 97412 [details] stacktrace Adding dependency to Maven project.
Created attachment 98135 [details] stacktrace right-clicked on Libraries in maven platform project
Created attachment 99077 [details] stacktrace Adding a maven dependency
Created attachment 99450 [details] stacktrace added open project as a dependency of a Maven Module Suite
This bug already has 50 duplicates see http://statistics.netbeans.org/exceptions/detail.do?id=163791
Nikita, please take a look. I believe it's maven problems but please investgate before reassigning.
It looks like the thread, which tries rolling back transaction isn't the thread, which has started it.
Unfortunately there are a vulnerability of the XAM transaction system. The methods endTransaction() and rollbackTransaciton() both finalize a transaction. But only one of them can be called. Otherwise the IllegalStateException is thrown. So the reliability of user's code strongly depends of using this methods. I tried analyzing possible variants. It doesn't worth repeating all considerations here because there are too many of them. I only going to write conclusions. 1. The methods endTransaction() and rollbackTransaciton() shouldn't throw exception in case the transaction already finished. They simply have to exit without exception. Such modification looks reasonable and seamless because it doesn't come to XAM API changes. I only going to add a few new lines to Javadoc of the methods, which should clarify theirs usage. 2. The most reliable transaction usage pattern is the following: model.startTransaction() try { doSomethingWithModel(); // // the transaction will be 100% ended if there isn't any exception. model.endTransaction(); } finally { // // the transaction will be 100% rolled back if it isn't ended. model.rollbackTransaction(); } 2.1. It's necessary to replace the transaction usage pattern on the page http://xml.netbeans.org/xml-usage.html 3. The method isIntransaction() should be used very carefully. Actually it looks like it isn't necessary almost at all. It can be helpful only in a case, which is close to reentrant transactions. The XAM model actually doesn't support really reentrant transactions. But in some cases it seems helpful to start a transaction automatically if it hasn't been started yet. Unfortunately, this method doesn't inform if the transaction is controlled by current thread or not. So another one method would be helpful in the mentioned case: isIntransactionByCurrentThread(). But I don't think it worth adding such method now because it change API and this bug seems doesn't require it. So now it's recommended to get rid of automatic transaction starting whenever it possible. The source code should start transactions explicitly. I'm sure it won't be difficult to find all places (catch all exception from thestartTransacton()) where a new transaction is trying to be started by the same thread (if transaction has already started by them).
reassign to maven project.
Created attachment 99504 [details] recommended changes to maven.model module
I've pushed the changes described above to the xml.xam module (XAM Model). See here http://hg.netbeans.org/main/rev/0f4b81bccc89 I haven't pushed changes to the maven.model module because I don't know how to validate it. But I suggest very simple modifications. See the attached file. Anyway, the exception shouldn't appear again after my fix. So I close the issue.
Integrated into 'main-golden', will be available in build *201005280001* on http://bits.netbeans.org/dev/nightly/ (upload may still be in progress) Changeset: http://hg.netbeans.org/main/rev/0f4b81bccc89 User: supernikita@netbeans.org Log: #181290 - IllegalStateException: attemped model write without invoking startTransaction
v.
The fix is simple and not dangerous so I'm going to mode it to release691
transplanted modification from trunk to release691 http://hg.netbeans.org/release691/rev/c633deb99fc4
v. in 201007062301
*** Bug 187867 has been marked as a duplicate of this bug. ***