Java Solaris Communities Sun Store Join SDN My Profile Why Join?
 
Bug Database
Bug Detail
Quick Lists
Top 25 Bugs
Top 25 RFE's
Recently Closed Bugs
Printable Page Printable Page


Bug Database
Bug ID: 6708840
Votes 0
Synopsis JAXP validation throws null pointer exception with StAXSource
Category jaxp:validation
Reported Against
Release Fixed 1.4, 6u14(b03) (Bug ID:2173431)
State 10-Fix Delivered, bug
Priority: 3-Medium
Related Bugs
Submit Date 30-MAY-2008
Description
Refer to JAXP forum:
http://forums.java.net/jive/thread.jspa?threadID=41626&tstart=0

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

ERROR: ''
Exception in thread "main" java.lang.NullPointerException
at com.sun.org. customer .xerces.internal.jaxp.validation.StAXValidatorHelper.validate(StAXValidatorHelper.java:95)
at com.sun.org. customer .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  customer . 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.

<code>
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
.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
Schema schemaGrammar = schemaFactory.newSchema(new File(xsdFile));

Validator schemaValidator = schemaGrammar.newValidator();

Source staxSrc = new StAXSource(staxReader);
schemaValidator.validate(staxSrc);

while (staxReader.hasNext()) {
int eventType = staxReader.next();
System.out.println("Event of type: " + eventType);
}
}
}
</code>
Posted Date : 2008-05-30 03:24:00.0
Work Around
N/A
Evaluation
Fix in JAXP 1.4. Will request an integration into a JDK6 update release.
Posted Date : 2008-07-02 04:50:13.0
Comments
  
  Include a link with my name & email   


PLEASE NOTE: JDK6 is formerly known as Project Mustang