[ https://issues.apache.org/jira/browse/XMLBEANS-583?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17464532#comment-17464532 ]
Dmitry Lastochkin commented on XMLBEANS-583: -------------------------------------------- When I ran the test on XMLBeans 2.4, I was generating source code using XMLBeans 2.4. When I ran the test on XMLBeans 5.0.0, I was generating source code using XMLBeans 5.0.0. > Duplicated "xmlns" attribute in XmlObject.toString() result > ----------------------------------------------------------- > > Key: XMLBEANS-583 > URL: https://issues.apache.org/jira/browse/XMLBEANS-583 > Project: XMLBeans > Issue Type: Bug > Affects Versions: Version 5.0.0 > Reporter: Dmitry Lastochkin > Priority: Major > Fix For: Version 5.0.3 > > Attachments: schemas.zip > > > Hello! > I ran into the following problem: in some cases, {{XmlObject.toString()}} > returns an XML containing duplicated "xmlns" attribute, as shown bellow > {code:xml} > <Ns2E1 xmlns="XmlToStringTest2Xsd.xsd"> > <Ns2T1E1 xmlns="" xmlns="XmlToStringTest2Xsd.xsd"> > <Ns1T1E1 xmlns="XmlToStringTest1Xsd.xsd">Ns1T1E1</Ns1T1E1> > </Ns2T1E1> > </Ns2E1> > {code} > I wrote a simple test that reproduces the error (you can find test XSDs in > [^schemas.zip]): > {code:java} > public class XmlToStringTest { > @Test > public void test() { > try { > final Ns2E1Document ns2e1Doc = > Ns2E1Document.Factory.newInstance(); > ns2e1Doc.addNewNs2E1().addNewNs2T1E1().setNs1T1E1("Ns1T1E1"); > > final Ns3E1Document ns3e1Doc = > Ns3E1Document.Factory.newInstance(); > > ns3e1Doc.addNewNs3E1().setNs3T1E1(Ns1T1.Factory.parse(ns2e1Doc.getNs2E1().getNs2T1E1().toString())); > > final Ns3E1Document pNs3e1Doc = > Ns3E1Document.Factory.parse(ns3e1Doc.toString()); > final Ns2E1Document pNs2e1Doc = > Ns2E1Document.Factory.newInstance(); > > pNs2e1Doc.addNewNs2E1().setNs2T1E1(pNs3e1Doc.getNs3E1().getNs3T1E1()); > > System.out.println(pNs2e1Doc.toString()); > Ns2E1Document.Factory.parse(pNs2e1Doc.toString()); > } catch (Exception ex) { > ex.printStackTrace(); > Assert.fail(); > } > } > } > {code} > I investigated the problem and found the cause. In the {{Saver.tryPrefix()}} > I found the following comment: > {quote} > // If the prefix is currently mapped, then try another prefix. A > // special case is that of trying to map the default prefix (""). > // Here, there always exists a default mapping. If this is the > // mapping we found, then remap it anyways. *I use != to compare* > // strings because I want to test for the *specific* initial default > // uri I added when I initialized the saver. > {quote} > But the code following this comment looks like this: > {code:java} > return existingUri == null || (prefix.length() <= 0 && > Objects.equals(existingUri, _initialDefaultUri)); // Objects.equals, not == > {code} > > And {{_initialDefaultUri}} initialized like this: > {code:java} > _initialDefaultUri = ""; > {code} > But should be > {code:java} > _initialDefaultUri = new String(""); > {code} > because we talk about a *specific* value. > Hopefully this information helps fix this bug. -- This message was sent by Atlassian Jira (v8.20.1#820001) --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@poi.apache.org For additional commands, e-mail: dev-h...@poi.apache.org