United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
JDK-6240963 : XSLT transforms broken in Turkish locale in JDK 1.5.0+

Details
Type:
Bug
Submit Date:
2005-03-15
Status:
Resolved
Updated Date:
2012-04-24
Project Name:
JDK
Resolved Date:
2005-07-21
Component:
xml
OS:
linux
Sub-Component:
javax.xml.transform
CPU:
x86
Priority:
P2
Resolution:
Fixed
Affected Versions:
5.0
Fixed Versions:
1.4.0 (6.0)

Related Reports
Relates:

Sub Tasks

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
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
                                     
2005-03-15
WORK AROUND

Run in English locale.
###@###.### 2005-03-15 18:46:27 GMT
                                     
2005-03-15
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
                                     
2005-03-15
EVALUATION

Was filed for BCEL:

http://issues.apache.org/bugzilla/show_bug.cgi?id=38787
                                     
2006-06-26



Hardware and Software, Engineered to Work Together