Issue Details (XML | Word | Printable)

Key: JAXB-918
Type: Bug Bug
Status: In Progress In Progress
Priority: Major Major
Assignee: Iaroslav Savytskyi
Reporter: ratoo
Votes: 0
Watchers: 0

If you were logged in you would be able to see more operations.

Wrong element name serialized.

Created: 05/Sep/12 02:50 PM   Updated: 16/Sep/13 03:47 PM
Component/s: runtime
Affects Version/s: 2.2.5
Fix Version/s: None

Time Tracking:
Not Specified

File Attachments: 1. Zip Archive (16 kB) 16/Sep/13 03:47 PM - Martin Grebac


JDK6u35, JDK7u7 Win7 64

Participants: Iaroslav Savytskyi and ratoo

 Description  « Hide

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; }

Iaroslav Savytskyi added a comment - 24/Jan/13 04:09 PM


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


ratoo added a comment - 24/Jan/13 04:46 PM

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.



ratoo added a comment - 17/May/13 02:14 PM - edited


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="") 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.