Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8145039

JAXB marshaller fails with ClassCastException on classes generated by xjc

XMLWordPrintable

    • b112
    • Not verified

        XJC generates incorrectly annotation @XmlSchemaType for types like:
            <!-- Simple type list -->
            <xsd:simpleType name="LongList">
                <xsd:list>
                    <xsd:simpleType>
                        <xsd:restriction base="xsd:unsignedInt"/>
                    </xsd:simpleType>
                </xsd:list>
            </xsd:simpleType>
            <!--- Complex test type -->
            <xsd:element name="typesLongList">
                <xsd:complexType>
                    <xsd:sequence>
                        <xsd:element name="in" type="tns:LongList"/>
                    </xsd:sequence>
                </xsd:complexType>
            </xsd:element>

        Follow-up marshalling of incorrectly generated classes triggers ClassCastException at runtime:
        java.lang.ClassCastException: java.lang.Long cannot be cast to java.lang.String
                at com.sun.xml.internal.bind.v2.model.impl.RuntimeBuiltinLeafInfoImpl$StringImplImpl.print(RuntimeBuiltinLeafInfoImpl.java:1034)
                at com.sun.xml.internal.bind.v2.runtime.reflect.ListTransducedAccessorImpl.print(ListTransducedAccessorImpl.java:103)
                at com.sun.xml.internal.bind.v2.runtime.reflect.DefaultTransducedAccessor.writeLeafElement(DefaultTransducedAccessor.java:54)
                at com.sun.xml.internal.bind.v2.runtime.property.ListElementProperty.serializeBody(ListElementProperty.java:107)
                at com.sun.xml.internal.bind.v2.runtime.ClassBeanInfoImpl.serializeBody(ClassBeanInfoImpl.java:345)
                at com.sun.xml.internal.bind.v2.runtime.XMLSerializer.childAsSoleContent(XMLSerializer.java:578)
                at com.sun.xml.internal.bind.v2.runtime.ClassBeanInfoImpl.serializeRoot(ClassBeanInfoImpl.java:326)
                at com.sun.xml.internal.bind.v2.runtime.XMLSerializer.childAsRoot(XMLSerializer.java:479)
                at com.sun.xml.internal.bind.v2.runtime.MarshallerImpl.write(MarshallerImpl.java:313)
                at com.sun.xml.internal.bind.v2.runtime.MarshallerImpl.marshal(MarshallerImpl.java:241)
                at javax.xml.bind.helpers.AbstractMarshallerImpl.marshal(AbstractMarshallerImpl.java:95)

              aefimov Aleksej Efimov
              shadowbug Shadow Bug
              Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

                Created:
                Updated:
                Resolved: