JDK-6708840 : JAXP validation throws null pointer exception with StAXSource
  • Type: Bug
  • Component: xml
  • Sub-Component: javax.xml.validation
  • Affected Version: jaxp_1.4,5.0
  • Priority: P3
  • Status: Resolved
  • Resolution: Fixed
  • OS: generic
  • CPU: generic
  • Submitted: 2008-05-30
  • Updated: 2013-05-16
  • Resolved: 2008-07-02
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 6 JDK 7 Other
6u14Fixed 7Fixed jaxp_1.4Fixed
Refer to JAXP forum:

Am I doing something wrong? I am attempting to create javax.xml.transform.stax.StAXSource object and pass it to a schema validator object and then call validate() but I get the following stack trace output when I run it:

Exception in thread "main" java.lang.NullPointerException
at com.sun.org.apache.xerces.internal.jaxp.validation.StAXValidatorHelper.validate(StAXValidatorHelper.java:95)
at com.sun.org.apache.xerces.internal.jaxp.validation.ValidatorImpl.validate(ValidatorImpl.java:114)
at javax.xml.validation.Validator.validate(Validator.java:127)
at alex.test.StaxExample.methodA(StaxExample.java:43)
at alex.test.StaxExample.main(StaxExample.java:22)

The schema .xsd file as well as the data .xml file are found and are good. On paper by reading the API's this should work. . .but it doesn't appear that it actually does. Here is the sample code, and I know I am not the only person who has encountered this problem as I took this from another forum elsewhere. But the post was somewhat old and I found nothing as far as a solution or answer by googling around for a while.

package alex.test;

import java.io.File;

import javax.xml.XMLConstants;
import javax.xml.stream.XMLInputFactory;
import javax.xml.stream.XMLStreamReader;
import javax.xml.transform.Source;
import javax.xml.transform.stax.StAXSource;
import javax.xml.transform.stream.StreamSource;
import javax.xml.validation.Schema;
import javax.xml.validation.SchemaFactory;
import javax.xml.validation.Validator;

public class StaxExample {

public static void main(String[] args) throws Exception {
if (args.length != 2) {
System.out.println("Usage : StaxExample <xmlFile> <schemaFile>");
} else {
methodA(args[0], args[1]);

private static void methodA(String xmlFile, String xsdFile)
throws Exception {
XMLInputFactory xmlif = XMLInputFactory.newInstance();

XMLStreamReader staxReader = xmlif.createXMLStreamReader(new StreamSource(xmlFile));

SchemaFactory schemaFactory = SchemaFactory
Schema schemaGrammar = schemaFactory.newSchema(new File(xsdFile));

Validator schemaValidator = schemaGrammar.newValidator();

Source staxSrc = new StAXSource(staxReader);

while (staxReader.hasNext()) {
int eventType = staxReader.next();
System.out.println("Event of type: " + eventType);

EVALUATION Fix in JAXP 1.4. Will request an integration into a JDK6 update release.