JiBX
  1. JiBX
  2. JIBX-11

getNamedStructure returns null instead of throwing exception

    Details

    • Type: Bug Bug
    • Status: Closed Closed
    • Priority: Minor Minor
    • Resolution: Fixed
    • Affects Version/s: 1.0-beta3a
    • Fix Version/s: 1.0-RC2
    • Component/s: core
    • Labels:
      None
    • Number of attachments :
      0

      Description

      I think this mainly has to do with the using/label stuff which you are reworking. I was trying to troubleshoot a couple of issues with the xsd2jibx servlet example, but the NullPointerException that the JiBX binding compiler was throwing wasn't very helpful.

      DefinitionContent.java can be modified like so:

      From:

      public IComponent getNamedStructure(String name) throws JiBXException {

      // check for named component defined at this level
      if (m_namedStructureMap == null)

      { return m_context.getNamedStructure(name); }

      else

      { return (IComponent)m_namedStructureMap.get(name); }

      }

      To:

      public IComponent getNamedStructure(String name) throws JiBXException {
      IComponent icomponent = null;
      // check for named component defined at this level
      if (m_namedStructureMap == null)

      { icomponent = m_context.getNamedStructure(name); }

      else

      { icomponent = (IComponent)m_namedStructureMap.get(name); }

      if( icomponent == null )

      { throw new JiBXException( "Unable to get structure named: " + name ); }

      return icomponent;
      }

      Actually knowing what "using" reference was causing the problem helped me track down an xsd2jibx bug and is usefull when troubleshooting the binding compiler.

        Activity

        Hide
        Dennis Sosnoski added a comment -

        Yes, the code was definitely bad. I've changed it to check when it reaches the outermost context and throw an exception in this case. Let me know if you get a chance to confirm that this now works properly.

        Show
        Dennis Sosnoski added a comment - Yes, the code was definitely bad. I've changed it to check when it reaches the outermost context and throw an exception in this case. Let me know if you get a chance to confirm that this now works properly.
        Hide
        Cameron Taggart added a comment -

        The bug has been fixed. To test it out, I made some modifications to example1 (although they don't make much sense logically).

        <!-- uses using/label instead of map-as -->
        <binding>
        <mapping name="customer" class="example1.Customer">
        <!-- must add these fields within Customer -->
        <structure name="mother" using="example1.Person" field="mother"/>
        <structure name="father" using="examplePerson" field="father"/>
        <value name="street" field="street"/>
        <value name="city" field="city"/>
        <value name="state" field="state"/>
        <value name="zip" field="zip"/>
        <value name="phone" field="phone"/>
        </mapping>
        <mapping name="person" class="example1.Person" label="example1.Person">
        <value name="cust-num" field="customerNumber"/>
        <value name="first-name" field="firstName"/>
        <value name="last-name" field="lastName"/>
        </mapping>
        </binding>

        Throws this exception, which is what it should do:

        org.jibx.runtime.JiBXException: Referenced label "examplePerson" not defined
        at org.jibx.binding.def.DefinitionContext.getNamedStructure(DefinitionContext.java:366)
        at org.jibx.binding.def.DefinitionContext.getNamedStructure(DefinitionContext.java:369)
        at org.jibx.binding.def.DefinitionContext.getNamedStructure(DefinitionContext.java:369)
        at org.jibx.binding.def.StructureReference.setLinkages(StructureReference.java:111)
        at org.jibx.binding.def.ElementWrapper.setLinkages(ElementWrapper.java:443)
        at org.jibx.binding.def.NestedStructure.setLinkages(NestedStructure.java:219)
        at org.jibx.binding.def.PassThroughComponent.setLinkages(PassThroughComponent.java:140)
        at org.jibx.binding.def.ObjectBinding.setLinkages(ObjectBinding.java:752)
        at org.jibx.binding.def.ElementWrapper.setLinkages(ElementWrapper.java:443)
        at org.jibx.binding.def.MappingDefinition.setLinkages(MappingDefinition.java:678)
        at org.jibx.binding.def.DefinitionContext.setLinkages(DefinitionContext.java:624)
        at org.jibx.binding.def.BindingDefinition.generateCode(BindingDefinition.java:524)
        at org.jibx.binding.Compile.compile(Compile.java:283)
        at org.jibx.binding.Compile.main(Compile.java:341)

        Show
        Cameron Taggart added a comment - The bug has been fixed. To test it out, I made some modifications to example1 (although they don't make much sense logically). <!-- uses using/label instead of map-as --> <binding> <mapping name="customer" class="example1.Customer"> <!-- must add these fields within Customer --> <structure name="mother" using="example1.Person" field="mother"/> <structure name="father" using="examplePerson" field="father"/> <value name="street" field="street"/> <value name="city" field="city"/> <value name="state" field="state"/> <value name="zip" field="zip"/> <value name="phone" field="phone"/> </mapping> <mapping name="person" class="example1.Person" label="example1.Person"> <value name="cust-num" field="customerNumber"/> <value name="first-name" field="firstName"/> <value name="last-name" field="lastName"/> </mapping> </binding> Throws this exception, which is what it should do: org.jibx.runtime.JiBXException: Referenced label "examplePerson" not defined at org.jibx.binding.def.DefinitionContext.getNamedStructure(DefinitionContext.java:366) at org.jibx.binding.def.DefinitionContext.getNamedStructure(DefinitionContext.java:369) at org.jibx.binding.def.DefinitionContext.getNamedStructure(DefinitionContext.java:369) at org.jibx.binding.def.StructureReference.setLinkages(StructureReference.java:111) at org.jibx.binding.def.ElementWrapper.setLinkages(ElementWrapper.java:443) at org.jibx.binding.def.NestedStructure.setLinkages(NestedStructure.java:219) at org.jibx.binding.def.PassThroughComponent.setLinkages(PassThroughComponent.java:140) at org.jibx.binding.def.ObjectBinding.setLinkages(ObjectBinding.java:752) at org.jibx.binding.def.ElementWrapper.setLinkages(ElementWrapper.java:443) at org.jibx.binding.def.MappingDefinition.setLinkages(MappingDefinition.java:678) at org.jibx.binding.def.DefinitionContext.setLinkages(DefinitionContext.java:624) at org.jibx.binding.def.BindingDefinition.generateCode(BindingDefinition.java:524) at org.jibx.binding.Compile.compile(Compile.java:283) at org.jibx.binding.Compile.main(Compile.java:341)

          People

          • Assignee:
            Dennis Sosnoski
            Reporter:
            Cameron Taggart
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: