bugzilla.mozilla.org will be intermittently unavailable on Saturday, March 24th, from 16:00 until 20:00 UTC.

DOM exception when mixing empty and non-empty namespaces



10 years ago
10 years ago


(Reporter: Matthieu Riou, Unassigned)




(1 attachment, 2 obsolete attachments)



10 years ago
User-Agent:       Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9) Gecko/2008060309 Firefox/3.0
Build Identifier: 1.7RC1

This isn't really easy to describe so you'll have to bear with me a little (and have a look at the steps to reproduce first).

When an expression like friendInfo.name gets executed, a new name element is created as a child of friendInfo. The new element qname matches the qname of the previous element if there was one before (friendInfo already had a name child). However when the new element gets created, the default namespace lookup happens on the parent node (the friendInfo element in this example) which does have a qname. So the code ends up creating an element with an empty namespace (as was previously) but with a prefix which is assumed to match the parent. That doesn't work quite well in DOM land.

Reproducible: Always

Steps to Reproduce:
Just type the following in a Rhino interpreter:

var friendInfo = <friend xmlns="http://ode.apache.org/simpel/1.0/definition/XmlData"><name xmlns=""/><phone xmlns=""/></friend>;
var msgIn = <xd:dataOpRequest xmlns:xd="http://ode.apache.org/simpel/1.0/definition/XmlData">
friendInfo.name = msgIn.person.firstName.text() + " " + msgIn.person.lastName.text();

Actual Results:  
Exception in thread "main" org.w3c.dom.DOMException: NAMESPACE_ERR: An attempt is made to create or change an object in a way which is incorrect with regard to namespaces.
        at com.sun.org.apache.xerces.internal.dom.ElementNSImpl.setName(ElementNSImpl.java:176)
        at com.sun.org.apache.xerces.internal.dom.ElementNSImpl.<init>(ElementNSImpl.java:112)
        at com.sun.org.apache.xerces.internal.dom.CoreDocumentImpl.createElementNS(CoreDocumentImpl.java:1969)
        at com.sun.org.apache.xerces.internal.dom.CoreDocumentImpl.importNode(CoreDocumentImpl.java:1487)
        at com.sun.org.apache.xerces.internal.dom.CoreDocumentImpl.importNode(CoreDocumentImpl.java:1444)
        at org.mozilla.javascript.xmlimpl.XmlNode.insertChildAt(XmlNode.java:223)
        at org.mozilla.javascript.xmlimpl.XmlNode.insertChildrenAt(XmlNode.java:237)
        at org.mozilla.javascript.xmlimpl.XML.insertChildAfter(XML.java:531)
        at org.mozilla.javascript.xmlimpl.XML.replace(XML.java:478)
        at org.mozilla.javascript.xmlimpl.XMLName.setMyValueOn(XMLName.java:341)
        at org.mozilla.javascript.xmlimpl.XML.putXMLProperty(XML.java:195)
        at org.mozilla.javascript.xmlimpl.XMLObjectImpl.ecmaPut(XMLObjectImpl.java:299)
        at org.mozilla.javascript.ScriptRuntime.setObjectProp(ScriptRuntime.java:1515)
        at org.mozilla.javascript.ScriptRuntime.setObjectProp(ScriptRuntime.java:1507)
        at org.mozilla.javascript.Interpreter.interpretLoop(Interpreter.java:3063)
        at org.mozilla.javascript.Interpreter.interpret(Interpreter.java:2484)
        at org.mozilla.javascript.InterpretedFunction.call(InterpretedFunction.java:162)
        at org.mozilla.javascript.ContextFactory.doTopCall(ContextFactory.java:401)
        at org.mozilla.javascript.ScriptRuntime.doTopCall(ScriptRuntime.java:3003)
        at org.mozilla.javascript.InterpretedFunction.exec(InterpretedFunction.java:173)
        at org.mozilla.javascript.tools.shell.Main.evaluateScript(Main.java:526)
        at org.mozilla.javascript.tools.shell.Main.processSource(Main.java:386)
        at org.mozilla.javascript.tools.shell.Main.processFiles(Main.java:179)
        at org.mozilla.javascript.tools.shell.Main$IProxy.run(Main.java:100)
        at org.mozilla.javascript.Context.call(Context.java:499)
        at org.mozilla.javascript.ContextFactory.call(ContextFactory.java:511)
        at org.mozilla.javascript.tools.shell.Main.exec(Main.java:162)
        at org.mozilla.javascript.tools.shell.Main.main(Main.java:140)

Comment 1

10 years ago
Created attachment 326426 [details] [diff] [review]
Patch to apply on xmlimplsrc/org/mozilla/javascript/xmlimpl/XmlNode.java

Comment 2

10 years ago
I tried the patch and got this:

    [javac] Compiling 11 source files to /home/norris/rhino17/mozilla/js/rhino/build/classes
    [javac] /home/norris/rhino17/mozilla/js/rhino/xmlimplsrc/org/mozilla/javascript/xmlimpl/XmlNode.java:92: cannot find symbol
    [javac] symbol  : method getUri()
    [javac] location: class org.mozilla.javascript.xmlimpl.XmlNode.QName
    [javac]         if (qname.getUri().length() == 0)
    [javac]                  ^
    [javac] /home/norris/rhino17/mozilla/js/rhino/xmlimplsrc/org/mozilla/javascript/xmlimpl/XmlNode.java:94: cannot find symbol
    [javac] symbol  : method getUri()
    [javac] location: class org.mozilla.javascript.xmlimpl.XmlNode.QName
    [javac]         else e = document.createElementNS(qname.getUri(), qname.qualify(referenceDom));
    [javac]                                                ^
    [javac] 2 errors

Comment 3

10 years ago
Created attachment 327700 [details] [diff] [review]
Patch updated to apply on Rhino trunk
Attachment #326426 - Attachment is obsolete: true

Comment 4

10 years ago
Sorry about that, I created the patch against 1.7RC1 and didn't notice that some cleanup had been done on trunk since then. I've attached a new patch that should work on trunk.

Comment 5

10 years ago
Can someone have a look at this? I've updated the patch last time.

Comment 6

10 years ago
I'll take a look.
Ever confirmed: true

Comment 7

10 years ago
I patched in the change (here's my context diff, with minor formatting changes):

RCS file: /cvsroot/mozilla/js/rhino/xmlimplsrc/org/mozilla/javascript/xmlimpl/XmlNode.java,v
retrieving revision 1.10
diff -u -r1.10 XmlNode.java
--- xmlimplsrc/org/mozilla/javascript/xmlimpl/XmlNode.java      2 Jul 2008 18:16:35 -0000       1.10
+++ xmlimplsrc/org/mozilla/javascript/xmlimpl/XmlNode.java      20 Aug 2008 18:17:37 -0000
@@ -94,7 +94,15 @@
             document = processor.newDocument();
         Node referenceDom = (reference != null) ? reference.dom : null;
-        Element e = document.createElementNS(qname.getNamespace().getUri(), qname.qualify(referenceDom));
+        Element e;
+        if (qname.getNamespace() == null ||
+            qname.getNamespace().getUri().length() == 0)
+        {
+            e = document.createElement(qname.getLocalName());
+        } else {
+            e = document.createElementNS(qname.getNamespace().getUri(),
+                qname.qualify(referenceDom));
+        }
         if (value != null) {

The following tests start failing after making the change:


Comment 8

10 years ago
Ah sorry, I didn't where the tests were before. Thanks for checking this, it looks like I'll have to do another deep dive in that code.

Comment 9

10 years ago
I think I've found the problem and fixed my patch. Sorry about the back and forth, XML namespaces are a real pain in the neck. I'd like to try the tests on it but don't know which bug list you typically use. Do you always test with all the 2618? Seems to be taking a looong time... :)

Anyway I'll attach my patch still but if you could let me know what you usually run for the tests, that'd be great.

Comment 10

10 years ago
Created attachment 335044 [details] [diff] [review]
Same as previous but forces empty NS instead of no NS
Attachment #327700 - Attachment is obsolete: true

Comment 11

10 years ago
I'll run them locally and let you know if there are any regressions.

Comment 12

10 years ago
That passed. I've committed the change:

Checking in xmlimplsrc/org/mozilla/javascript/xmlimpl/XmlNode.java;
/cvsroot/mozilla/js/rhino/xmlimplsrc/org/mozilla/javascript/xmlimpl/XmlNode.java,v  <--  XmlNode.java
new revision: 1.11; previous revision: 1.10

Checking in testsrc/doctests/441417.doctest;
/cvsroot/mozilla/js/rhino/testsrc/doctests/441417.doctest,v  <--  441417.doctest
initial revision: 1.1
Last Resolved: 10 years ago
Resolution: --- → FIXED

Comment 13

10 years ago
Perfect, thanks!
You need to log in before you can comment on or make changes to this bug.