jaxb
  1. jaxb
  2. JAXB-962

JAXBContext.newInstance fails when one schema uses a reference to another with: The element name ... has more than one mapping.

    Details

    • Type: Bug Bug
    • Status: Open
    • Priority: Major Major
    • Resolution: Unresolved
    • Affects Version/s: 2.2.4u2
    • Fix Version/s: None
    • Component/s: xjc
    • Labels:
      None
    • Environment:

      Oracle JDK 1.7.0_21, Ubuntu 12.04.2 LTS

      Description

      I have two XSD files, one referencing an element of another. I am compiling the two schemas separately using episodes and then try to instantiate a JAXBContext in order to unmarshall an XML file and I get the following exception:

      Caused by: javax.xml.bind.JAXBException: Provider com.sun.xml.bind.v2.ContextFactory could not
      be instantiated: com.sun.xml.bind.v2.runtime.IllegalAnnotationsException: 1 counts
      of IllegalAnnotationExceptions
      [java] The element name

      {http://www.example.org/A}

      someType has more than one mapping.

      Below is the smallest possible specimen that demonstrates this issue:

          • file A.xsd ***

      <?xml version="1.0" encoding="UTF-8"?>
      <schema elementFormDefault="qualified"
      xmlns ="http://www.w3.org/2001/XMLSchema"
      targetNamespace ="http://www.example.org/A">

      <element name="someType" type="string"></element>
      </schema>

          • file B.xsd ***

      <?xml version="1.0" encoding="UTF-8"?>
      <schema elementFormDefault="qualified"
      xmlns ="http://www.w3.org/2001/XMLSchema"
      xmlns:a ="http://www.example.org/A"
      xmlns:b ="http://www.example.org/B"
      targetNamespace="http://www.example.org/B"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">

      <import namespace="http://www.example.org/A" schemaLocation="A.xsd"/>

      <element name="root" type="b:RootType"></element>
      <complexType name="RootType">
      <sequence>
      <element ref="a:someType"/>
      </sequence>
      </complexType>
      </schema>

          • file b.xml ***

      <?xml version="1.0" encoding="UTF-8"?>
      <b:root xmlns:a="http://www.example.org/A"
      xmlns:b="http://www.example.org/B"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:schemaLocation="http://www.example.org/A A.xsd
      http://www.example.org/B B.xsd">
      <a:someType>foo</a:someType>
      </b:root>

          • excrepts from build.file that show XMLSchema compilation ***

      <property name="a.schema" value="A.xsd"/>
      <property name="a.schema.file" value="$

      {basedir}/${a.schema}"/>
      <property name="a.schema.package" value="example.a"/>
      <property name="a.dir" value="${src.dir}/example/a"/>
      <property name="a.schema.episode" value="${a.schema.package}.episode"/>

      <property name="b.schema" value="B.xsd"/>
      <property name="b.schema.file" value="${basedir}

      /$

      {b.schema}"/>
      <property name="b.schema.package" value="example.b"/>
      <property name="b.dir" value="${src.dir}/example/b"/>

      <target name="jaxb-generate-a">
      <mkdir dir="${a.dir}"/>
      <xjc schema="${a.schema.file}" destdir="${src.dir}" package="${a.schema.package}" extension="true">
      <arg value="-npa"/>
      <arg value="-episode"/>
      <arg value="${a.schema.episode}"/>
      <depends dir="${basedir}">
      <include name="${a.schema}"/>
      </depends>
      <produces dir="${a.dir}">
      <include name="*.java"/>
      </produces>
      </xjc>
      </target>

      <target name="jaxb-generate-b" depends="jaxb-generate-a">
      <mkdir dir="${b.dir}"/>
      <xjc schema="${b.schema.file}" destdir="${src.dir}" package="${b.schema.package}" extension="true">
      <arg value="-npa"/>
      <arg value="-b"/>
      <arg value="${a.schema.episode}"/>
      <depends dir="${basedir}">
      <include name="${b.schema}

      "/>
      </depends>
      <produces dir="$

      {b.dir}

      ">
      <include name="*.java"/>
      </produces>
      </xjc>
      </target>

          • Java code ***

      import java.io.*;
      import java.util.List;
      import java.math.BigDecimal;
      import javax.xml.bind.JAXBContext;
      import javax.xml.bind.JAXBException;
      import javax.xml.bind.Marshaller;
      import javax.xml.bind.JAXBElement;
      import javax.xml.bind.Unmarshaller;

      import example.a.*;
      import example.b.*;

      public class FooMain {

      public static void main (String args[]) throws JAXBException, FileNotFoundException

      { JAXBContext jc = JAXBContext.newInstance( "example.a:example.b" ); Unmarshaller u = jc.createUnmarshaller(); JAXBElement<RootType> element = (JAXBElement<RootType>)u.unmarshal( new FileInputStream( "b.xml" ) ); }

      }

          • exception trace ***
            [java] javax.xml.bind.JAXBException: Provider com.sun.xml.bind.v2.ContextFactory could not be instantiated: com.sun.xml.bind.v2.runtime.IllegalAnnotationsException: 1 counts of IllegalAnnotationExceptions
            [java] The element name {http://www.example.org/A}

            someType has more than one mapping.
            [java] this problem is related to the following location:
            [java] at public javax.xml.bind.JAXBElement example.b.ObjectFactory.createSomeType(java.lang.String)
            [java] at example.b.ObjectFactory
            [java] this problem is related to the following location:
            [java] at public javax.xml.bind.JAXBElement example.a.ObjectFactory.createSomeType(java.lang.String)
            [java] at example.a.ObjectFactory
            [java]
            [java] - with linked exception:
            [java] [com.sun.xml.bind.v2.runtime.IllegalAnnotationsException: 1 counts of IllegalAnnotationExceptions
            [java] The element name

            {http://www.example.org/A}

            someType has more than one mapping.
            [java] this problem is related to the following location:
            [java] at public javax.xml.bind.JAXBElement example.b.ObjectFactory.createSomeType(java.lang.String)
            [java] at example.b.ObjectFactory
            [java] this problem is related to the following location:
            [java] at public javax.xml.bind.JAXBElement example.a.ObjectFactory.createSomeType(java.lang.String)
            [java] at example.a.ObjectFactory
            [java] ]
            [java] at org.apache.tools.ant.taskdefs.ExecuteJava.execute(ExecuteJava.java:194)
            [java] at org.apache.tools.ant.taskdefs.Java.run(Java.java:771)
            [java] at org.apache.tools.ant.taskdefs.Java.executeJava(Java.java:221)
            [java] at org.apache.tools.ant.taskdefs.Java.executeJava(Java.java:135)
            [java] at org.apache.tools.ant.taskdefs.Java.execute(Java.java:108)
            [java] at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:291)
            [java] at sun.reflect.GeneratedMethodAccessor4.invoke(Unknown Source)
            [java] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
            [java] at java.lang.reflect.Method.invoke(Method.java:601)
            [java] at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)
            [java] at org.apache.tools.ant.Task.perform(Task.java:348)
            [java] at org.apache.tools.ant.taskdefs.Sequential.execute(Sequential.java:68)
            [java] at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:291)
            [java] at sun.reflect.GeneratedMethodAccessor4.invoke(Unknown Source)
            [java] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
            [java] at java.lang.reflect.Method.invoke(Method.java:601)
            [java] at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)
            [java] at org.apache.tools.ant.Task.perform(Task.java:348)
            [java] at org.apache.tools.ant.taskdefs.MacroInstance.execute(MacroInstance.java:398)
            [java] at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:291)
            [java] at sun.reflect.GeneratedMethodAccessor4.invoke(Unknown Source)
            [java] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
            [java] at java.lang.reflect.Method.invoke(Method.java:601)
            [java] at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)
            [java] at org.apache.tools.ant.Task.perform(Task.java:348)
            [java] at org.apache.tools.ant.Target.execute(Target.java:390)
            [java] at org.apache.tools.ant.Target.performTasks(Target.java:411)
            [java] at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1399)
            [java] at org.apache.tools.ant.Project.executeTarget(Project.java:1368)
            [java] at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:41)
            [java] at org.apache.tools.ant.Project.executeTargets(Project.java:1251)
            [java] at org.apache.tools.ant.Main.runBuild(Main.java:809)
            [java] at org.apache.tools.ant.Main.startAnt(Main.java:217)
            [java] at org.apache.tools.ant.launch.Launcher.run(Launcher.java:280)
            [java] at org.apache.tools.ant.launch.Launcher.main(Launcher.java:109)
            [java] Caused by: javax.xml.bind.JAXBException: Provider com.sun.xml.bind.v2.ContextFactory could not be instantiated: com.sun.xml.bind.v2.runtime.IllegalAnnotationsException: 1 counts of IllegalAnnotationExceptions
            [java] The element name

            {http://www.example.org/A}

            someType has more than one mapping.
            [java] this problem is related to the following location:
            [java] at public javax.xml.bind.JAXBElement example.b.ObjectFactory.createSomeType(java.lang.String)
            [java] at example.b.ObjectFactory
            [java] this problem is related to the following location:
            [java] at public javax.xml.bind.JAXBElement example.a.ObjectFactory.createSomeType(java.lang.String)
            [java] at example.a.ObjectFactory
            [java]
            [java] - with linked exception:
            [java] [com.sun.xml.bind.v2.runtime.IllegalAnnotationsException: 1 counts of IllegalAnnotationExceptions
            [java] The element name

            {http://www.example.org/A}

            someType has more than one mapping.
            [java] this problem is related to the following location:
            [java] at public javax.xml.bind.JAXBElement example.b.ObjectFactory.createSomeType(java.lang.String)
            [java] at example.b.ObjectFactory
            [java] this problem is related to the following location:
            [java] at public javax.xml.bind.JAXBElement example.a.ObjectFactory.createSomeType(java.lang.String)
            [java] at example.a.ObjectFactory
            [java] ]
            [java] at javax.xml.bind.ContextFinder.newInstance(ContextFinder.java:146)
            [java] at javax.xml.bind.ContextFinder.find(ContextFinder.java:334)
            [java] at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:431)
            [java] at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:394)
            [java] at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:298)
            [java] at FooMain.main(FooMain.java:20)
            [java] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
            [java] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
            [java] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
            [java] at java.lang.reflect.Method.invoke(Method.java:601)
            [java] at org.apache.tools.ant.taskdefs.ExecuteJava.run(ExecuteJava.java:217)
            [java] at org.apache.tools.ant.taskdefs.ExecuteJava.execute(ExecuteJava.java:152)
            [java] ... 34 more
            [java] Caused by: com.sun.xml.bind.v2.runtime.IllegalAnnotationsException: 1 counts of IllegalAnnotationExceptions
            [java] The element name

            {http://www.example.org/A}

            someType has more than one mapping.
            [java] this problem is related to the following location:
            [java] at public javax.xml.bind.JAXBElement example.b.ObjectFactory.createSomeType(java.lang.String)
            [java] at example.b.ObjectFactory
            [java] this problem is related to the following location:
            [java] at public javax.xml.bind.JAXBElement example.a.ObjectFactory.createSomeType(java.lang.String)
            [java] at example.a.ObjectFactory
            [java]
            [java] at com.sun.xml.bind.v2.runtime.IllegalAnnotationsException$Builder.check(IllegalAnnotationsException.java:106)
            [java] at com.sun.xml.bind.v2.runtime.JAXBContextImpl.getTypeInfoSet(JAXBContextImpl.java:471)
            [java] at com.sun.xml.bind.v2.runtime.JAXBContextImpl.<init>(JAXBContextImpl.java:303)
            [java] at com.sun.xml.bind.v2.runtime.JAXBContextImpl.<init>(JAXBContextImpl.java:142)
            [java] at com.sun.xml.bind.v2.runtime.JAXBContextImpl$JAXBContextBuilder.build(JAXBContextImpl.java:1174)
            [java] at com.sun.xml.bind.v2.ContextFactory.createContext(ContextFactory.java:162)
            [java] at com.sun.xml.bind.v2.ContextFactory.createContext(ContextFactory.java:286)
            [java] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
            [java] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
            [java] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
            [java] at java.lang.reflect.Method.invoke(Method.java:601)
            [java] at javax.xml.bind.ContextFinder.newInstance(ContextFinder.java:172)
            [java] at javax.xml.bind.ContextFinder.newInstance(ContextFinder.java:132)
            [java] ... 45 more
            [java] Java Result: -1

        Activity

        Hide
        Phoenix_the_II added a comment -

        I'm having the same problem. Did you manage to work around this problem or?

        Show
        Phoenix_the_II added a comment - I'm having the same problem. Did you manage to work around this problem or?
        Hide
        Iaroslav Savytskyi added a comment -

        Hi,

        I've tried to reproduce the issue. The only difference I've made is that I've generated classes with xjc from command line.

        xjc a.xsd b.xsd

        and with a fresh JAXB I have no error.

        Can you please try to test the issue with JAXB 2.2.8-b01 (it's available on maven).

        Thanks.


        Iaroslav

        Show
        Iaroslav Savytskyi added a comment - Hi, I've tried to reproduce the issue. The only difference I've made is that I've generated classes with xjc from command line. xjc a.xsd b.xsd and with a fresh JAXB I have no error. Can you please try to test the issue with JAXB 2.2.8-b01 (it's available on maven). Thanks. – Iaroslav
        Hide
        Phoenix_the_II added a comment - - edited

        Same error shall I provide a complete zip file with a test case inside of it? And a download link?

        Will use original XSD's of third parties, they are opensource anyways so

        Show
        Phoenix_the_II added a comment - - edited Same error shall I provide a complete zip file with a test case inside of it? And a download link? Will use original XSD's of third parties, they are opensource anyways so
        Hide
        Phoenix_the_II added a comment -

        Ok here's the test case:

        https://dl.dropboxusercontent.com/u/3828392/jaxb-962.zip

        Just run the com.jaxb.Main class and you'll see the errors popup.

        Inside com.jaxb.schema.iisse is a build.sh this is used to compile the jaxb classes. Note that we both use episodes instead of a 1-liner xjc.

        Show
        Phoenix_the_II added a comment - Ok here's the test case: https://dl.dropboxusercontent.com/u/3828392/jaxb-962.zip Just run the com.jaxb.Main class and you'll see the errors popup. Inside com.jaxb.schema.iisse is a build.sh this is used to compile the jaxb classes. Note that we both use episodes instead of a 1-liner xjc.

          People

          • Assignee:
            Iaroslav Savytskyi
            Reporter:
            m_perdikeas
          • Votes:
            1 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated: