JiBX
  1. JiBX
  2. JIBX-169

Binding compile of two classes with same element name fails with NPE in NameAttributes.equals although output only

    Details

    • Type: Bug Bug
    • Status: Closed Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: JiBX 1.1.5
    • Fix Version/s: JiBX 1.1.6
    • Component/s: core
    • Labels:
      None
    • Environment:
      Windows XP, Java 1.5.0_10
    • Number of attachments :
      1

      Description

      Just tried upgrading to JIBX 1.1.5 from 1.0.1 and hit this problem.

      I have a binding that is direction="output" and I have three hibernate classes that map to the same element name.

      When I try to bind compile, there is an exception thrown because the equals method in NameAttributes, when the name is the same, resorts to the namespace to distinguish the two objects, but the namespace has not been set on either of them.

      [java] Error running binding compiler
      [java] java.lang.NullPointerException
      [java] at org.jibx.binding.model.NameAttributes.equals(NameAttributes.java:184)
      [java] at java.util.HashMap.eq(HashMap.java:299)
      [java] at java.util.HashMap.containsKey(HashMap.java:381)
      [java] at org.jibx.binding.model.DefinitionContext.addMappedName(DefinitionContext.java:551)
      [java] at org.jibx.binding.model.RegistrationVisitor.visit(RegistrationVisitor.java:183)
      [java] at org.jibx.binding.model.TreeContext.tourTree(TreeContext.java:171)
      [java] at org.jibx.binding.model.TreeContext.tourTree(TreeContext.java:232)
      [java] at org.jibx.binding.model.RegistrationVisitor.visitTree(RegistrationVisitor.java:96)
      [java] at org.jibx.binding.model.BindingElement.runValidation(BindingElement.java:755)
      [java] at org.jibx.binding.model.BindingElement.validateBinding(BindingElement.java:819)
      [java] at org.jibx.binding.Utility.validateBinding(Utility.java:228)
      [java] at org.jibx.binding.Utility.loadBinding(Utility.java:269)
      [java] at org.jibx.binding.Utility.loadFileBinding(Utility.java:413)
      [java] at org.jibx.binding.Compile.compile(Compile.java:296)
      [java] at org.jibx.binding.Compile.main(Compile.java:385)

      I understand that it is not possible to unmarshal an incoming element to one of multiple classes, since there is not enough information to figure out which class to instantiate. But it would be useful to be able to marshal multiple classes to the same element name.

      The attached code has a target outputIssue that causes the exception

        Activity

        Hide
        Ingo Wilken added a comment -

        I have the same problem, but I'm not restricted to marshalling.

        Basically, I have a small 'control' file containing some metadata and a related (possibly very large)
        'data' file, both using the same element name. Most important, the control file contains the path
        to the data file.

        <binding value-style="attribute">
        <mapping name="foo" class="FooControl">
        <value name="path" field="pathToData"/>
        </mapping>

        <mapping name="foo" class="FooData">
        <!-- lots of stuff here -->
        </mapping>
        </binding>

        A server application feeds control files to my program, and using the contained path my program knows where to
        find the real data. So when I read/write an XML file, I know exactly what class to unmarshal to/marshal from, and
        simply use two IBindingFactory instances to read and write both kind of files:
        IBindingFactory controlFactory = BindingDirectory.getFactory(FooControl.class);
        IBindingFactory dataFactory = BindingDirectory.getFactory(FooData.class);

        This works great with JiBX 1.0.2.

        1.1.3 complains:

        Error: Duplicate mapping name not allowed for unmarshalling; on mapping element at (line 6, col 37, in binding.xml)
        Error running binding compiler
        org.jibx.runtime.JiBXException: Binding binding.xml is unusable because of validation errors
        at org.jibx.binding.Utility.loadBinding(Utility.java:346)
        at org.jibx.binding.Utility.loadFileBinding(Utility.java:413)
        at org.jibx.binding.Compile.compile(Compile.java:296)
        at org.jibx.binding.Compile.main(Compile.java:385)

        1.1.5 fails with the NullPointerException from the original bug report.

        Show
        Ingo Wilken added a comment - I have the same problem, but I'm not restricted to marshalling. Basically, I have a small 'control' file containing some metadata and a related (possibly very large) 'data' file, both using the same element name. Most important, the control file contains the path to the data file. <binding value-style="attribute"> <mapping name="foo" class="FooControl"> <value name="path" field="pathToData"/> </mapping> <mapping name="foo" class="FooData"> <!-- lots of stuff here --> </mapping> </binding> A server application feeds control files to my program, and using the contained path my program knows where to find the real data. So when I read/write an XML file, I know exactly what class to unmarshal to/marshal from, and simply use two IBindingFactory instances to read and write both kind of files: IBindingFactory controlFactory = BindingDirectory.getFactory(FooControl.class); IBindingFactory dataFactory = BindingDirectory.getFactory(FooData.class); This works great with JiBX 1.0.2. 1.1.3 complains: Error: Duplicate mapping name not allowed for unmarshalling; on mapping element at (line 6, col 37, in binding.xml) Error running binding compiler org.jibx.runtime.JiBXException: Binding binding.xml is unusable because of validation errors at org.jibx.binding.Utility.loadBinding(Utility.java:346) at org.jibx.binding.Utility.loadFileBinding(Utility.java:413) at org.jibx.binding.Compile.compile(Compile.java:296) at org.jibx.binding.Compile.main(Compile.java:385) 1.1.5 fails with the NullPointerException from the original bug report.
        Hide
        Deepak Pant added a comment -

        This is failing for me as well.

        I have been using JIBX Beta 3a in Production for over 2 years without any issues.

        I tried upgrading to 1.1.5 and am facing this error. I downgraded to 1.1 and it works for me.

        Let me know if any stack trace or testing effort etc is needed.

        Show
        Deepak Pant added a comment - This is failing for me as well. I have been using JIBX Beta 3a in Production for over 2 years without any issues. I tried upgrading to 1.1.5 and am facing this error. I downgraded to 1.1 and it works for me. Let me know if any stack trace or testing effort etc is needed.
        Hide
        Dennis Sosnoski added a comment -

        I've verified that the supplied binding compiles with the current CVS code, after some earlier fixes to the name handling. The test program fails when it tries to create an unmarshaller for the output-only binding (and I've also corrected the error message for this case, which previously had marshaller and unmarshaller reversed).

        The problem reported by Ingo Wilken is not really an issue, since the JiBX unmarshalling code correctly requires distinct names for each concrete <mapping> definition. I don't know how this ever could have worked with 1.0.2, but the only way to define multiple <mappings> with the same name now is to use separate binding definitions. If you split your current binding into two, and compile them in a single execution of the binding compiler, that should work.

        Show
        Dennis Sosnoski added a comment - I've verified that the supplied binding compiles with the current CVS code, after some earlier fixes to the name handling. The test program fails when it tries to create an unmarshaller for the output-only binding (and I've also corrected the error message for this case, which previously had marshaller and unmarshaller reversed). The problem reported by Ingo Wilken is not really an issue, since the JiBX unmarshalling code correctly requires distinct names for each concrete <mapping> definition. I don't know how this ever could have worked with 1.0.2, but the only way to define multiple <mappings> with the same name now is to use separate binding definitions. If you split your current binding into two, and compile them in a single execution of the binding compiler, that should work.
        Dennis Sosnoski made changes -
        Field Original Value New Value
        Fix Version/s JiBX 1.1.6 [ 14068 ]
        Resolution Fixed [ 1 ]
        Assignee Dennis Sosnoski [ dsosnoski ]
        Status Open [ 1 ] Resolved [ 5 ]
        Dennis Sosnoski made changes -
        Status Resolved [ 5 ] Closed [ 6 ]

          People

          • Assignee:
            Dennis Sosnoski
            Reporter:
            Andrew Harris
          • Votes:
            3 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: