JDK-6240963 : XSLT transforms broken in Turkish locale in JDK 1.5.0+
  • Type: Bug
  • Component: xml
  • Sub-Component: javax.xml.transform
  • Affected Version: 5.0
  • Priority: P2
  • Status: Resolved
  • Resolution: Fixed
  • OS: linux
  • CPU: x86
  • Submitted: 2005-03-15
  • Updated: 2012-04-24
  • Resolved: 2005-07-21
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.
Other
1.4.0 6.0Fixed
Related Reports
Relates :  
Description
Compile and run the following program, a bare-bones usage of XSLT transforms:

---%<---
import java.io.StringReader;
import java.util.Locale;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.transform.Source;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;
import javax.xml.transform.stream.StreamSource;
import org.w3c.dom.Document;
public class TestTurkishXSLT {
    public static void main(String[] args) throws Exception {
        Locale.setDefault(new Locale("tr", "TR"));
        String xslt =
            "<xsl:stylesheet version='1.0' xmlns:xsl='http://www.w3.org/1999/XSL/Transform'>\n" +
            "    <xsl:output method='xml' indent='yes' omit-xml-declaration='yes'/>\n" +
            "    <xsl:template match='/'>\n" +
            "        <hello/>\n" +
            "    </xsl:template>\n" +
            "</xsl:stylesheet>";
        Source source = new StreamSource(new StringReader(xslt));
        Transformer t = TransformerFactory.newInstance().newTransformer(source);
        Document doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().getDOMImplementation().createDocument(null, "x", null);
        t.transform(new DOMSource(doc), new StreamResult(System.out));
    }
}
---%<---

Results under JDK 1.4.2 are as expected:

---%<---
$ /space/jdk1.4/bin/java -showversion -cp /tmp/test-turkish-xslt/build/classes TestTurkishXSLT
java version "1.4.2_06"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.2_06-b03)
Java HotSpot(TM) Client VM (build 1.4.2_06-b03, mixed mode)

<hello/>
---%<---

However under JDK 1.5 (or later), it is broken:

---%<---
$ /space/jdk1.5/bin/java -showversion -cp /tmp/test-turkish-xslt/build/classes TestTurkishXSLT
java version "1.5.0_01"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_01-b08)
Java HotSpot(TM) Client VM (build 1.5.0_01-b08, mixed mode)

java.lang.RuntimeException: Instruction unknown: load<<<DOTLESS-i>>>nstruction
	at com.sun.org.apache.bcel.internal.util.InstructionFinder.mapName(InstructionFinder.java:138)
	at com.sun.org.apache.bcel.internal.util.InstructionFinder.compilePattern(InstructionFinder.java:170)
	at com.sun.org.apache.bcel.internal.util.InstructionFinder.search(InstructionFinder.java:218)
	at com.sun.org.apache.bcel.internal.util.InstructionFinder.search(InstructionFinder.java:264)
	at com.sun.org.apache.xalan.internal.xsltc.compiler.Mode.peepHoleOptimization(Mode.java:1444)
	at com.sun.org.apache.xalan.internal.xsltc.compiler.Mode.compileApplyTemplates(Mode.java:1058)
	at com.sun.org.apache.xalan.internal.xsltc.compiler.Stylesheet.compileModes(Stylesheet.java:615)
	at com.sun.org.apache.xalan.internal.xsltc.compiler.Stylesheet.translate(Stylesheet.java:730)
	at com.sun.org.apache.xalan.internal.xsltc.compiler.XSLTC.compile(XSLTC.java:335)
	at com.sun.org.apache.xalan.internal.xsltc.compiler.XSLTC.compile(XSLTC.java:410)
	at com.sun.org.apache.xalan.internal.xsltc.trax.TransformerFactoryImpl.newTemplates(TransformerFactoryImpl.java:791)
	at com.sun.org.apache.xalan.internal.xsltc.trax.TransformerFactoryImpl.newTransformer(TransformerFactoryImpl.java:619)
	at TestTurkishXSLT.main(TestTurkishXSLT.java:22)
ERROR:  'Instruction unknown: load<<<DOTLESS-i>>>nstruction
FATAL ERROR:  'Could not compile stylesheet'
Exception in thread "main" javax.xml.transform.TransformerConfigurationException: Could not compile stylesheet
	at com.sun.org.apache.xalan.internal.xsltc.trax.TransformerFactoryImpl.newTemplates(TransformerFactoryImpl.java:824)
	at com.sun.org.apache.xalan.internal.xsltc.trax.TransformerFactoryImpl.newTransformer(TransformerFactoryImpl.java:619)
	at TestTurkishXSLT.main(TestTurkishXSLT.java:22)
---%<---

Here <<<DOTLESS-i>>> is the Turkish lowercase dotless 'i'.

Removing the call to Locale.setDefault, or using e.g. fr_FR, does not exhibit any bug; only Turkish locale.
###@###.### 2005-03-15 18:46:27 GMT

Comments
EVALUATION Was filed for BCEL: http://issues.apache.org/bugzilla/show_bug.cgi?id=38787
26-06-2006

SUGGESTED FIX Use String.toLowerCase(Locale.US) unless you have a very good reason to use the no-arg version. ###@###.### 2005-03-15 18:46:27 GMT
15-03-2005

EVALUATION The cause of the problem is pretty clear if you are familiar with bug #6208680 and look through the stack trace: com.sun.org.apache.bcel.internal.util.InstructionFinder.compilePattern: ---%<--- String lower = pattern.toLowerCase(); ---%<--- Here "loadInstruction" or similar is being translated to a non-ASCII string due to locale rules. Presumably the original Xalan interpreted code did not have this bug, but the XSLTC compiler did, so JDK 1.5 by switching to XSLTC began to suffer from it. Needs to be reported to Xalan developers; can't find any mention in issues.apache.org/jira. ###@###.### 2005-03-15 18:46:27 GMT
15-03-2005

WORK AROUND Run in English locale. ###@###.### 2005-03-15 18:46:27 GMT
15-03-2005