Project

Profile

Help

BUG 9.0 PreparedStylesheet.newTransformer()

Added by Anonymous over 16 years ago

Legacy ID: #4642285 Legacy Poster: Bruno Grieder (bgrieder)

Hi, PresparedStylesheet.newTransformer() will throw an NPE after the PreparedStylesheet has been serialized then deserialized. Explanation: A serialization/deserialization cycle (using Java standard ObjectStreams) of a PreparedStylesheet will restore the variable config to Null, since it is declared transient line 43. The method newTransformer instantiates a net.sf.saxon.Controller with config to Null. The Controller constructor line 121 calls reset() which executes 'namePool = config.getNamePool()' line 154, throwing an NPE. Bruno Grieder http://www.amalto.com


Replies (5)

Please register to reply

RE: BUG 9.0 PreparedStylesheet.newTransformer - Added by Anonymous over 16 years ago

Legacy ID: #4642496 Legacy Poster: Michael Kay (mhkay)

You need to create a new Configuration object and then load the serialized stylesheet using one of the two factory methods named PreparedStylesheet.loadCompiledStylesheet(). Michael Kay http://www.saxonica.com/

RE: BUG 9.0 PreparedStylesheet.newTransformer - Added by Anonymous over 16 years ago

Legacy ID: #4642504 Legacy Poster: Bruno Grieder (bgrieder)

Hi, Thanks. This is the code I am trying now. Variable parameters points to an instance of a Serializable Bean that stores a PreparedStylesheet. net.sf.saxon.TransformerFactoryImpl transFactory = new net.sf.saxon.TransformerFactoryImpl(); PreparedStylesheet sheet = parameters.getPreparedStyleSheet(); sheet.setConfiguration(transFactory.getConfiguration()); NamePool compiledNamePool = sheet.getTargetNamePool(); sheet.getExecutable().setConfiguration(transFactory.getConfiguration()); transFactory.getConfiguration().setNamePool(compiledNamePool); NamePool.setDefaultNamePool(compiledNamePool); Cheers Bruno Grieder http://www.amalto.com

RE: BUG 9.0 PreparedStylesheet.newTransformer - Added by Anonymous over 16 years ago

Legacy ID: #4642863 Legacy Poster: Bruno Grieder (bgrieder)

Hi, When using the code in the post above followed by Transformer transformer = preparedStyleSheet.newTransformer(); then transformer.transform( new StreamSource(new StringReader(xml)), new StreamResult(sw) ); I get the following Exception java.lang.IllegalArgumentException: Unknown name code 1558 18:34:47,774 INFO [STDOUT] at net.sf.saxon.om.NamePool.unknownNameCode(NamePool.java:831) 18:34:47,776 INFO [STDOUT] at net.sf.saxon.om.NamePool.getDisplayName(NamePool.java:730) 18:34:47,778 INFO [STDOUT] at net.sf.saxon.event.XMLEmitter.startElement(XMLEmitter.java:290) 18:34:47,780 INFO [STDOUT] at net.sf.saxon.event.ImplicitResultChecker.startElement(ImplicitResultChecker.java:32) 18:34:47,781 INFO [STDOUT] at net.sf.saxon.event.NamespaceReducer.startElement(NamespaceReducer.java:72) 18:34:47,784 INFO [STDOUT] at net.sf.saxon.event.ComplexContentOutputter.startContent(ComplexContentOutputter.java:513) 18:34:47,791 INFO [STDOUT] at net.sf.saxon.event.ComplexContentOutputter.startElement(ComplexContentOutputter.java:168) 18:34:47,793 INFO [STDOUT] at net.sf.saxon.instruct.ElementCreator.processLeavingTail(ElementCreator.java:291) 18:34:47,795 INFO [STDOUT] at net.sf.saxon.instruct.Block.processLeavingTail(Block.java:399) 18:34:47,797 INFO [STDOUT] at net.sf.saxon.instruct.Instruction.process(Instruction.java:94) 18:34:47,799 INFO [STDOUT] at net.sf.saxon.instruct.ElementCreator.processLeavingTail(ElementCreator.java:298) 18:34:47,800 INFO [STDOUT] at net.sf.saxon.instruct.Block.processLeavingTail(Block.java:399) 18:34:47,802 INFO [STDOUT] at net.sf.saxon.instruct.Instruction.process(Instruction.java:94) 18:34:47,804 INFO [STDOUT] at net.sf.saxon.instruct.ElementCreator.processLeavingTail(ElementCreator.java:298) 18:34:47,808 INFO [STDOUT] at net.sf.saxon.instruct.Template.applyLeavingTail(Template.java:175) 18:34:47,810 INFO [STDOUT] at net.sf.saxon.instruct.ApplyTemplates.applyTemplates(ApplyTemplates.java:343) 18:34:47,813 INFO [STDOUT] at net.sf.saxon.Controller.transformDocument(Controller.java:1735) 18:34:47,815 INFO [STDOUT] at net.sf.saxon.Controller.transform(Controller.java:1559) .................. Could you please point me to the right direction ? Bruno Grieder http://www.amalto.com

RE: BUG 9.0 PreparedStylesheet.newTransformer - Added by Anonymous over 16 years ago

Legacy ID: #4645147 Legacy Poster: Michael Kay (mhkay)

I can't immediately see what's wrong with your code, which looks very similar to the code Saxon is using when you run a compiled stylesheet from the command line. But the message suggests strongly that the NamePool being used to build the source document isn't the same as the NamePool that was used to compile the stylesheet. Michael Kay Saxonica

RE: BUG 9.0 PreparedStylesheet.newTransformer - Added by Anonymous over 16 years ago

Legacy ID: #4645174 Legacy Poster: Bruno Grieder (bgrieder)

Hi Michael, The code looks similar for a good reason: I actually copied it from you sources.... I tried the alternative route you suggested, doing something like net.sf.saxon.TransformerFactoryImpl factory = new net.sf.saxon.TransformerFactoryImpl(); //ois contains the serialized/deserialized PreparedStylesheet Object instance PreparedStylesheet pss = PreparedStylesheet.loadCompiledStylesheet(factory.getConfiguration, ois); Transformer transformer = pss.newTransformer(); Doing so I get an NPE linked to NamePools. I do not have much time to investigate now, but will try and prepare a test case to easily reproduce the error. Cheers Bruno Grieder http://www.amalto.com

    (1-5/5)

    Please register to reply