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 181290 - IllegalStateException: attempted model write without invoking startTransaction
Summary: IllegalStateException: attempted model write without invoking startTransaction
Alias: None
Product: projects
Classification: Unclassified
Component: Maven (show other bugs)
Version: 6.x
Hardware: All All
: P1 normal (vote)
Assignee: David Simonek
: 187867 (view as bug list)
Depends on:
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
Exception Reporter: 163791

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

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:


stopd: I was adding a dependency from a Maven Repositories search result.

GUEST: Added a new library (JMF) to an existing maven project.

java.lang.IllegalStateException: attempted model write without invoking startTransaction
   at org.netbeans.modules.xml.xam.AbstractModel.validateWrite(
   at org.netbeans.modules.xml.xam.AbstractModel.rollbackTransaction(
   at org.netbeans.modules.maven.model.Utilities.performPOMModelOperations(
   at org.netbeans.modules.maven.api.ModelUtils.addDependency(
   at org.netbeans.modules.maven.nodes.DependenciesNode$AddDependencyAction.actionPerformed(
   at javax.swing.AbstractButton.fireActionPerformed(
Comment 1 Michal Mocnak 2010-02-26 10:38:05 UTC
Created attachment 94566 [details]
Comment 2 kawazu428 2010-03-17 13:01:18 UTC
Created attachment 95284 [details]

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 
Comment 4 aldobrucale 2010-04-14 11:40:43 UTC
Created attachment 97312 [details]

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]

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

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

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

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 
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: 
  try {
      // the transaction will be 100% ended if there isn't any exception.
  } finally {
      // the transaction will be 100% rolled back if it isn't ended.

2.1. It's necessary to replace the transaction usage pattern on the page 

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

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 (upload may still be in progress)
Log: #181290 - IllegalStateException: attemped model write without invoking startTransaction
Comment 17 Jaroslav Pospisil 2010-06-10 13:40:38 UTC
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
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. ***