Sunday, February 18, 2007

System Properties...

I've been playing around with SaxParserFactories and found something a little annoying regarding its use of System Properties. If the property javax.xml.parsers.SAXParserFactory is set to a fully qualified class name, then that class name will be used as the SAXParserFactory. If it isn't set, then it will use the default parser.

So I'm testing and I end up setting the property back to null after the test (since I thought I was being smart and saved the initial value before I changed the value). But then the properties are backed by a Hashtable and setting a key to null throws a NullPointerException. [sigh] The solution was to dig into the SaxParserFactory class and find that the current default setting is com.sun.org.apache.xerces.internal.jaxp.SAXParserFactoryImpl and set that explicitly. I'm not entirely happy with this solution, but a better solution is currently out of my hands.

The right solution would be either I can remove a property from the System Properties (and I'm imagining there may be good reasons why this would be a bad thing?) or for SaxParserFactory to use the default factory on something other than null. For instance, if it used the default factory when the setting was null or "".

Update: Andy has been so kind to point out that System has a clearyProperty function that will do what I wanted and has had it since 1.5. Thanks Andy!

1 Comments:

At 20 February, 2007 08:49, Anonymous Rob Dawson said...

and with a famous dsouth typo in the update....

perhaps you meant clearProperty?

 

Post a Comment

Links to this post:

Create a Link

<< Home