Uploaded image for project: 'XMLBeans'
  1. XMLBeans
  2. XMLBEANS-111

Upper case conversion of special characters causes javac error

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Resolved
    • Minor
    • Resolution: Fixed
    • None
    • Version 2 Beta 2, Version 2
    • Compiler
    • None
    • Tested with UTF-8 encoding

    Description

      When a character has no Unicode upper case equivalent, and it is mapped to upper case by NameUtil.java, the conversion returns an invalid character. This causes the compilation of the generated classes to fail. A sample xsd that causes the error, the javac output, and diff of a suggested fix follow.

      Thanks - excellent program - saves tons of time over doing it the old-fashioned way!

      ----------------------------------------------

      Sample XSD that causes the error:

      <?xml version="1.0" encoding="UTF-8"?>
      <xs:schema
      elementFormDefault="qualified"
      attributeFormDefault="unqualified"
      xmlns:xs="http://www.w3.org/2001/XMLSchema">
      <xs:element name="Unit" type="unit_list"/>
      <xs:simpleType name="unit_list">
      <xs:restriction base="xs:string">
      <xs:enumeration value="g/dl"/>
      <xs:enumeration value="µg/dl"/>
      <xs:enumeration value="µg/L"/>
      <xs:enumeration value="g/ml"/>
      <xs:enumeration value="pg/µL"/>
      <xs:enumeration value="No unit"/>
      </xs:restriction>
      </xs:simpleType>
      </xs:schema>

      -------------------------------------------------

      Here's the error from javac after scomp:

      C:\>scomp -out test.jar test.xsd
      Time to build schema type system: 0.781 seconds
      Time to generate code: 0.081 seconds
      C:\..\Temp\xbean16323.d\src\noNamespace\UnitList.java:24: <identifier> expected
      static final Enum ?G_DL = Enum.forString("╡g/dl");
      ^
      C:\..\Temp\xbean16323.d\src\noNamespace\UnitList.java:24: = expected
      static final Enum ?G_DL = Enum.forString("╡g/dl");
      ^
      C:\..\Temp\xbean16323.d\src\noNamespace\UnitList.java:25: <identifier> expected
      static final Enum ?G_L = Enum.forString("╡g/L");
      ^
      C:\..\Temp\xbean16323.d\src\noNamespace\UnitList.java:25: = expected
      static final Enum ?G_L = Enum.forString("╡g/L");
      ^
      C:\..\Temp\xbean16323.d\src\noNamespace\UnitList.java:27: = expected
      static final Enum PG_?_L = Enum.forString("pg/╡L");
      ^
      C:\..\Temp\xbean16323.d\src\noNamespace\UnitList.java:31: = expected
      static final int INT_?G_DL = Enum.INT_?G_DL;
      ^
      C:\..\Temp\xbean16323.d\src\noNamespace\UnitList.java:32: = expected
      static final int INT_?G_L = Enum.INT_?G_L;
      ^
      C:\..\Temp\xbean16323.d\src\noNamespace\UnitList.java:34: = expected
      static final int INT_PG_?L = Enum.INT_PG?_L;
      ^
      C:\..\Temp\xbean16323.d\src\noNamespace\UnitList.java:69: ';' expected
      static final int INT_?G_DL = 2;
      ^
      C:\..\Temp\xbean16323.d\src\noNamespace\UnitList.java:70: ';' expected
      static final int INT_?G_L = 3;
      ^
      C:\..\Temp\xbean16323.d\src\noNamespace\UnitList.java:72: ';' expected
      static final int INT_PG_?_L = 5;
      ^
      C:\..\Temp\xbean16323.d\src\noNamespace\UnitList.java:81: : expected
      new Enum("╡g/dl", INT_?G_DL),
      ^
      C:\..\Temp\xbean16323.d\src\noNamespace\UnitList.java:86: illegal start of expression
      }
      ^
      13 errors

      BUILD FAILED

      -----------------------------------------------------------

      On my own copy of the XMLBeans source I've fixed the problem by altering NameUtil.java to check for a successful conversion to upper case, and replace any offending characters with underscores. In case it would be useful here's a diff of the changes:

      C:\WebsphereStuff\xmlbeans\source\trunk\src\common\org\apache\xmlbeans\impl\comm
      on>svn diff
      Index: NameUtil.java
      ===================================================================
      — NameUtil.java (revision 154882)
      +++ NameUtil.java (working copy)
      @@ -555,9 +555,8 @@
      for(int j = 0 ; j < len ; j++)

      { char c = buf.charAt(j); - buf.setCharAt(j, Character.toUpperCase(c)); - }

      -
      + buf.setCharAt(j, safeToUpperCase(c));
      + }
      return buf.toString();
      }

      @@ -638,7 +637,7 @@
      return s;

      StringBuffer buf = new StringBuffer(s);

      • buf.setCharAt(0, Character.toUpperCase(buf.charAt(0)));
        + buf.setCharAt(0, safeToUpperCase(buf.charAt(0)));
        return buf.toString();
        }

      @@ -776,4 +775,17 @@

      { return javaNames.contains(word); }

      +
      + public static char safeToUpperCase(char c) {
      + Character upperCaseC = new Character(Character.toUpperCase(c));
      + Character lowerCaseC = new Character(Character.toLowerCase(upperCaseC.charValue()));
      + if(!lowerCaseC.equals(new Character(c)))
      + //if we cannot get back to the lower case, then the character has no upper case form
      + //replace with underscore
      +

      { + upperCaseC = new Character(USCORE); + }

      + return upperCaseC.charValue();
      + }
      +
      }

      Attachments

        1. XMLBEANS-111.patch
          2 kB
          Radu Preotiuc

        Activity

          People

            radup Radu Preotiuc
            ivy Anne Marie Simmie
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: