Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-6771547

SynthParser throws StringIndexOutOfBoundsException parsing custom ColorTypes

    Details

    • Subcomponent:
    • Resolved In Build:
      b03
    • CPU:
      x86
    • OS:
      solaris_2.5.1
    • Verification:
      Verified

      Backports

        Description

        FULL PRODUCT VERSION :
        java version "1.6.0_10-rc2"
        Java(TM) SE Runtime Environment (build 1.6.0_10-rc2-b32)
        Java HotSpot(TM) Server VM (build 11.0-b15, mixed mode)


        ADDITIONAL OS VERSION INFORMATION :
        Linux fred 2.6.18-78.el5 #1 SMP Tue Feb 5 18:28:41 EST 2008 i686 i686 i386 GNU/Linux

        A DESCRIPTION OF THE PROBLEM :
        I try to use a custom ColorType in my configuration file for the SynthLookAndFeel. So instead of using "FOREGROUND" or "BACKGRUND" as type in the color declaration of the xml file i specify the complete path to a class and field like described in the Synth File Format specification. Initializing the SynthLookAndFeeld now leads to an StringIndexOutOfBoundsException in line 649 of class SynthParser.
        It seems like the author of that class thought the second argument of the method String.substring(int,int) is treatet like the length of the substrng. Instead of this it should be the end index of the string.

        STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
        Run the attached example an see what happens...

        EXPECTED VERSUS ACTUAL BEHAVIOR :
        EXPECTED -
        no exception
        ACTUAL -
        an exception occurs

        ERROR MESSAGES/STACK TRACES THAT OCCUR :
        Exception in thread "main" java.lang.StringIndexOutOfBoundsException: String index out of range: -23
        at java.lang.String.substring(String.java:1938)
        at javax.swing.plaf.synth.SynthParser.startColor(SynthParser.java:649)
        at javax.swing.plaf.synth.SynthParser.startElement(SynthParser.java:1179)
        at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.startElement(AbstractSAXParser.java:453)
        at com.sun.org.apache.xerces.internal.parsers.AbstractXMLDocumentParser.emptyElement(AbstractXMLDocumentParser.java:179)
        at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanStartElement(XMLDocumentFragmentScannerImpl.java:1339)
        at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.next(XMLDocumentFragmentScannerImpl.java:2747)
        at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(XMLDocumentScannerImpl.java:648)
        at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:510)
        at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:807)
        at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:737)
        at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:107)
        at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:1205)
        at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(SAXParserImpl.java:522)
        at javax.xml.parsers.SAXParser.parse(SAXParser.java:364)
        at javax.xml.parsers.SAXParser.parse(SAXParser.java:142)
        at javax.swing.plaf.synth.SynthParser.parse(SynthParser.java:225)
        at javax.swing.plaf.synth.SynthLookAndFeel.load(SynthLookAndFeel.java:590)


        REPRODUCIBILITY :
        This bug can be reproduced always.

        ---------- BEGIN SOURCE ----------
        --- file test/gui/synthconfig.xml ---
        <synth>
        <style id="button">
            <color value="#CAFEBA" type="javax.swing.plaf.synth.ColorType.FOREGROUND"/>
        </style>
          <bind style="button" type="region" key="Button"/>
        </synth>
        --- end of file ---

        --- class test.gui.SynthTest ---
        package test.gui;

        import java.io.InputStream;
        import javax.swing.plaf.synth.SynthLookAndFeel;

        public class SynthTest {

        public static void main(String[] args) throws Exception{
        SynthLookAndFeel laf = new SynthLookAndFeel();
        InputStream in = SynthTest2.class.getResourceAsStream("/test/gui/synthconfig.xml");
        laf.load(in, SynthTest2.class);
        }
        }
        --- end of class ---
        ---------- END SOURCE ----------

        CUSTOMER SUBMITTED WORKAROUND :
        no known workaround

          Attachments

            Issue Links

              Activity

                People

                • Assignee:
                  alexp Alexander Potochkin (Inactive)
                  Reporter:
                  ndcosta Nelson Dcosta
                • Votes:
                  0 Vote for this issue
                  Watchers:
                  0 Start watching this issue

                  Dates

                  • Created:
                    Updated:
                    Resolved:
                    Imported:
                    Indexed: