Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Built-in XML SAX parser changed between Java 1.4 and 6?

 
Peter Chase
Ranch Hand
Posts: 1970
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I have recently switched an application from Java 1.4 to Java 6. I am having problems with one bit that parses XML using SAX.

The old code did this: -


Under Java 6, this causes a ClassNotFoundException (not at the above code, but when it tries to parse XML).

Under Java 6, if we simply don't bother with this code at all, it seems to parse XML just fine. So, in a way, I already have a solution. But I would like to know exactly what's changed in the Java distributions and why.

A quick Google didn't reveal the answers I'd hoped for. Can anyone point me to appropriate documentation about what XML SAX parser(s) are in what JDK?
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Posts: 15495
43
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't have a direct answer to your question (which SAX parser is included in which JDK version), but: You shouldn't write programs that depend on undocumented implementation details (such as the particular XML parser used under the covers by Java). The API documentation for JDK 1.4 doesn't specify that Crimson is included in the JDK. In fact, the XML API is set up in such a way that other XML parsers can easily be plugged into it and which one is the default or which one is included isn't specified and shouldn't be of concern.

It's been a while since I have worked with XML on Java 1.4. Are you really sure that you have to set this system property (org.xml.sax.driver)? What happens if you just don't set that system property? I'd expect that it should work also on Java 1.4 without setting that property.
[ April 24, 2007: Message edited by: Jesper Young ]
 
Peter Chase
Ranch Hand
Posts: 1970
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I didn't write this code, so I don't know whether there was a good reason for fixing the SAX parser choice. The application is a very advanced user of XML, so it is quite possible that we did need to do that, at some time anyway.

I can say that it appears to work in Java 6 without any code to specify any particular SAX parser.

What I am likely to do is to conditionalise the system property setting code so that it only runs if Java version is 1.4 (Mac OS X still on 1.4 in our app). We'll then have to re-do lots of testing, to make sure everything is OK with the SAX parser that's in Java 6.

FTR I eventually found this Sun document, which explains the stuff I needed to know.
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Posts: 15495
43
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Instead of setting the system property in the code, you could also pass it on the command line, like this:

java -Dorg.xml.sax.driver=org.apache.crimson.parser.XMLReaderImpl ...

Looking at just the Java version might not be enough. What if someone is running your program with IBM JVM version 1.4? It might use something else than Crimson.
 
Peter Chase
Ranch Hand
Posts: 1970
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
We distribute the JRE with our application, so it runs on what we choose. Except on Mac OS X, where it runs on what Apple give you. Either way, there is little/no chance of suddenly encountering an unexpected Java version.

Anyway, for the future running Java 6, I intend not to specify a specific version. For compatibility with the past Java 1.4, I intend to continue specifying what we always specified.

We could do a test by trying to load the specified class at the time of setting the system property.
[ April 24, 2007: Message edited by: Peter Chase ]
 
Rahul Bhattacharjee
Ranch Hand
Posts: 2308
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
JDK 1.4 comes with a JAXP 1.1 compatible parser with it.[Crimson ]. I think java 1.6 comes with a higher version of JAXP.So your program might not be working.

I am wondering why it isn't backward compatible.
 
Peter Chase
Ranch Hand
Posts: 1970
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Rahul Bhattacharjee:
I am wondering why it isn't backward compatible.


It's not backwards compatible because our code specifically requests the Crimson parser, which is missing in Java 6 (and 5, I think).

As discussed above, the norm is not to specify a particular parser, but to let Java choose.
 
Rahul Bhattacharjee
Ranch Hand
Posts: 2308
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am sorry , I did not notice that the user is specifically using Crimson.

Putting crimson parser version in the path , which is compatible to the JAXP version that is used by JDK 1.6 should solve this issue.
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Posts: 15495
43
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Peter Chase:
We distribute the JRE with our application, so it runs on what we choose. Except on Mac OS X, where it runs on what Apple give you. Either way, there is little/no chance of suddenly encountering an unexpected Java version.

Well I could just as well have written "Apple's Java" instead of "IBM Java" - Apple's implementation isn't the same as Sun's, so there's no guarantee that Crimson will be present in Apple's Java.
 
Peter Chase
Ranch Hand
Posts: 1970
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The guarantee is that we tested it on the versions of Mac OS X that we support.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic