[JAXB-918] Wrong element name serialized. Created: 05/Sep/12  Updated: 16/Sep/13

Status: In Progress
Project: jaxb
Component/s: runtime
Affects Version/s: 2.2.5
Fix Version/s: None

Type: Bug Priority: Major
Reporter: ratoo Assignee: Iaroslav Savytskyi
Resolution: Unresolved Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

JDK6u35, JDK7u7 Win7 64


Attachments: Zip Archive jaxb918.zip    

 Description   

There is a bug in com.sun.xml.bind.v2.runtime.output.NamespaceContextImpl

NamespaceContextImpl reuses NamespaceContextImpl.Element objects to generate prefixes.
NamespaceContextImpl.Element.setTagName(Name tagName, Object outerPeer) doesn't clean up NamespaceContextImpl.Element.elementLocalName
When the element is reused in
NamespaceContextImpl.declareNsUri(String uri, String preferedPrefix, boolean requirePrefix) {
...
if (current.elementLocalName!=null)

{ // CHANGES A NAME TO THOSE LEFT FROM AN OTHER NODE!!! current.setTagName(size, current.elementLocalName, current.getOuterPeer()); }

...
}

Solution is to clean elementLocalName in

public void setTagName( Name tagName, Object outerPeer ) {
assert tagName!=null;
this.elementName = tagName;
this.elementLocalName = null; // +
this.outerPeer = outerPeer;
}



 Comments   
Comment by Iaroslav Savytskyi [ 24/Jan/13 ]

Hi,

thank you for reporting. Can you please provide small test case how can I reproduce the problem.

Thanks.

Comment by ratoo [ 24/Jan/13 ]

Unfortunately I can't .
Things works to me now and I did too much changes to figure out what was wrong.

I had an adapter with a DOM Element returned.
Somehow JAXB is parsing this element tree using localNames.
IMHO it's obvious that either elementName or elementLocalName must be null.

Cheers,

D.

Comment by ratoo [ 17/May/13 ]

Hello,

I got the bug again and finally figured out what exactly happens.
I have a QName attribute.
When the default namespace is defined (i.e. xmlns="www.example.com") and
my QName attribute has no namespace,
NamespaceContextImpl tries to rearrange:

> 188 // first, if the previous URI assigned to "" is
> 189 // a "known URI", remember what we've reallocated
> 190 // so that we can fix it when this context pops.
...
> 202 if (current.elementLocalName!=null)

{ > 203 current.setTagName(size, current.elementLocalName, current.getOuterPeer()); > 204 }

here it changes the tag name (current).
setTagName has a bug - doesn't clean elementLocalName (as seen above).

P.S. can't find a way to submit jUnit test code.
https://java.net/projects/jaxb/lists/users/archive/2013-05/message/7

Generated at Sun Aug 02 09:07:35 UTC 2015 using JIRA 6.2.3#6260-sha1:63ef1d6dac3f4f4d7db4c1effd405ba38ccdc558.