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 165465 - IllegalArgumentException: old node must be in the tree
Summary: IllegalArgumentException: old node must be in the tree
Status: RESOLVED FIXED
Alias: None
Product: apisupport
Classification: Unclassified
Component: Maven (show other bugs)
Version: 6.x
Hardware: All All
: P2 blocker (vote)
Assignee: Milos Kleint
URL: http://statistics.netbeans.org/except...
Keywords:
Depends on:
Blocks:
 
Reported: 2009-05-19 08:36 UTC by martin_wh99
Modified: 2009-11-04 22:30 UTC (History)
9 users (show)

See Also:
Issue Type: DEFECT
Exception Reporter: 150616


Attachments
stacktrace (3.82 KB, text/plain)
2009-05-19 08:36 UTC, martin_wh99
Details
stacktrace (2.25 KB, text/plain)
2009-06-11 22:00 UTC, rohitbrai
Details
stacktrace (3.63 KB, text/plain)
2009-06-11 22:01 UTC, rohitbrai
Details
stacktrace (3.63 KB, text/plain)
2009-07-04 15:37 UTC, rohitbrai
Details
stacktrace (6.94 KB, text/plain)
2009-08-25 13:15 UTC, Milos Kleint
Details
stacktrace (6.95 KB, text/plain)
2009-08-26 12:43 UTC, Milos Kleint
Details

Note You need to log in before you can comment on or make changes to this bug.
Description martin_wh99 2009-05-19 08:36:14 UTC
Build: NetBeans IDE 6.7 Beta (Build 200904242137)
VM: Java HotSpot(TM) Client VM, 10.0-b22, Java(TM) SE Runtime Environment, 1.6.0_06-b02
OS: Windows Vista, 6.0, x86

User Comments:
GUEST: I wanted to change the Source/Binary-Format from 1.3 to 1.6 in the properties of a Maven jar project, when the crash occured.



Stacktrace: 
java.lang.IllegalArgumentException: old node must be in the tree
        at org.netbeans.modules.xml.xdm.XDMModel.getPathToRoot(XDMModel.java:320)
        at org.netbeans.modules.xml.xdm.XDMModel.mutate(XDMModel.java:360)
        at org.netbeans.modules.xml.xdm.XDMModel.mutate(XDMModel.java:339)
        at org.netbeans.modules.xml.xdm.XDMModel.append(XDMModel.java:622)
        at org.netbeans.modules.xml.xdm.xam.XDMAccess.appendChild(XDMAccess.java:267)
        at org.netbeans.modules.xml.xam.dom.AbstractDocumentComponent.appendChildQuietly(AbstractDocumentComponent.java:296)
Comment 1 martin_wh99 2009-05-19 08:36:19 UTC
Created attachment 82367 [details]
stacktrace
Comment 2 rohitbrai 2009-06-11 22:00:48 UTC
Build: NetBeans IDE 6.7 RC2 (Build 200906042131)
VM: Java HotSpot(TM) 64-Bit Server VM, 11.3-b02, Java(TM) SE Runtime Environment, 1.6.0_13-b03
OS: Windows Vista, 6.0, amd64

User Comments: 
I tried to deploy a maven web project to Glassfish V3 server

Stacktrace: 
java.lang.IllegalArgumentException: old node must be in the tree
        at org.netbeans.modules.xml.xdm.XDMModel.getPathToRoot(XDMModel.java:320)
        at org.netbeans.modules.xml.xdm.XDMModel.mutate(XDMModel.java:360)
        at org.netbeans.modules.xml.xdm.XDMModel.mutate(XDMModel.java:339)
        at org.netbeans.modules.xml.xdm.XDMModel.append(XDMModel.java:622)
        at org.netbeans.modules.xml.xdm.xam.XDMAccess.appendChild(XDMAccess.java:267)
        at org.netbeans.modules.xml.xam.dom.AbstractDocumentComponent.appendChildQuietly(AbstractDocumentComponent.java:296)
Comment 3 rohitbrai 2009-06-11 22:00:58 UTC
Created attachment 83466 [details]
stacktrace
Comment 4 Exceptions Reporter 2009-06-11 22:01:13 UTC
This issue already has 12 duplicates 
see http://statistics.netbeans.org/exceptions/detail.do?id=150616
Comment 5 rohitbrai 2009-06-11 22:01:50 UTC
Build: NetBeans IDE 6.7 RC2 (Build 200906042131)
VM: Java HotSpot(TM) 64-Bit Server VM, 11.3-b02, Java(TM) SE Runtime Environment, 1.6.0_13-b03
OS: Windows Vista, 6.0, amd64

User Comments: 
Set Glassfish V3 as the server in a maven web project properties

Stacktrace: 
java.lang.IllegalArgumentException: old node must be in the tree
        at org.netbeans.modules.xml.xdm.XDMModel.getPathToRoot(XDMModel.java:320)
        at org.netbeans.modules.xml.xdm.XDMModel.mutate(XDMModel.java:360)
        at org.netbeans.modules.xml.xdm.XDMModel.mutate(XDMModel.java:339)
        at org.netbeans.modules.xml.xdm.XDMModel.append(XDMModel.java:622)
        at org.netbeans.modules.xml.xdm.xam.XDMAccess.appendChild(XDMAccess.java:267)
        at org.netbeans.modules.xml.xam.dom.AbstractDocumentComponent.appendChildQuietly(AbstractDocumentComponent.java:296)
Comment 6 rohitbrai 2009-06-11 22:01:58 UTC
Created attachment 83467 [details]
stacktrace
Comment 7 Exceptions Reporter 2009-06-11 22:02:53 UTC
This issue already has 13 duplicates 
see http://statistics.netbeans.org/exceptions/detail.do?id=150616
Comment 8 rohitbrai 2009-07-04 15:36:58 UTC
Build: NetBeans IDE 6.7 (Build 200906241340)
VM: Java HotSpot(TM) 64-Bit Server VM, 11.3-b02, Java(TM) SE Runtime Environment, 1.6.0_13-b03
OS: Windows Vista, 6.0, amd64

User Comments: 


Stacktrace: 
java.lang.IllegalArgumentException: old node must be in the tree
        at org.netbeans.modules.xml.xdm.XDMModel.getPathToRoot(XDMModel.java:320)
        at org.netbeans.modules.xml.xdm.XDMModel.mutate(XDMModel.java:360)
        at org.netbeans.modules.xml.xdm.XDMModel.mutate(XDMModel.java:339)
        at org.netbeans.modules.xml.xdm.XDMModel.append(XDMModel.java:622)
        at org.netbeans.modules.xml.xdm.xam.XDMAccess.appendChild(XDMAccess.java:267)
        at org.netbeans.modules.xml.xam.dom.AbstractDocumentComponent.appendChildQuietly(AbstractDocumentComponent.java:296)
Comment 9 rohitbrai 2009-07-04 15:37:02 UTC
Created attachment 84363 [details]
stacktrace
Comment 10 Exceptions Reporter 2009-07-04 15:37:07 UTC
This issue already has 14 duplicates 
see http://statistics.netbeans.org/exceptions/detail.do?id=150616
Comment 11 Milos Kleint 2009-08-25 13:15:29 UTC
Build: NetBeans IDE Dev (Build 090821)
VM: Java HotSpot(TM) Client VM, 1.5.0_09-b03, Java(TM) 2 Runtime Environment, Standard Edition, 1.5.0_09-b03
OS: Linux, 2.6.29.6-desktop-2mnb, i386

User Comments: 


Stacktrace: 
java.lang.IllegalArgumentException: old node must be in the tree
        at org.netbeans.modules.xml.xdm.XDMModel.getPathToRoot(XDMModel.java:320)
        at org.netbeans.modules.xml.xdm.XDMModel.mutate(XDMModel.java:360)
        at org.netbeans.modules.xml.xdm.XDMModel.mutate(XDMModel.java:339)
        at org.netbeans.modules.xml.xdm.XDMModel.append(XDMModel.java:622)
        at org.netbeans.modules.xml.xdm.xam.XDMAccess.appendChild(XDMAccess.java:267)
        at org.netbeans.modules.xml.xam.dom.AbstractDocumentComponent.appendChildQuietly(AbstractDocumentComponent.java:296)
Comment 12 Milos Kleint 2009-08-25 13:15:33 UTC
Created attachment 86621 [details]
stacktrace
Comment 13 Milos Kleint 2009-08-25 13:19:05 UTC
I can reliably reproduce by doing the following
1. create a maven project
2. go to project properties, change source level and encoding
3. CANCEL the dialog (the transaction shall be rollbacked)
4. go to project properties again, fiddle with source level and encoding -> exception

Comment 14 Milos Kleint 2009-08-26 12:43:45 UTC
Build: NetBeans IDE Dev (Build 090821)
VM: Java HotSpot(TM) Client VM, 1.5.0_09-b03, Java(TM) 2 Runtime Environment, Standard Edition, 1.5.0_09-b03
OS: Linux, 2.6.29.6-desktop-2mnb, i386

User Comments: 
cancel on maven project proeprties dialog, then open it again immediately

Stacktrace: 
java.lang.IllegalArgumentException: old node must be in the tree
        at org.netbeans.modules.xml.xdm.XDMModel.getPathToRoot(XDMModel.java:320)
        at org.netbeans.modules.xml.xdm.XDMModel.mutate(XDMModel.java:360)
        at org.netbeans.modules.xml.xdm.XDMModel.mutate(XDMModel.java:339)
        at org.netbeans.modules.xml.xdm.XDMModel.append(XDMModel.java:622)
        at org.netbeans.modules.xml.xdm.xam.XDMAccess.appendChild(XDMAccess.java:267)
        at org.netbeans.modules.xml.xam.dom.AbstractDocumentComponent.appendChildQuietly(AbstractDocumentComponent.java:296)
Comment 15 Milos Kleint 2009-08-26 12:43:49 UTC
Created attachment 86679 [details]
stacktrace
Comment 16 _ alexpetrov 2009-10-05 20:43:40 UTC
Steps to reproduce:
1. Create a simple Maven project
2. Invoke the dialog Project Properties.
3. In the tree Categories select the tree node Sources.
4. Select a new value in the combo-box Source/Binary Format (for example, change the value 1.3 to 1.5).
5. Click the button Cancel.
6. Repeat steps 2, 3, 4.

Result:
IllegalArgumentException will be thrown.

If the button OK is used in the step 5 instead of the button Cancel, this bug will never happen.

This bug is caused by mismatch of POMModel based on XAM and a related XDM model, which updates pom.xml.

When user changes a value in the combo-box Source/Binary Format for the first time, a chain of method invocations will
contain:
    SourcesPanel.handleSourceLevelChange() {
        ..............
        ModelUtils.checkSourceLevel(handle, sourceLevel);
        ..............
    }
    ModelUtils.checkSourceLevel(...) {
        POMModel mdl = ...;
        ..............
        mdl.getProject().setBuild(mdl.getFactory().createBuild());
        ..............
        mdl.getProject().getBuild().addPlugin(plugin);
    }

So, now POMModel tree will be modified: Project -> Build -> PluginList (Plugins) -> Plugin.
But XDM model and pom.xml are not modified because a started transaction is not finished yet.

This transaction will be either commited (an user clicks OK) or rolled back (an user clicks Cancel):

     // OK
     CustomizerProviderImpl.OptionListener.actionPerformed(...) {
        ..............
        if (handle.isModified(handle.getPOMModel())) {
            handle.getPOMModel().endTransaction();
        } else {
            handle.getPOMModel().rollbackTransaction();
        }
        ..............
     }
     A structure of pom.xml will be modified: 
     <project>
         <build>
             <plugins>
                 <plugin>

     // Cancel
     CustomizerProviderImpl.OptionListener.windowClosed(...) {
        ..............
         if (handle.getPOMModel().isIntransaction()) {
             handle.getPOMModel().rollbackTransaction();
         }
        ..............
     }

     A structure of pom.xml will not be modified in this case,
     but (!) POMModel will still contain an object Build (model's changes will not be rolled back).

And when user tries to change value of Source/Binary Format for the 2nd time (after clicking Cancel), this will throw an
exception because value of variable 'childs' (see below) is not null (POMModel (XAM) contains an object Build):
    BuildBaseImpl.addPlugin(Plugin plugin) {
        ModelList<Plugin> childs = getChild(PluginImpl.List.class);
        if (childs == null) {
        ..............
        }
        childs.addListChild(plugin);
    }

    Then childs.addListChild(plugin) invokes 
        XDMModel.getPathToRoot((Node node, Document root) 
        and  
        PathFromRootVisitor.findPath(Document root, Node target)
    
    XDM model (pom.xml) was not modified and doesn't contain a required node <build>.
    So, a required path can't be defined ==> IllegalArgumentException.

More investigation of XAM and XDM interaction is needed.
Comment 17 Exceptions Reporter 2009-10-13 21:33:38 UTC
This issue already has 22 duplicates 
see http://statistics.netbeans.org/exceptions/detail.do?id=150616
Comment 18 Exceptions Reporter 2009-10-14 21:37:25 UTC
This issue already has 23 duplicates 
see http://statistics.netbeans.org/exceptions/detail.do?id=150616
Comment 19 Exceptions Reporter 2009-10-14 21:42:27 UTC
This issue already has 24 duplicates 
see http://statistics.netbeans.org/exceptions/detail.do?id=150616
Comment 20 _ alexpetrov 2009-10-26 18:00:06 UTC
Now I'd like to describe a result of my investigation related to my comment dated by Mon Oct 5 19:43:40
Please look at additional comments from alexpetrov Mon Oct 5 19:43:40 +0000 2009.

Short description.
IllegalArgumentException will be thrown if an user clicks Cancel button while editing of maven project properties,
because XAM and XDM models will get unsynchronized, though if OK is clicked XAM and XDM models will be synchronized.

It seems that this behaviour is caused by the following reason:

If an user clicks Cancel button the method rollbackTransaction() will be invoked:
org.netbeans.modules.maven.customizer.CustomizerProviderImpl.java
  CustomizerProviderImpl.OptionListener.windowClosed(...) => handle.getPOMModel().rollbackTransaction() =>
org.netbeans.modules.xml.xam.AbstractModel.rollbackTransaction()

Invocation of rollbackTransaction() should remove a created object Build (org.netbeans.modules.maven.model.pom.Build)
from POMModel (XAM model).

Here is a chain of method invocations:

AbstractModel.rollbackTransaction() => AbstractModel$ModelUndoableEditSupport.abortUpdate() => ... =>
XDMAccess.finishUndoRedo() => XDMListener.endSync() => ... => AbstractDocumentModel.processSyncUnit() =>
AbstractDocumentModel.removeChildComponent(Component child) [child: org.netbeans.modules.maven.model.pom.impl.BuildImpl]
=> org.netbeans.modules.maven.model.pom.visitor.ChildComponentUpdateVisitor.update() [target: ProjectImpl, child:
BuildImpl, operation: REMOVE] => BuildImpl.accept((POMComponentVisitor visitor) [visitor: ChildComponentUpdateVisitor]
=> org.netbeans.modules.maven.model.pom.visitor.DefaultVisitor.visit(Build target) =>  DefaultVisitor.visitComponent(...)

But an implementation of DefaultVisitor.visitComponent() is empty:
    protected void visitComponent(POMComponent target) {
    }

Thus an object Build has not been removed from POM model and this will cause an exception when project properties are
edited in the next time.
A correct implementation of the method visit(Build target) should be produced.

So, I think this bug should be reassigned to maven plugin team.
Please let me know if you have any objections.
Comment 21 Milos Kleint 2009-10-27 09:37:08 UTC
alexpetrov: great thanks for the explanation. It seems I never really understood what the childupdatevisitor is supposed
to do. I there any relevant example I could use to rewrite it?
Comment 22 _ alexpetrov 2009-10-27 13:57:49 UTC
OK, please, take a look at a piece of code below (it's a fragment of the class
org.netbeans.modules.bpel.model.ext.editor.impl.NMPropertyImpl, which implements the method "... void update(...)"):

public void update(BpelEntity target, ExtensionEntity child, int index, Operation operation) {
    if (target instanceof NMProperties) {
        NMProperties nmProperties = (NMProperties) target;
        NMProperty nmProperty = (NMProperty) child;
        switch (operation) {
        case ADD:
            nmProperties.insertNMProperty(nmProperty, index);
            break;
        case REMOVE:
            nmProperties.remove(nmProperty);
            break;
        }
    }
}

And then take a look at a COMMENTED PART OF CODE included into your class
org.netbeans.modules.maven.model.pom.visitor.ChildComponentUpdateVisitor - I think it already contains code which you
can use or which will be useful for you (I'm sure you will understand an idea very quickly).

In your case:
BpelEntity target     => POMComponent target (ProjectImpl)
ExtensionEntity child => POMComponent child (BuildImpl)

So, your ProjectImpl just must remove an unnecessary BuildImpl from its model tree.
Let me know if you have any questions.
Comment 23 Milos Kleint 2009-10-29 14:15:14 UTC
alexpetrov: 
as I mentioned in a private email, I'm lost why the ComponentUpdater is necessary at all. The AbstractComponent class
seems to have 2 generic methods for adding and removing child nodes. I've added a dummy implementation that to the
ComponentUpdater that delegates to these methods and it seems to work. At least this exception is gone. The remaining
question is what property is to be fired. It seems that none of the internals of the XAM/XDM models listen to it. No
code in maven support listens to it either, so is it reasonable to assume that the property listening and firing is just
an optional mechanism? Please review:
http://hg.netbeans.org/core-main/rev/d9961884787f
Comment 24 Quality Engineering 2009-10-30 11:07:01 UTC
Integrated into 'main-golden', will be available in build *200910300201* on http://bits.netbeans.org/dev/nightly/ (upload may still be in progress)
Changeset: http://hg.netbeans.org/main-golden/rev/d9961884787f
User: Milos Kleint <mkleint@netbeans.org>
Log: #165465 implement ComponentUpdater to really add/remove child components. Still not clear if the impl is correct or how to figure the right "property" to get fired.
Comment 25 Quality Engineering 2009-11-04 22:30:32 UTC
Integrated into 'main-golden', will be available in build *200911041401* on http://bits.netbeans.org/dev/nightly/ (upload may still be in progress)
Changeset: http://hg.netbeans.org/main/rev/4a49732ebdc9
User: Milos Kleint <mkleint@netbeans.org>
Log: #165465 ContentUpdater for profiles and settings as well