ModeShape

An open-source, federated content repository

SAX broken in Java 6 and 7 (and how open source really works)

Not long ago Serge, one of DNA’s committers, found a bug when running our XML sequencer with Java 6. Turns out the culprit is actually the Java 6’s SAX parser, which is calling the handler methods for entity references in the wrong order! Ouch!

Normally, when processing an XML entity reference, whether a standard entity like “&lt;” or a custom one like “&version;“, the SAX parser first calls startEntity(String) method on LexicalHandler with the name of the entity (e.g., “lt”). It then calls the the character(...) method on ContentHandler to process the replacement content (e.g., “<“). Finally, the parser then calls endEntity(String) method on LexicalHandler (again with the name of the entity).

That’s the way it’s supposed to work. In Java 6, the startEntity(String) method is called correctly, but the endEntity(String) method is then called, and the content passed to the characters(...) includes the replacement content and the next set of content that would be processed. WTF?

I had a tough time finding out whether anyone else hand encountered this. Surely they had – a problem like this? In fact, my search results kept including the DNA bug in the top results. (In hindsight, the only reason we care is that we want to keep the original entity reference rather than use the replacement content, which SAX normally does. So most people may not actually notice the problem.)

But, for the moment, it didn’t matter whether it was a JDK problem or not. We want to release DNA in a few days, and the XML sequencer worked correctly in Java 5, but not in Java 6. So, either find a fix or treat as a known issue. Well, this issue could come up a lot with XML sequencing, so we tried a fix. In fact, I found a workaround that was actually pretty minimal, so now the sequencer works on both Java versions. Score!

Okay, now that DNA was on track, back to the JDK bug. Based upon our unit tests, I had a hunch it was just Java 6 on OS-X. So, would I file the bug with Apple or with Sun? This morning I started working on a simple test to show the problem, which I could use to find out exactly which JDKs were a problem and where I’d need to file the bug.

But then open source to the rescue! Daniel (from the Smooks project) found the same problem and he filed a bug report. Today no less. Turns out my hunch about OS-X was wrong, and it’s a problem in Java 6 and 7. Of course, like a good open-source citizen, Daniel commented on our JIRA issue. That’s how I found out about his bug report. Thanks, Daniel – you saved me some time, and hopefully our initial triaging served you well.

I love how open source works.

Advertisements

Filed under: open source, testing

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

ModeShape is

a lightweight, fast, pluggable, open-source JCR repository that federates and unifies content from multiple systems, including files systems, databases, data grids, other repositories, etc.

Use the JCR API to access the information you already have, or use it like a conventional JCR system (just with more ways to persist your content).

ModeShape used to be 'JBoss DNA'. It's the same project, same community, same license, and same software.

ModeShape

Topics

%d bloggers like this: