JDK-8140516 : Regression: NPE when validating XSD annotations
  • Type: Bug
  • Component: xml
  • Sub-Component: org.xml.sax
  • Affected Version: 6,7,8,9
  • Priority: P3
  • Status: Closed
  • Resolution: Duplicate
  • OS: generic
  • CPU: x86
  • Submitted: 2015-10-01
  • Updated: 2016-02-29
  • Resolved: 2016-02-29
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 9
9Resolved
Related Reports
Duplicate :  
Description
FULL PRODUCT VERSION :
java version "1.8.0-ea"
Java(TM) SE Runtime Environment (build 1.8.0-ea-b113)
Java HotSpot(TM) 64-Bit Server VM (build 25.0-b55, mixed mode)


ADDITIONAL OS VERSION INFORMATION :
Darwin mbp 13.0.0 Darwin Kernel Version 13.0.0: Thu Sep 19 22:22:27 PDT 2013; root:xnu-2422.1.72~6/RELEASE_X86_64 x86_64

A DESCRIPTION OF THE PROBLEM :
b113 and later fails with NPE if a <d:annotation> element is present in the XSD.


REGRESSION.  Last worked in version 8

ADDITIONAL REGRESSION INFORMATION: 
java version "1.8.0-ea"
Java(TM) SE Runtime Environment (build 1.8.0-ea-b112)
Java HotSpot(TM) 64-Bit Server VM (build 25.0-b54, mixed mode)


STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Compile and run the attached program.

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Did parse document: UTF-8

ACTUAL -
java.lang.NullPointerException
	at com.sun.org.apache.xerces.internal.impl.XMLEntityManager.reset(XMLEntityManager.java:1504)
	at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.resetCommon(XML11Configuration.java:1023)
	at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:810)
	at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:777)
	at com.sun.org.apache.xerces.internal.impl.xs.traversers.XSDHandler.validateAnnotations(XSDHandler.java:690)
	at com.sun.org.apache.xerces.internal.impl.xs.traversers.XSDHandler.parseSchema(XSDHandler.java:670)
	at com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaLoader.loadSchema(XMLSchemaLoader.java:616)
	at com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaValidator.findSchemaGrammar(XMLSchemaValidator.java:2453)
	at com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaValidator.handleStartElement(XMLSchemaValidator.java:1773)
	at com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaValidator.emptyElement(XMLSchemaValidator.java:766)
	at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.scanStartElement(XMLNSDocumentScannerImpl.java:355)
	at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl$NSContentDriver.scanRootElementHook(XMLNSDocumentScannerImpl.java:604)
	at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.next(XMLDocumentFragmentScannerImpl.java:3130)
	at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl$PrologDriver.next(XMLDocumentScannerImpl.java:880)
	at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(XMLDocumentScannerImpl.java:606)
	at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.next(XMLNSDocumentScannerImpl.java:117)
	at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:510)
	at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:848)
	at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:777)
	at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:141)
	at com.sun.org.apache.xerces.internal.parsers.DOMParser.parse(DOMParser.java:243)
	at com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderImpl.parse(DocumentBuilderImpl.java:348)
	at javax.xml.parsers.DocumentBuilder.parse(DocumentBuilder.java:121)
	at XsdAnnots.main(XsdAnnots.java:47)

REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import org.w3c.dom.Document;
import org.xml.sax.EntityResolver;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;

public class XsdAnnots
{
	static final String xsdText = "<?xml version='1.0' encoding='UTF-8' ?>\n" +
			"<d:schema xmlns:d='http://www.w3.org/2001/XMLSchema'>\n" +
			"    <d:element name='test'>\n" +
			"        <d:annotation>\n" +
			"            <d:documentation>\n" +
			"                This is documentation\n" +
			"            </d:documentation>\n" +
			"        </d:annotation>\n" +
			"        <d:complexType>\n" +
			"            <d:sequence/>\n" +
			"            <d:attribute name='group' use='required' type='d:token'/>\n" +
			"        </d:complexType>\n" +
			"    </d:element>\n" +
			"</d:schema>\n";

	static final String xmlText = "<?xml version='1.0' encoding='UTF-8' ?>\n" +
			"<test\n" +
			"        xsi:noNamespaceSchemaLocation='XsdAnnots.xsd'\n" +
			"        xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'\n" +
			"        group='testing'/>\n";

	public static void main(String[] args) throws Exception
	{
		try {
			DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
			factory.setNamespaceAware(true);
			factory.setValidating(true);
			factory.setAttribute("http://apache.org/xml/features/validation/schema", true);
			factory.setAttribute("http://apache.org/xml/features/validate-annotations", true);
			//
			DocumentBuilder parser = factory.newDocumentBuilder();
			parser.setEntityResolver(new MyResolver());
			//
			InputStream is = new ByteArrayInputStream(xmlText.getBytes("UTF-8"));
			Document doc = parser.parse(is);
			System.err.println("Did parse document: " + doc.getXmlEncoding());
		}
		catch (Throwable ex) {
			ex.printStackTrace();
		}
	}

	static class MyResolver implements EntityResolver
	{
		@Override
		public InputSource resolveEntity(String publicId, String systemId) throws SAXException, IOException
		{
			if (publicId != null || systemId == null || !systemId.endsWith("XsdAnnots.xsd"))
				throw new IOException("Not found: " + systemId);
			InputSource is = new InputSource(new ByteArrayInputStream(xsdText.getBytes("UTF-8")));
			is.setSystemId(systemId);
			return is;
		}
	}
}

---------- END SOURCE ----------


Comments
This bugs will be resolved by fix for JDK-8149915 that is currently under review: http://mail.openjdk.java.net/pipermail/core-libs-dev/2016-February/038881.html
19-02-2016

Issue is reproducible on latest JDK9,8,7 repo builds
29-10-2015