castor
  1. castor
  2. CASTOR-1905

xs:documentation string ending in * (asterix) causes ArrayIndexOutOfBoundsException in BaseFactory.normalize()

    Details

    • Type: Bug Bug
    • Status: Closed Closed
    • Priority: Minor Minor
    • Resolution: Fixed
    • Affects Version/s: 1.1
    • Fix Version/s: 1.1.1
    • Component/s: XML code generator
    • Labels:
      None
    • Number of attachments :
      2

      Description

      (/castor/trunk/codegen/src/main/java/org/exolab/castor/builder/BaseFactory.java)
      xs:documentation string ending in * causes ArrayIndexOutOfBoundsException in BaseFactory.normalize() line 103 rev 6807 - however i believe the offending line is 112, where when an asterix is found a check for '/' is made by looking at the next char in the array without checking if it's at the end of the array already.

      If you have an xsd annotation like the one below in your xsd it will trigger an ArrayIndexOutOfBoundsException when you try to generate source:

      <xs:annotation>
      <xs:documentation>Accommodation rating, e.g. 3*, 5*</xs:documentation>
      </xs:annotation>

      which causes the following stack trace output:

      Caused by: java.lang.ArrayIndexOutOfBoundsException: 33
      at org.exolab.castor.builder.BaseFactory.normalize(BaseFactory.java:103)
      at org.exolab.castor.builder.SourceFactory.processAnnotations(SourceFactory.java:1516)
      at org.exolab.castor.builder.SourceFactory.createSourceCode(SourceFactory.java:771)
      at org.exolab.castor.builder.SourceFactory.processAttributes(SourceFactory.java:1584)
      at org.exolab.castor.builder.SourceFactory.processComplexType(SourceFactory.java:1715)
      at org.exolab.castor.builder.SourceFactory.processComplexType(SourceFactory.java:646)
      at org.exolab.castor.builder.SourceFactory.createSourceCode(SourceFactory.java:342)
      at org.exolab.castor.builder.SourceGenerator.processComplexType(SourceGenerator.java:899)
      at org.exolab.castor.builder.SourceGenerator.generateAllClassFiles(SourceGenerator.java:694)
      at org.exolab.castor.builder.SourceGenerator.generateSource(SourceGenerator.java:655)
      at org.exolab.castor.builder.SourceGenerator.generateSource(SourceGenerator.java:598)
      at org.exolab.castor.builder.SourceGenerator.generateSource(SourceGenerator.java:503)
      at com.xmltravel.taskdefs.CastorSourceGenerator.compile(Unknown Source)

      if you add a space to the end of the string it works fine:

      <xs:annotation>
      <xs:documentation>Accommodation rating, e.g. 3*, 5* </xs:documentation>
      </xs:annotation>

      1. patch.c1905.20070314.txt
        0.6 kB
        Werner Guttmann
      2. testbug.xsd
        0.5 kB
        Simon Lord

        Issue Links

          Activity

          Hide
          Werner Guttmann added a comment -

          Just tried to reproduce this against SVN trunk, but failed to do so. Can you please attach a sample XML schema that fails for you at code generation ?

          Show
          Werner Guttmann added a comment - Just tried to reproduce this against SVN trunk, but failed to do so. Can you please attach a sample XML schema that fails for you at code generation ?
          Hide
          Werner Guttmann added a comment -

          This is the XML schema I used:

          <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
          xmlns:ns1="http://www.fpml.org/2004/FpML-4-1"
          xmlns:dsig="http://www.w3.org/2000/09/xmldsig#"
          xmlns="http://www.fpml.org/2003/FpML-4-0"
          targetNamespace="http://www.fpml.org/2003/FpML-4-0"
          elementFormDefault="qualified" attributeFormDefault="unqualified">

          <xsd:element name="eventDate" type="xsd:date">
          <xsd:annotation>
          <xsd:documentation>Accommodation rating, e.g. 3*, 5*</xsd:documentation>
          </xsd:annotation>
          </xsd:element>
          </xsd:schema>

          Show
          Werner Guttmann added a comment - This is the XML schema I used: <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:ns1="http://www.fpml.org/2004/FpML-4-1" xmlns:dsig="http://www.w3.org/2000/09/xmldsig#" xmlns="http://www.fpml.org/2003/FpML-4-0" targetNamespace="http://www.fpml.org/2003/FpML-4-0" elementFormDefault="qualified" attributeFormDefault="unqualified"> <xsd:element name="eventDate" type="xsd:date"> <xsd:annotation> <xsd:documentation>Accommodation rating, e.g. 3*, 5*</xsd:documentation> </xsd:annotation> </xsd:element> </xsd:schema>
          Hide
          Werner Guttmann added a comment -

          Simon, any ideas ?

          Show
          Werner Guttmann added a comment - Simon, any ideas ?
          Hide
          Simon Lord added a comment -

          Hi Werner, didn't realize i'd get a reply quite so quickly!

          Using the schema below should recreate the bug:

          <?xml version="1.0" encoding="UTF-8"?>
          <xs:schema xmlns="http://www.xmltravel.com/fab/2002/09" xmlns:xs="http://www.w3.org/2001/XMLSchema" version="1.18">

          <xs:simpleType name="AccommodationClassCode">
          <xs:annotation>
          <xs:documentation>Code indicating the quality of an Accommodation, e.g. 3*, 5*</xs:documentation>
          </xs:annotation>
          <xs:restriction base="xs:string">
          <xs:enumeration value="X"/>
          <xs:enumeration value="Y"/>
          </xs:restriction>
          </xs:simpleType>
          </xs:schema>

          what is interesting to note is that if you change the restriction block from:

          <xs:restriction base="xs:string">
          <xs:enumeration value="X"/>
          <xs:enumeration value="Y"/>
          </xs:restriction>

          to this: <xs:restriction base="xs:string"/> it will work!!

          So it's my fault for not providing enough info to start with...sorry But hopefully now you can recreate it.

          Thank you for your time

          Si

          Show
          Simon Lord added a comment - Hi Werner, didn't realize i'd get a reply quite so quickly! Using the schema below should recreate the bug: <?xml version="1.0" encoding="UTF-8"?> <xs:schema xmlns="http://www.xmltravel.com/fab/2002/09" xmlns:xs="http://www.w3.org/2001/XMLSchema" version="1.18"> <xs:simpleType name="AccommodationClassCode"> <xs:annotation> <xs:documentation>Code indicating the quality of an Accommodation, e.g. 3*, 5*</xs:documentation> </xs:annotation> <xs:restriction base="xs:string"> <xs:enumeration value="X"/> <xs:enumeration value="Y"/> </xs:restriction> </xs:simpleType> </xs:schema> what is interesting to note is that if you change the restriction block from: <xs:restriction base="xs:string"> <xs:enumeration value="X"/> <xs:enumeration value="Y"/> </xs:restriction> to this: <xs:restriction base="xs:string"/> it will work!! So it's my fault for not providing enough info to start with...sorry But hopefully now you can recreate it. Thank you for your time Si
          Hide
          Simon Lord added a comment -

          This schema should recreate the bug

          Show
          Simon Lord added a comment - This schema should recreate the bug
          Hide
          Werner Guttmann added a comment -

          As indicated by the user.

          Show
          Werner Guttmann added a comment - As indicated by the user.
          Hide
          Werner Guttmann added a comment -

          Final patch for review.

          Show
          Werner Guttmann added a comment - Final patch for review.

            People

            • Assignee:
              Werner Guttmann
              Reporter:
              Simon Lord
            • Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: