Xml 1.1 throwing NullPointerException when used in xsd

I have an xsd file. I am trying to create javax.xml.validation.Schema using this xsd file. I wrote a program that does this. When I use <?xml version="1.0" encoding="UTF-8"?> Everything works fine. But when I use <?xml version="1.1" encoding="UTF-8"?> , The first attempt to create Schema is to throw NPE, but the second and subsequent attempts will succeed. Below is the source:

 import java.io.File; import javax.xml.validation.Schema; import javax.xml.validation.SchemaFactory; public class Test { SchemaFactory sf = null; public static void main(String args[]) { Test test = new Test(); test.init(); File schemaFile = new File("D:\\test.xsd"); try { test.doIt(schemaFile); } catch (Exception e) { System.out.println("doIt() failed " + e.getMessage()); } try { test.doItAgain(schemaFile); } catch (Exception e) { System.out.println("doItAgain() failed " + e.getMessage()); } System.out.println("Execution completed"); } public void doIt(File schemaFile) throws Exception { @SuppressWarnings("unused") Schema schema = null; synchronized (sf) { schema = sf.newSchema(schemaFile); } System.out.println("doIt() success"); } public void doItAgain(File schemaFile) throws Exception { @SuppressWarnings("unused") Schema schema = null; synchronized (sf) { schema = sf.newSchema(schemaFile); } System.out.println("doAgainIt() success"); } public void init() { sf = SchemaFactory.newInstance("http://www.w3.org/2001/XMLSchema"); } } 

First, the ( doIt() or doItAgain() ) method is executed, which throws an NPE.

The following is a stack trace:

 java.lang.NullPointerException at com.sun.org.apache.xerces.internal.impl.XMLEntityScanner.load(XMLEntityScanner.java:1738) at com.sun.org.apache.xerces.internal.impl.XMLEntityScanner.load(XMLEntityScanner.java:1770) at com.sun.org.apache.xerces.internal.impl.XMLEntityScanner.skipSpaces(XMLEntityScanner.java:1543) at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl$TrailingMiscDriver.next(XMLDocumentScannerImpl.java:1400) at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(XMLDocumentScannerImpl.java:648) at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.next(XMLNSDocumentScannerImpl.java:140) at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:511) at com.sun.org.apache.xerces.internal.impl.xs.opti.SchemaParsingConfig.parse(SchemaParsingConfig.java:435) at com.sun.org.apache.xerces.internal.impl.xs.opti.SchemaParsingConfig.parse(SchemaParsingConfig.java:491) at com.sun.org.apache.xerces.internal.impl.xs.opti.SchemaDOMParser.parse(SchemaDOMParser.java:510) at com.sun.org.apache.xerces.internal.impl.xs.traversers.XSDHandler.getSchemaDocument(XSDHandler.java:1802) at com.sun.org.apache.xerces.internal.impl.xs.traversers.XSDHandler.parseSchema(XSDHandler.java:531) at com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaLoader.loadSchema(XMLSchemaLoader.java:552) at com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaLoader.loadGrammar(XMLSchemaLoader.java:519) at com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaLoader.loadGrammar(XMLSchemaLoader.java:485) at com.sun.org.apache.xerces.internal.jaxp.validation.XMLSchemaFactory.newSchema(XMLSchemaFactory.java:210) at javax.xml.validation.SchemaFactory.newSchema(SchemaFactory.java:594) at javax.xml.validation.SchemaFactory.newSchema(SchemaFactory.java:610) at Test.doIt(Test.java:39) at Test.main(Test.java:20) 

My question is, Why is XML 1.1 not working correctly? Why was only the first attempt unsuccessful?

0
source share
1 answer

I found that if I use the latest version of the Xerces jar, I do not encounter isue. I also found that the problem is that there is an error in the JDK, and it is also registered on the openjdk website , and more interesting is that no one cared to fix it. So use the latest version of Xerces jar or use xml version 1.0. I will go with the first option. Who knows how many hidden surprises will be in the old: P

+1
source

All Articles