JDK-8149915 : enabling validate-annotations feature for xsd schema with annotation causes NPE
  • Type: Bug
  • Component: xml
  • Sub-Component: jaxp
  • Priority: P3
  • Status: Resolved
  • Resolution: Fixed
  • Submitted: 2016-02-16
  • Updated: 2016-07-21
  • Resolved: 2016-02-22
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 8 JDK 9
8u102Fixed 9 b108Fixed
Related Reports
Duplicate :  
Relates :  
Description
When an xsd that contains annotations is validated with the feature "http://apache.org/xml/features/validate-annotations" enabled, validation fails throwing a NullPointerException:

Exception in thread "main" java.lang.NullPointerException at com.sun.org.apache.xerces.internal.impl.XMLEntityManager.reset(XMLEntityManager.java:1525) at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.resetCommon(XML11Configuration.java:1051) at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:838) at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:805) at com.sun.org.apache.xerces.internal.impl.xs.traversers.XSDHandler.validateAnnotations(XSDHandler.java:685) at com.sun.org.apache.xerces.internal.impl.xs.traversers.XSDHandler.parseSchema(XSDHandler.java:665) at com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaLoader.loadSchema(XMLSchemaLoader.java:612) at com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaLoader.loadGrammar(XMLSchemaLoader.java:571) at com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaLoader.loadGrammar(XMLSchemaLoader.java:537) at com.sun.org.apache.xerces.internal.jaxp.validation.XMLSchemaFactory.newSchema(XMLSchemaFactory.java:266) at javax.xml.validation.SchemaFactory.newSchema(SchemaFactory.java:649)

Following code snippet to reproduce:
SchemaFactory factory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
// "http://apache.org/xml/features/validate-annotations"
factory.setFeature(Constants.XERCES_FEATURE_PREFIX + Constants.VALIDATE_ANNOTATIONS_FEATURE, true); factory.newSchema(new File(XSDValidator.class.getResource("testxsd.xsd").getFile()));

This is the xsd content:
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:annotation>
   <xs:appinfo>Testapp for XSD annotation issue</xs:appinfo>
   <xs:documentation xml:lang="en">This is an XSD annotation, just for the sake of it.</xs:documentation>
</xs:annotation>
</xs:schema>