Project

Profile

Help

Bug #2102

closed

Saxon should support an empty DOMSource(). As-is, NPE in net.sf.saxon.dom.DOMObjectModel.unravel.

Added by Mark Ziesemer over 10 years ago. Updated over 10 years ago.

Status:
Closed
Priority:
Low
Assignee:
Category:
JAXP Java API
Sprint/Milestone:
-
Start date:
2014-07-09
Due date:
% Done:

100%

Estimated time:
Legacy ID:
Applies to branch:
Fix Committed on Branch:
Fixed in Maintenance Release:
Platforms:

Description

Nearly identical to http://saxon-xslt-and-xquery-processor.13853.n7.nabble.com/empty-DOMSource-td3046.html :

When we create an empty DOMSource with new DOMSource() and use it as the input of transform(), we get:

java.lang.NullPointerException
	at net.sf.saxon.dom.DOMObjectModel.unravel(DOMObjectModel.java:297)
	at net.sf.saxon.Configuration.unravel(Configuration.java:3077)
	at net.sf.saxon.Controller.prepareInputTree(Controller.java:1955)
	at net.sf.saxon.Controller.transform(Controller.java:1846)

The Javadoc for the empty DOMSource constructor says:

If this constructor is used, and no DOM source is set, then the Transformer will create an empty source Document using DocumentBuilder.newDocument().

As-is, this code throws the exception:

transformer.transform(new DOMSource(), new StreamResult(System.out));

This can be used as a work-around:

transformer.transform(new DOMSource(DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument()), new StreamResult(System.out));

IBM previously fixed a similar issue in WebSphere 2008 (http://blogger.ziesemer.com/2008/11/ibm-pk70653-websphere-xslt-empty-dom.html) - and am hoping this will be as easy as a fix here. :-) Christopher Sahnwaldt already provided a patch for review in the above mailing list archive link.

Thanks!

Actions #1

Updated by Michael Kay over 10 years ago

  • Status changed from New to In Progress
  • Found in version changed from 9.5.1-5 to 9.5

I agree, this is a non-conformance with the JAXP spec (and cannot be justified on the usual basis that JAXP does not support XSLT 2.0).

I don't think it's actually necessary to fix this by creating an empty DOM Document; any empty XDM document will do, and the simplest way to create an empty XDM document is probably by using new net.sf.saxon.tree.linked.DocumentImpl(). It's true that the spec says

If this constructor is used, and no DOM source is set, then

the Transformer will create an empty source Document using

DocumentBuilder.newDocument().

but it has no business saying how the Transformer should create an empty document, so long as the observable effect is the same.

Actions #2

Updated by Michael Kay over 10 years ago

  • Status changed from In Progress to Resolved
  • Assignee set to Michael Kay

Fix committed on the 9.5 and 9.6 branches; JUnit test case added in JAXPTest/DOMTest.

Actions #3

Updated by O'Neil Delpratt over 10 years ago

  • Status changed from Resolved to Closed
  • % Done changed from 0 to 100
  • Fixed in version set to 9.5.1.6

Bug fix applied in Saxon maintenance release 9.5.1.6

Please register to edit this issue

Also available in: Atom PDF