Skip to main content

I think I have found a bug in JAXP

2 replies [Last post]
gkacy
Offline
Joined: 2005-12-14
Points: 0

I think I have found a bug in JAXP

Look at the to classes below and a simple test program

<br />
@XmlRootElement<br />
  @XmlType(name="ClassA", propOrder={<br />
  "sAOne",<br />
  "sATwo"})<br />
  public static class ClassA {</p>
<p>    private String sAOne;<br />
    private String sATwo;</p>
<p>    @XmlElement<br />
    public String getSAOne() {<br />
      return sAOne;<br />
    }</p>
<p>    public void setSAOne(String s) {<br />
      this.sAOne = s;<br />
    }</p>
<p>    @XmlElement<br />
    public String getSATwo() {<br />
      return sATwo;<br />
    }</p>
<p>    public void setSATwo(String s) {<br />
      this.sATwo = s;<br />
    }<br />
  }<br />

When marshalled to xml this class gives an exception:

<br />
Property SAOne is present but not specified in @XmlType.propOrder<br />
	this problem is related to the following location:<br />
		at public java.lang.String com.zeugma.test.PlatformTestDriver$ClassA.getSAOne()<br />
		at com.zeugma.test.PlatformTestDriver$ClassA<br />
Property SATwo is present but not specified in @XmlType.propOrder<br />
	this problem is related to the following location:<br />
		at public java.lang.String com.zeugma.test.PlatformTestDriver$ClassA.getSATwo()<br />
		at com.zeugma.test.PlatformTestDriver$ClassA<br />
Property sAOne appears in @XmlType.propOrder, but no such property exists<br />
	this problem is related to the following location:<br />
		at com.zeugma.test.PlatformTestDriver$ClassA<br />
Property sATwo appears in @XmlType.propOrder, but no such property exists<br />
	this problem is related to the following location:<br />
		at com.zeugma.test.PlatformTestDriver$ClassA</p>
<p>	at com.sun.xml.internal.bind.v2.runtime.IllegalAnnotationsException$Builder.check(IllegalAnnotationsException.java:66)<br />
	at com.sun.xml.internal.bind.v2.runtime.JAXBContextImpl.getTypeInfoSet(JAXBContextImpl.java:361)<br />
	at com.sun.xml.internal.bind.v2.runtime.JAXBContextImpl.(JAXBContextImpl.java:217)<br />
	at com.sun.xml.internal.bind.v2.ContextFactory.createContext(ContextFactory.java:76)<br />
	at com.sun.xml.internal.bind.v2.ContextFactory.createContext(ContextFactory.java:55)<br />
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)<br />
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)<br />
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)<br />
	at java.lang.reflect.Method.invoke(Method.java:597)<br />
	at javax.xml.bind.ContextFinder.newInstance(ContextFinder.java:210)<br />
	at javax.xml.bind.ContextFinder.find(ContextFinder.java:381)<br />
	at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:574)<br />
	at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:522)<br />
	at com.zeugma.test.PlatformTestDriver.createContext(PlatformTestDriver.java:222)<br />
	at com.zeugma.test.PlatformTestDriver.toXML(PlatformTestDriver.java:202)<br />
	at com.zeugma.test.PlatformTestDriver.propOrdertest(PlatformTestDriver.java:242)<br />
	at com.zeugma.test.PlatformTestDriver.main(PlatformTestDriver.java:255)<br />
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)<br />
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)<br />
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)<br />
ERROR<br />
	at java.lang.reflect.Method.invoke(Method.java:597)<br />
	at com.intellij.rt.execution.application.AppMain.main(AppMain.java:86)<br />

This is the test driver

</p>
<p> // output utility<br />
  public static String toXML(Object obj, Class ... clazzez) {<br />
    try {<br />
      JAXBContext jc = createContext(obj, clazzez);<br />
      Marshaller marshaller = jc.createMarshaller();<br />
      marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);</p>
<p>      StringWriter writer = new StringWriter();<br />
      marshaller.marshal(obj, writer);<br />
      return writer.toString();<br />
    } catch (JAXBException exc) {<br />
      exc.printStackTrace();<br />
      return "ERROR";<br />
    }<br />
  }</p>
<p>  public static JAXBContext createContext(Object obj, Class ... clazzez) throws JAXBException {<br />
    Class[] classes = new Class[clazzez.length + 1];</p>
<p>    classes[0] = obj.getClass();<br />
    for (int i = 0; i < clazzez.length; i++) {<br />
      classes[1 + i] = clazzez[i];<br />
    }<br />
    return JAXBContext.newInstance(classes);<br />
  }</p>
<p>  public static void propOrdertest() {</p>
<p>    ClassA a = new ClassA();<br />
    a.setSAOne("A1");<br />
    a.setSATwo("A2");</p>
<p>    System.out.println(toXML(a));</p>
<p>  }</p>
<p>

Now when the properties are named with additional "aa"s

<br />
@XmlRootElement<br />
  @XmlType(name="ClassA", propOrder={<br />
  "saaAOne",<br />
  "saaATwo"})<br />
  public static class ClassA {</p>
<p>    private String saaAOne;<br />
    private String saaATwo;</p>
<p>    @XmlElement<br />
    public String getSaaAOne() {<br />
      return saaAOne;<br />
    }</p>
<p>    public void setSaaAOne(String s) {<br />
      this.saaAOne = s;<br />
    }</p>
<p>    @XmlElement<br />
    public String getSaaATwo() {<br />
      return saaATwo;<br />
    }</p>
<p>    public void setSaaATwo(String s) {<br />
      this.saaATwo = s;<br />
    }<br />
  }</p>
<p> public static void propOrdertest() {</p>
<p>    ClassA a = new ClassA();<br />
    a.setSaaAOne("A1");<br />
    a.setSaaATwo("A2");</p>
<p>    System.out.println(toXML(a));</p>
<p>  }</p>
<p>

everything is correct and the output is:

</p>
<p><?xml version="1.0" encoding="UTF-8" standalone="yes"?></p>
<p>    A1<br />
    A2</p>
<p>

I think the fact that the property had a lowercase first letter followed by an uppercase with conjunction of using propOrder is cauing problems.

Also I should add that this exception will not show up in the first case if propOrder is not used.

Do you guys agree with me or I am missing something ?

Message was edited by: gkacy

Message was edited by: gkacy

Message was edited by: gkacy

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
joehw
Offline
Joined: 2004-12-15
Points: 0

Hi,

That's JAXB. You may want to file it using jaxb issue tracker.

Thanks.

gkacy
Offline
Joined: 2005-12-14
Points: 0

I am using

[code]
java version "1.6.0_02"
Java(TM) SE Runtime Environment (build 1.6.0_02-b06)
Java HotSpot(TM) Client VM (build 1.6.0_02-b06, mixed mode)
[/code]