SUN/Oracle Java 6 Shipped with Buggy Xalan Libraries
Java has integrated XML functionality (Parser, DOM and XPath handling, …) starting with version 1.5. This is nice, because one does not need additional libraries to provide XML handling in the own code. The integrated XML functionality (compatible to JAXP 1.3) in Java 1.5 and 1.6 is provided by the Apache Xerces and Xalan libraries. Problematic is that SUN/Oracle uses quite old versions of these libraries:
- Xerces: Xerces-J 2.6.2, released: 20.02.2004 (!)
- Xalan: Xalan Java 2.6.0, released: 29.02.2004 (!)
This can lead to unexpected behavior of your code. For example, I am using an XSLT transformation in a software project. The code is correct and worked as expected – when running single threaded. But when starting in a multi threaded environment, even while taking care about the API comments to use one XML Transformer object for a thread, it sometimes worked and sometimes it does not. NullPointerExceptions were thrown by an internal (Xalan) class. Using more heap space delayed the problem, but did not solve it. The solution was an update of the much too old Xalan libraries included in Java 1.6. The problem disappeared after the upgrade.
The newest versions of Xerces an Xalan are currently:
- Xerces: Xerces-J 2.10.0, released: 18.06.2010
- Xalan: Xalan Java 2.7.1, released: November 2007
If you encounter problems using the SUN/Oracle Java built in implementation, you can replace the implementation by a new one this way:
- Download the Xalan and/or Xerces libraries (Xalan is shipped with the matching Xerces libs!)
- Unpack the *.jar files from the archive
- Place them somewhere in your applications lib/ folder
- Be sure that you call your application with the *.jar files on its classpath (
java -cp xalan.jar:xercesimpl.jar:serializer.jar:xml-apis.jar MyApplication)
One may place the files in the $JAVA_HOME/jre/lib/ext/ folder instead. Why Java 1.6 is shipped with internal implementations of Xerces that are more that 6 years old is a question that only SUN/Oracle can answer. Even the newest Xalan version is three years old now, so one could expect that the libs are integrated in the JRE in the meantime…
How to find out the version of Xalan you are using:
- Download this JAVA program: Xalanv.java
- Compile it:
javac Xalanv.java - Run it:
java Xalanv
Links:
- Infos about SUN Java integrated JAXP 1.3 implementation: http://download-llnw.oracle.com/javase/1.5.0/docs/guide/xml/jaxp/JAXP-Compatibility_150.html
- Find out the Xerces version you are using: http://cafe.elharo.com/xml/what-version-of-xerces-are-you-using/
- Apache Xalan Homepage: http://xalan.apache.org/index.html
- Apache Xerces-J Homepage: http://xerces.apache.org/xerces2-j/
- Jakarta release infos, including release dates of Xerces and Xalan: http://jakarta.apache.org/site/news/index.html
- Getting an idea what the
lib/ext/folder is for: http://mindprod.com/jgloss/ext.html