Project

Profile

Help

Is it possible to improve error message when -x option does not work as provided parser class needs additonal class(es)?

Added by Martin Honnen almost 9 years ago

I tried to use Saxon-HE 9.6.0.7J together with LexEv (http://andrewjwelch.com/lexev/LexEv.jar) from the command line and the command line option @-x:com.andrewjwelch.lexev.LexEv@. I ended up getting the error

Transformation failed: net.sf.saxon.trans.XPathException: Failed to instantiate
class com.andrewjwelch.lexev.LexEv (does it have a public zero-argument constructor?)

and I double checked my class path settings and the LexEv.jar several times without seeing anything wrong. I finally tried to write a Java application with Saxon and LexEv and then the stack trace showed me that it was not LexEv directly that caused the problem but LexEv trying to use a Xerces class. So putting @xercesImpl.jar@ in addition to LexEv.jar on the class path finally allowed me to run Saxon from the command line without getting that error.

As the error message only mentioned "Failed to instantiate class com.andrewjwelch.lexev.LexEv" it was kind of hard to find the root of the problem. Perhaps the error message can be improved when loading the parser class fails due to other classes missing.


Replies (1)

RE: Is it possible to improve error message when -x option does not work as provided parser class needs additonal class(es)? - Added by Michael Kay almost 9 years ago

I'll look at it. This kind of thing is always tricky because there are paths where failure to load a class is not an error (it's a condition that the system recovers from); furthermore it's generally bad form to do anything other than throw an exception. In this case (as happens quite often) the message associated with the exception is fairly generic, but the exception has an underlying "cause" field which is only displayed if you explicitly look at it, or if you print the stack trace. In addition, this kind of error condition tends to be under-tested because when you are automating tests, varying the classpath between one test and another is kind of difficult...

    (1-1/1)

    Please register to reply