L8storm's IT Blog

Keeping my mind free for other stuff

SUN/Oracle Java 6 Shipped with Buggy Xalan Libraries

without comments

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:

  1. Download the Xalan and/or Xerces libraries (Xalan is shipped with the matching Xerces libs!)
  2. Unpack the *.jar files from the archive
  3. Place them somewhere in your applications lib/ folder
  4. 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:

  1. Download this JAVA program: Xalanv.java
  2. Compile it: javac Xalanv.java
  3. Run it: java Xalanv

Links:

Written by l8storm

August 15th, 2010 at 2:26 pm

Leave a Reply