Please use the Apache issue tracking system for new NetBeans issues (https://issues.apache.org/jira/projects/NETBEANS0/issues) !!
Bug 181290 - IllegalStateException: attempted model write without invoking startTransaction
IllegalStateException: attempted model write without invoking startTransaction
Status: VERIFIED FIXED
Product: projects
Classification: Unclassified
Component: Maven
6.x
All All
: P1 (vote)
: 6.x
Assigned To: David Simonek
issues@projects
EXCEPTIONS_REPORT, 69patch1
:
: 187867 (view as bug list)
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2010-02-26 10:38 UTC by Michal Mocnak
Modified: 2010-07-15 14:33 UTC (History)
18 users (show)

See Also:
Issue Type: DEFECT
:


Attachments
stacktrace (3.11 KB, text/plain)
2010-02-26 10:38 UTC, Michal Mocnak
Details
stacktrace (2.58 KB, text/plain)
2010-03-17 13:01 UTC, kawazu428
Details
stacktrace (2.58 KB, text/plain)
2010-04-14 11:40 UTC, aldobrucale
Details
stacktrace (2.64 KB, text/plain)
2010-04-15 08:34 UTC, Petr Jiricka
Details
stacktrace (2.64 KB, text/plain)
2010-04-27 12:29 UTC, Kenneth Ganfield
Details
stacktrace (2.58 KB, text/plain)
2010-05-17 09:37 UTC, aldobrucale
Details
stacktrace (2.64 KB, text/plain)
2010-05-25 16:35 UTC, Kenneth Ganfield
Details
recommended changes to maven.model module (3.65 KB, text/plain)
2010-05-26 18:43 UTC, Nikita Krjukov
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Michal Mocnak 2010-02-26 10:38:00 UTC
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)
Comment 1 Michal Mocnak 2010-02-26 10:38:05 UTC
Created attachment 94566 [details]
stacktrace
Comment 2 kawazu428 2010-03-17 13:01:18 UTC
Created attachment 95284 [details]
stacktrace

removed a dependency from a maven2 pom.xml ...
Comment 3 Exceptions Reporter 2010-03-17 13:01:31 UTC
This bug already has 10 duplicates 
see http://statistics.netbeans.org/exceptions/detail.do?id=163791
Comment 4 aldobrucale 2010-04-14 11:40:43 UTC
Created attachment 97312 [details]
stacktrace

Adding dependency to nb platform application (maven) via "Libraries" nore/ add
Comment 5 Petr Jiricka 2010-04-15 08:34:46 UTC
Created attachment 97412 [details]
stacktrace

Adding dependency to Maven project.
Comment 6 Kenneth Ganfield 2010-04-27 12:29:15 UTC
Created attachment 98135 [details]
stacktrace

right-clicked on Libraries in maven platform project
Comment 7 aldobrucale 2010-05-17 09:37:52 UTC
Created attachment 99077 [details]
stacktrace

Adding a maven dependency
Comment 8 Kenneth Ganfield 2010-05-25 16:35:28 UTC
Created attachment 99450 [details]
stacktrace

added open project as a dependency of a Maven Module Suite
Comment 9 Exceptions Reporter 2010-05-25 16:35:38 UTC
This bug already has 50 duplicates 
see http://statistics.netbeans.org/exceptions/detail.do?id=163791
Comment 10 Sergey Lunegov 2010-05-25 16:52:32 UTC
Nikita, please take a look. I believe it's maven problems but please investgate before reassigning.
Comment 11 Nikita Krjukov 2010-05-25 19:28:05 UTC
It looks like the thread, which tries rolling back transaction isn't the thread, which has started it.
Comment 12 Nikita Krjukov 2010-05-26 17:47:15 UTC
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).
Comment 13 Sergey Lunegov 2010-05-26 17:55:52 UTC
reassign to maven project.
Comment 14 Nikita Krjukov 2010-05-26 18:43:32 UTC
Created attachment 99504 [details]
recommended changes to maven.model module
Comment 15 Nikita Krjukov 2010-05-26 18:47:28 UTC
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.
Comment 16 Quality Engineering 2010-05-28 08:03:09 UTC
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
Comment 17 Jaroslav Pospisil 2010-06-10 13:40:38 UTC
v.
Comment 18 Nikita Krjukov 2010-06-18 17:09:39 UTC
The fix is simple and not dangerous so I'm going to mode it to release691
Comment 19 Nikita Krjukov 2010-06-18 20:22:18 UTC
transplanted modification from trunk to release691 http://hg.netbeans.org/release691/rev/c633deb99fc4
Comment 20 Jaroslav Pospisil 2010-07-08 13:35:21 UTC
v. in 201007062301
Comment 21 Jesse Glick 2010-07-15 14:32:48 UTC
*** Bug 187867 has been marked as a duplicate of this bug. ***


By use of this website, you agree to the NetBeans Policies and Terms of Use. © 2014, Oracle Corporation and/or its affiliates. Sponsored by Oracle logo