JDK-6771547 : SynthParser throws StringIndexOutOfBoundsException parsing custom ColorTypes
  • Type: Bug
  • Component: client-libs
  • Sub-Component: javax.swing
  • Affected Version: 6u10
  • Priority: P4
  • Status: Closed
  • Resolution: Fixed
  • OS: solaris_2.5.1
  • CPU: x86
  • Submitted: 2008-11-14
  • Updated: 2011-02-16
  • Resolved: 2010-01-13
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 6 JDK 7
6u18 b03Fixed 7Fixed
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

Comments
EVALUATION the fix description mentioned in the description seem to make sense
18-09-2009