8149915: enabling validate-annotations feature for xsd schema with annotation causes NPE

Reviewed-by: joehw
This commit is contained in:
Christoph Langer 2016-02-22 11:00:06 -08:00 committed by Joe Wang
parent 886c549879
commit 5b5e0a63e7
13 changed files with 270 additions and 260 deletions

View file

@ -97,19 +97,9 @@ import com.sun.org.apache.xerces.internal.xni.XNIException;
public class XML11DTDScannerImpl public class XML11DTDScannerImpl
extends XMLDTDScannerImpl { extends XMLDTDScannerImpl {
/** Array of 3 strings. */
private String[] fStrings = new String[3];
/** String. */
private XMLString fString = new XMLString();
/** String buffer. */ /** String buffer. */
private XMLStringBuffer fStringBuffer = new XMLStringBuffer(); private XMLStringBuffer fStringBuffer = new XMLStringBuffer();
/** String buffer. */
private XMLStringBuffer fStringBuffer2 = new XMLStringBuffer();
private XMLStringBuffer fStringBuffer3 = new XMLStringBuffer();
// //
// Constructors // Constructors
// //

View file

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2003, 2015, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2003, 2016, Oracle and/or its affiliates. All rights reserved.
*/ */
/* /*
@ -46,7 +46,6 @@ import com.sun.org.apache.xerces.internal.impl.XMLEntityHandler;
import com.sun.org.apache.xerces.internal.impl.Constants; import com.sun.org.apache.xerces.internal.impl.Constants;
import com.sun.org.apache.xerces.internal.utils.XMLLimitAnalyzer; import com.sun.org.apache.xerces.internal.utils.XMLLimitAnalyzer;
import com.sun.org.apache.xerces.internal.utils.XMLSecurityManager; import com.sun.org.apache.xerces.internal.utils.XMLSecurityManager;
import com.sun.xml.internal.stream.Entity;
/** /**
* This class is responsible for scanning the declarations found * This class is responsible for scanning the declarations found

View file

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2003, 2013, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2003, 2016, Oracle and/or its affiliates. All rights reserved.
*/ */
/* /*
@ -23,7 +23,6 @@ package com.sun.org.apache.xerces.internal.impl;
import com.sun.xml.internal.stream.XMLBufferListener; import com.sun.xml.internal.stream.XMLBufferListener;
import com.sun.xml.internal.stream.XMLEntityStorage; import com.sun.xml.internal.stream.XMLEntityStorage;
import com.sun.xml.internal.stream.XMLInputFactoryImpl;
import com.sun.xml.internal.stream.dtd.DTDGrammarUtil; import com.sun.xml.internal.stream.dtd.DTDGrammarUtil;
import java.io.EOFException; import java.io.EOFException;
@ -50,17 +49,11 @@ import com.sun.org.apache.xerces.internal.xni.parser.XMLInputSource;
import com.sun.org.apache.xerces.internal.xni.Augmentations; import com.sun.org.apache.xerces.internal.xni.Augmentations;
import com.sun.org.apache.xerces.internal.impl.Constants; import com.sun.org.apache.xerces.internal.impl.Constants;
import com.sun.org.apache.xerces.internal.impl.XMLEntityHandler; import com.sun.org.apache.xerces.internal.impl.XMLEntityHandler;
import com.sun.org.apache.xerces.internal.util.NamespaceSupport;
import com.sun.org.apache.xerces.internal.utils.SecuritySupport; import com.sun.org.apache.xerces.internal.utils.SecuritySupport;
import com.sun.org.apache.xerces.internal.utils.XMLLimitAnalyzer;
import com.sun.org.apache.xerces.internal.utils.XMLSecurityManager; import com.sun.org.apache.xerces.internal.utils.XMLSecurityManager;
import com.sun.org.apache.xerces.internal.utils.XMLSecurityManager.Limit; import com.sun.org.apache.xerces.internal.utils.XMLSecurityManager.Limit;
import com.sun.org.apache.xerces.internal.utils.XMLSecurityManager.State;
import com.sun.org.apache.xerces.internal.utils.XMLSecurityPropertyManager; import com.sun.org.apache.xerces.internal.utils.XMLSecurityPropertyManager;
import com.sun.org.apache.xerces.internal.xni.NamespaceContext;
import javax.xml.XMLConstants;
import javax.xml.stream.XMLStreamConstants; import javax.xml.stream.XMLStreamConstants;
import javax.xml.stream.events.XMLEvent;
/** /**
* *
@ -210,12 +203,12 @@ public class XMLDocumentFragmentScannerImpl
null, null,
null, null,
null, null,
EXTERNAL_ACCESS_DEFAULT null
}; };
private static final char [] cdata = {'[','C','D','A','T','A','['}; private static final char [] cdata = {'[','C','D','A','T','A','['};
static final char [] xmlDecl = {'<','?','x','m','l'}; static final char [] xmlDecl = {'<','?','x','m','l'};
private static final char [] endTag = {'<','/'}; // private static final char [] endTag = {'<','/'};
// debugging // debugging
/** Debug scanner state. */ /** Debug scanner state. */
@ -2066,7 +2059,7 @@ public class XMLDocumentFragmentScannerImpl
*/ */
String checkAccess(String systemId, String allowedProtocols) throws IOException { String checkAccess(String systemId, String allowedProtocols) throws IOException {
String baseSystemId = fEntityScanner.getBaseSystemId(); String baseSystemId = fEntityScanner.getBaseSystemId();
String expandedSystemId = fEntityManager.expandSystemId(systemId, baseSystemId,fStrictURI); String expandedSystemId = XMLEntityManager.expandSystemId(systemId, baseSystemId, fStrictURI);
return SecuritySupport.checkAccess(expandedSystemId, allowedProtocols, Constants.ACCESS_EXTERNAL_ALL); return SecuritySupport.checkAccess(expandedSystemId, allowedProtocols, Constants.ACCESS_EXTERNAL_ALL);
} }
@ -2602,8 +2595,6 @@ public class XMLDocumentFragmentScannerImpl
// //
// Driver methods // Driver methods
// //
private boolean fContinueDispatching = true;
private boolean fScanningForMarkup = true;
/** /**
* decides the appropriate state of the parser * decides the appropriate state of the parser
@ -3266,7 +3257,7 @@ public class XMLDocumentFragmentScannerImpl
protected XMLString getString(){ protected XMLString getString(){
if(fAttributeCacheUsedCount < initialCacheCount || fAttributeCacheUsedCount < attributeValueCache.size()){ if(fAttributeCacheUsedCount < initialCacheCount || fAttributeCacheUsedCount < attributeValueCache.size()){
return (XMLString)attributeValueCache.get(fAttributeCacheUsedCount++); return attributeValueCache.get(fAttributeCacheUsedCount++);
} else{ } else{
XMLString str = new XMLString(); XMLString str = new XMLString();
fAttributeCacheUsedCount++; fAttributeCacheUsedCount++;

View file

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2003, 2015, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2003, 2016, Oracle and/or its affiliates. All rights reserved.
*/ */
/* /*
@ -31,7 +31,6 @@ import com.sun.org.apache.xerces.internal.utils.SecuritySupport;
import com.sun.org.apache.xerces.internal.xni.Augmentations; import com.sun.org.apache.xerces.internal.xni.Augmentations;
import com.sun.org.apache.xerces.internal.xni.NamespaceContext; import com.sun.org.apache.xerces.internal.xni.NamespaceContext;
import com.sun.org.apache.xerces.internal.xni.XMLResourceIdentifier; import com.sun.org.apache.xerces.internal.xni.XMLResourceIdentifier;
import com.sun.org.apache.xerces.internal.xni.XMLString;
import com.sun.org.apache.xerces.internal.xni.XNIException; import com.sun.org.apache.xerces.internal.xni.XNIException;
import com.sun.org.apache.xerces.internal.xni.parser.XMLComponentManager; import com.sun.org.apache.xerces.internal.xni.parser.XMLComponentManager;
import com.sun.org.apache.xerces.internal.xni.parser.XMLConfigurationException; import com.sun.org.apache.xerces.internal.xni.parser.XMLConfigurationException;
@ -224,9 +223,6 @@ public class XMLDocumentScannerImpl
/** A DTD Description. */ /** A DTD Description. */
private final XMLDTDDescription fDTDDescription = new XMLDTDDescription(null, null, null, null, null); private final XMLDTDDescription fDTDDescription = new XMLDTDDescription(null, null, null, null, null);
/** String. */
private XMLString fString = new XMLString();
private static final char [] DOCTYPE = {'D','O','C','T','Y','P','E'}; private static final char [] DOCTYPE = {'D','O','C','T','Y','P','E'};
private static final char [] COMMENTSTRING = {'-','-'}; private static final char [] COMMENTSTRING = {'-','-'};

View file

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2009, 2015, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2009, 2016, Oracle and/or its affiliates. All rights reserved.
*/ */
/* /*
* Licensed to the Apache Software Foundation (ASF) under one or more * Licensed to the Apache Software Foundation (ASF) under one or more
@ -370,7 +370,7 @@ public class XMLEntityManager implements XMLComponent, XMLEntityResolver {
protected Map<String, Entity> fEntities = new HashMap<>(); protected Map<String, Entity> fEntities = new HashMap<>();
/** Entity stack. */ /** Entity stack. */
protected Stack fEntityStack = new Stack(); protected Stack<Entity> fEntityStack = new Stack<>();
/** Current entity. */ /** Current entity. */
protected Entity.ScannedEntity fCurrentEntity = null; protected Entity.ScannedEntity fCurrentEntity = null;
@ -633,10 +633,10 @@ public class XMLEntityManager implements XMLComponent, XMLEntityResolver {
final HTTPInputSource httpInputSource = (HTTPInputSource) xmlInputSource; final HTTPInputSource httpInputSource = (HTTPInputSource) xmlInputSource;
// set request properties // set request properties
Iterator propIter = httpInputSource.getHTTPRequestProperties(); Iterator<Map.Entry<String, String>> propIter = httpInputSource.getHTTPRequestProperties();
while (propIter.hasNext()) { while (propIter.hasNext()) {
Map.Entry entry = (Map.Entry) propIter.next(); Map.Entry<String, String> entry = propIter.next();
urlConnection.setRequestProperty((String) entry.getKey(), (String) entry.getValue()); urlConnection.setRequestProperty(entry.getKey(), entry.getValue());
} }
// set preference for redirection // set preference for redirection
@ -1057,7 +1057,6 @@ public class XMLEntityManager implements XMLComponent, XMLEntityResolver {
String literalSystemId = resourceIdentifier.getLiteralSystemId(); String literalSystemId = resourceIdentifier.getLiteralSystemId();
String baseSystemId = resourceIdentifier.getBaseSystemId(); String baseSystemId = resourceIdentifier.getBaseSystemId();
String expandedSystemId = resourceIdentifier.getExpandedSystemId(); String expandedSystemId = resourceIdentifier.getExpandedSystemId();
String namespace = resourceIdentifier.getNamespace();
// if no base systemId given, assume that it's relative // if no base systemId given, assume that it's relative
// to the systemId of the current scanned entity // to the systemId of the current scanned entity
@ -2067,14 +2066,6 @@ public class XMLEntityManager implements XMLComponent, XMLEntityResolver {
// system id has to be a valid URI // system id has to be a valid URI
if (strict) { if (strict) {
// check if there is a system id before
// trying to expand it.
if (systemId == null) {
return null;
}
try { try {
// if it's already an absolute one, return it // if it's already an absolute one, return it
new URI(systemId); new URI(systemId);
@ -2968,7 +2959,7 @@ public class XMLEntityManager implements XMLComponent, XMLEntityResolver {
if (!fCurrentEntity.xmlDeclChunkRead) if (!fCurrentEntity.xmlDeclChunkRead)
{ {
fCurrentEntity.xmlDeclChunkRead = true; fCurrentEntity.xmlDeclChunkRead = true;
len = fCurrentEntity.DEFAULT_XMLDECL_BUFFER_SIZE; len = DEFAULT_XMLDECL_BUFFER_SIZE;
} }
return fInputStream.read(b, off, len); return fInputStream.read(b, off, len);
} }

View file

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2003, 2015, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2003, 2016, Oracle and/or its affiliates. All rights reserved.
*/ */
/* /*
@ -25,8 +25,6 @@ import com.sun.org.apache.xerces.internal.xni.XMLString;
import com.sun.org.apache.xerces.internal.impl.dtd.XMLDTDValidatorFilter; import com.sun.org.apache.xerces.internal.impl.dtd.XMLDTDValidatorFilter;
import com.sun.org.apache.xerces.internal.impl.msg.XMLMessageFormatter; import com.sun.org.apache.xerces.internal.impl.msg.XMLMessageFormatter;
import com.sun.org.apache.xerces.internal.util.XMLAttributesImpl; import com.sun.org.apache.xerces.internal.util.XMLAttributesImpl;
import com.sun.org.apache.xerces.internal.util.XMLAttributesIteratorImpl;
import com.sun.org.apache.xerces.internal.util.XMLStringBuffer;
import com.sun.org.apache.xerces.internal.util.XMLSymbols; import com.sun.org.apache.xerces.internal.util.XMLSymbols;
import com.sun.org.apache.xerces.internal.xni.NamespaceContext; import com.sun.org.apache.xerces.internal.xni.NamespaceContext;
import com.sun.org.apache.xerces.internal.xni.QName; import com.sun.org.apache.xerces.internal.xni.QName;
@ -34,13 +32,9 @@ import com.sun.org.apache.xerces.internal.xni.XNIException;
import com.sun.org.apache.xerces.internal.xni.parser.XMLComponentManager; import com.sun.org.apache.xerces.internal.xni.parser.XMLComponentManager;
import com.sun.org.apache.xerces.internal.xni.parser.XMLConfigurationException; import com.sun.org.apache.xerces.internal.xni.parser.XMLConfigurationException;
import com.sun.org.apache.xerces.internal.xni.XMLDocumentHandler; import com.sun.org.apache.xerces.internal.xni.XMLDocumentHandler;
import com.sun.org.apache.xerces.internal.xni.XMLAttributes;
import com.sun.org.apache.xerces.internal.xni.parser.XMLDocumentSource; import com.sun.org.apache.xerces.internal.xni.parser.XMLDocumentSource;
import com.sun.org.apache.xerces.internal.util.XMLAttributesImpl;
import com.sun.org.apache.xerces.internal.utils.XMLSecurityManager; import com.sun.org.apache.xerces.internal.utils.XMLSecurityManager;
import javax.xml.stream.XMLInputFactory;
import javax.xml.stream.XMLStreamConstants;
import javax.xml.stream.events.XMLEvent; import javax.xml.stream.events.XMLEvent;
/** /**

View file

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2003, 2013, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2003, 2016, Oracle and/or its affiliates. All rights reserved.
*/ */
/* /*
@ -25,7 +25,6 @@ import com.sun.org.apache.xerces.internal.util.Status;
import com.sun.xml.internal.stream.XMLEntityStorage; import com.sun.xml.internal.stream.XMLEntityStorage;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap;
import javax.xml.stream.events.XMLEvent; import javax.xml.stream.events.XMLEvent;
import com.sun.org.apache.xerces.internal.impl.msg.XMLMessageFormatter; import com.sun.org.apache.xerces.internal.impl.msg.XMLMessageFormatter;
import com.sun.org.apache.xerces.internal.util.SymbolTable; import com.sun.org.apache.xerces.internal.util.SymbolTable;
@ -120,8 +119,8 @@ public abstract class XMLScanner
//we should have a feature when set to true computes this value //we should have a feature when set to true computes this value
private boolean fNeedNonNormalizedValue = false; private boolean fNeedNonNormalizedValue = false;
protected ArrayList attributeValueCache = new ArrayList(); protected ArrayList<XMLString> attributeValueCache = new ArrayList<>();
protected ArrayList stringBufferCache = new ArrayList(); protected ArrayList<XMLStringBuffer> stringBufferCache = new ArrayList<>();
protected int fStringBufferIndex = 0; protected int fStringBufferIndex = 0;
protected boolean fAttributeCacheInitDone = false; protected boolean fAttributeCacheInitDone = false;
protected int fAttributeCacheUsedCount = 0; protected int fAttributeCacheUsedCount = 0;
@ -1470,7 +1469,7 @@ public abstract class XMLScanner
XMLStringBuffer getStringBuffer(){ XMLStringBuffer getStringBuffer(){
if((fStringBufferIndex < initialCacheCount )|| (fStringBufferIndex < stringBufferCache.size())){ if((fStringBufferIndex < initialCacheCount )|| (fStringBufferIndex < stringBufferCache.size())){
return (XMLStringBuffer)stringBufferCache.get(fStringBufferIndex++); return stringBufferCache.get(fStringBufferIndex++);
}else{ }else{
XMLStringBuffer tmpObj = new XMLStringBuffer(); XMLStringBuffer tmpObj = new XMLStringBuffer();
fStringBufferIndex++; fStringBufferIndex++;

View file

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2016 Oracle and/or its affiliates. All rights reserved.
*/ */
/* /*
* Licensed to the Apache Software Foundation (ASF) under one or more * Licensed to the Apache Software Foundation (ASF) under one or more
@ -1172,7 +1172,7 @@ public class XSAttributeChecker {
if (max != SchemaSymbols.OCCURRENCE_UNBOUNDED) { if (max != SchemaSymbols.OCCURRENCE_UNBOUNDED) {
// maxOccurLimit is only check in secure mode // maxOccurLimit is only check in secure mode
if (fSchemaHandler.fSecureProcessing != null) { if (fSchemaHandler.fSecurityManager != null) {
String localName = element.getLocalName(); String localName = element.getLocalName();
// The maxOccurs restriction no longer applies to elements // The maxOccurs restriction no longer applies to elements
@ -1191,8 +1191,8 @@ public class XSAttributeChecker {
if (!optimize) { if (!optimize) {
//Revisit :: IMO this is not right place to check //Revisit :: IMO this is not right place to check
// maxOccurNodeLimit. // maxOccurNodeLimit.
int maxOccurNodeLimit = fSchemaHandler.fSecureProcessing.getLimit(XMLSecurityManager.Limit.MAX_OCCUR_NODE_LIMIT); int maxOccurNodeLimit = fSchemaHandler.fSecurityManager.getLimit(XMLSecurityManager.Limit.MAX_OCCUR_NODE_LIMIT);
if (max > maxOccurNodeLimit && !fSchemaHandler.fSecureProcessing.isNoLimit(maxOccurNodeLimit)) { if (max > maxOccurNodeLimit && !fSchemaHandler.fSecurityManager.isNoLimit(maxOccurNodeLimit)) {
reportSchemaFatalError("MaxOccurLimit", new Object[] {new Integer(maxOccurNodeLimit)}, element); reportSchemaFatalError("MaxOccurLimit", new Object[] {new Integer(maxOccurNodeLimit)}, element);
// reset max values in case processing continues on error // reset max values in case processing continues on error

View file

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2007, 2015, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2007, 2016, Oracle and/or its affiliates. All rights reserved.
*/ */
/* /*
* Licensed to the Apache Software Foundation (ASF) under one or more * Licensed to the Apache Software Foundation (ASF) under one or more
@ -194,6 +194,7 @@ public class XSDHandler {
/** Property identifier: entity resolver. */ /** Property identifier: entity resolver. */
public static final String ENTITY_RESOLVER = public static final String ENTITY_RESOLVER =
Constants.XERCES_PROPERTY_PREFIX + Constants.ENTITY_RESOLVER_PROPERTY; Constants.XERCES_PROPERTY_PREFIX + Constants.ENTITY_RESOLVER_PROPERTY;
/** Property identifier: entity manager. */ /** Property identifier: entity manager. */
protected static final String ENTITY_MANAGER = protected static final String ENTITY_MANAGER =
Constants.XERCES_PROPERTY_PREFIX + Constants.ENTITY_MANAGER_PROPERTY; Constants.XERCES_PROPERTY_PREFIX + Constants.ENTITY_MANAGER_PROPERTY;
@ -214,9 +215,6 @@ public class XSDHandler {
protected static final String SECURITY_MANAGER = protected static final String SECURITY_MANAGER =
Constants.XERCES_PROPERTY_PREFIX + Constants.SECURITY_MANAGER_PROPERTY; Constants.XERCES_PROPERTY_PREFIX + Constants.SECURITY_MANAGER_PROPERTY;
private static final String SECURE_PROCESSING =
Constants.XERCES_PROPERTY_PREFIX + Constants.SECURITY_MANAGER_PROPERTY;
/** Property identifier: locale. */ /** Property identifier: locale. */
protected static final String LOCALE = protected static final String LOCALE =
Constants.XERCES_PROPERTY_PREFIX + Constants.LOCALE_PROPERTY; Constants.XERCES_PROPERTY_PREFIX + Constants.LOCALE_PROPERTY;
@ -243,17 +241,12 @@ public class XSDHandler {
// as unlikely as possible to cause collisions. // as unlikely as possible to cause collisions.
public final static String REDEF_IDENTIFIER = "_fn3dktizrknc9pi"; public final static String REDEF_IDENTIFIER = "_fn3dktizrknc9pi";
// //protected data that can be accessible by any traverser
//protected data that can be accessable by any traverser
protected XSDeclarationPool fDeclPool = null; protected XSDeclarationPool fDeclPool = null;
/** // the Security manager in effect.
* <p>Security manager in effect.</p> protected XMLSecurityManager fSecurityManager = null;
*
* <p>Protected to allow access by any traverser.</p>
*/
protected XMLSecurityManager fSecureProcessing = null;
private String fAccessExternalSchema; private String fAccessExternalSchema;
private String fAccessExternalDTD; private String fAccessExternalDTD;
@ -266,27 +259,28 @@ public class XSDHandler {
// XSDocumentInfoRegistry we can easily get the corresponding // XSDocumentInfoRegistry we can easily get the corresponding
// XSDocumentInfo object. // XSDocumentInfo object.
private boolean registryEmpty = true; private boolean registryEmpty = true;
private Map<String, Element> fUnparsedAttributeRegistry = new HashMap(); private Map<String, Element> fUnparsedAttributeRegistry = new HashMap<>();
private Map<String, Element> fUnparsedAttributeGroupRegistry = new HashMap(); private Map<String, Element> fUnparsedAttributeGroupRegistry = new HashMap<>();
private Map<String, Element> fUnparsedElementRegistry = new HashMap(); private Map<String, Element> fUnparsedElementRegistry = new HashMap<>();
private Map<String, Element> fUnparsedGroupRegistry = new HashMap(); private Map<String, Element> fUnparsedGroupRegistry = new HashMap<>();
private Map<String, Element> fUnparsedIdentityConstraintRegistry = new HashMap(); private Map<String, Element> fUnparsedIdentityConstraintRegistry = new HashMap<>();
private Map<String, Element> fUnparsedNotationRegistry = new HashMap(); private Map<String, Element> fUnparsedNotationRegistry = new HashMap<>();
private Map<String, Element> fUnparsedTypeRegistry = new HashMap(); private Map<String, Element> fUnparsedTypeRegistry = new HashMap<>();
// Compensation for the above maps to locate XSDocumentInfo, // Compensation for the above maps to locate XSDocumentInfo,
// Since we may take Schema Element directly, so can not get the // Since we may take Schema Element directly, so can not get the
// corresponding XSDocumentInfo object just using above maps. // corresponding XSDocumentInfo object just using above maps.
private Map<String, XSDocumentInfo> fUnparsedAttributeRegistrySub = new HashMap(); private Map<String, XSDocumentInfo> fUnparsedAttributeRegistrySub = new HashMap<>();
private Map<String, XSDocumentInfo> fUnparsedAttributeGroupRegistrySub = new HashMap(); private Map<String, XSDocumentInfo> fUnparsedAttributeGroupRegistrySub = new HashMap<>();
private Map<String, XSDocumentInfo> fUnparsedElementRegistrySub = new HashMap(); private Map<String, XSDocumentInfo> fUnparsedElementRegistrySub = new HashMap<>();
private Map<String, XSDocumentInfo> fUnparsedGroupRegistrySub = new HashMap(); private Map<String, XSDocumentInfo> fUnparsedGroupRegistrySub = new HashMap<>();
private Map<String, XSDocumentInfo> fUnparsedIdentityConstraintRegistrySub = new HashMap(); private Map<String, XSDocumentInfo> fUnparsedIdentityConstraintRegistrySub = new HashMap<>();
private Map<String, XSDocumentInfo> fUnparsedNotationRegistrySub = new HashMap(); private Map<String, XSDocumentInfo> fUnparsedNotationRegistrySub = new HashMap<>();
private Map<String, XSDocumentInfo> fUnparsedTypeRegistrySub = new HashMap(); private Map<String, XSDocumentInfo> fUnparsedTypeRegistrySub = new HashMap<>();
// Stores XSDocumentInfo (keyed by component name), to check for duplicate // Stores XSDocumentInfo (keyed by component name), to check for duplicate
// components declared within the same xsd document // components declared within the same xsd document
private Map fUnparsedRegistriesExt[] = new HashMap[] { @SuppressWarnings("unchecked")
private Map<String, XSDocumentInfo> fUnparsedRegistriesExt[] = new HashMap[] {
null, null,
null, // ATTRIBUTE_TYPE null, // ATTRIBUTE_TYPE
null, // ATTRIBUTEGROUP_TYPE null, // ATTRIBUTEGROUP_TYPE
@ -300,17 +294,19 @@ public class XSDHandler {
// this map is keyed on by XSDocumentInfo objects. Its values // this map is keyed on by XSDocumentInfo objects. Its values
// are Vectors containing the XSDocumentInfo objects <include>d, // are Vectors containing the XSDocumentInfo objects <include>d,
// <import>ed or <redefine>d by the key XSDocumentInfo. // <import>ed or <redefine>d by the key XSDocumentInfo.
private Map<XSDocumentInfo, Vector> fDependencyMap = new HashMap(); private Map<XSDocumentInfo, Vector<XSDocumentInfo>> fDependencyMap = new HashMap<>();
// this map is keyed on by a target namespace. Its values // this map is keyed on by a target namespace. Its values
// are Vectors containing namespaces imported by schema documents // are Vectors containing namespaces imported by schema documents
// with the key target namespace. // with the key target namespace.
// if an imprted schema has absent namespace, the value "null" is stored. // if an imported schema has absent namespace, the value "null" is stored.
private Map<String, Vector> fImportMap = new HashMap(); private Map<String, Vector> fImportMap = new HashMap<> ();
// all namespaces that imports other namespaces // all namespaces that imports other namespaces
// if the importing schema has absent namespace, empty string is stored. // if the importing schema has absent namespace, empty string is stored.
// (because the key of a map can't be null.) // (because the key of a map can't be null.)
private Vector fAllTNSs = new Vector(); private Vector<String> fAllTNSs = new Vector<>();
// stores instance document mappings between namespaces and schema hints // stores instance document mappings between namespaces and schema hints
private Map<String, XMLSchemaLoader.LocationArray> fLocationPairs = null; private Map<String, XMLSchemaLoader.LocationArray> fLocationPairs = null;
@ -333,7 +329,7 @@ public class XSDHandler {
if(ele.getOwnerDocument() instanceof com.sun.org.apache.xerces.internal.impl.xs.opti.SchemaDOM){ if(ele.getOwnerDocument() instanceof com.sun.org.apache.xerces.internal.impl.xs.opti.SchemaDOM){
documentURI = ((com.sun.org.apache.xerces.internal.impl.xs.opti.SchemaDOM) ele.getOwnerDocument()).getDocumentURI(); documentURI = ((com.sun.org.apache.xerces.internal.impl.xs.opti.SchemaDOM) ele.getOwnerDocument()).getDocumentURI();
} }
return documentURI != null ? documentURI : (String) fDoc2SystemId.get(ele); return documentURI != null ? documentURI : fDoc2SystemId.get(ele);
} }
// This vector stores strings which are combinations of the // This vector stores strings which are combinations of the
@ -341,11 +337,11 @@ public class XSDHandler {
// schema document. This combination is used so that the user's // schema document. This combination is used so that the user's
// EntityResolver can provide a consistent way of identifying a // EntityResolver can provide a consistent way of identifying a
// schema document that is included in multiple other schemas. // schema document that is included in multiple other schemas.
private Map fTraversed = new HashMap(); private Map<XSDKey, Element> fTraversed = new HashMap<>();
// this map contains a mapping from Schema Element to its systemId // this map contains a mapping from Schema Element to its systemId
// this is useful to resolve a uri relative to the referring document // this is useful to resolve a uri relative to the referring document
private Map fDoc2SystemId = new HashMap(); private Map<Element, String> fDoc2SystemId = new HashMap<>();
// the primary XSDocumentInfo we were called to parse // the primary XSDocumentInfo we were called to parse
private XSDocumentInfo fRoot = null; private XSDocumentInfo fRoot = null;
@ -387,7 +383,15 @@ public class XSDHandler {
// the XMLErrorReporter // the XMLErrorReporter
private XMLErrorReporter fErrorReporter; private XMLErrorReporter fErrorReporter;
private XMLEntityResolver fEntityResolver;
// the XMLErrorHandler
private XMLErrorHandler fErrorHandler;
// the Locale
private Locale fLocale;
// the XMLEntityManager
private XMLEntityResolver fEntityManager;
// the XSAttributeChecker // the XSAttributeChecker
private XSAttributeChecker fAttributeChecker; private XSAttributeChecker fAttributeChecker;
@ -404,6 +408,9 @@ public class XSDHandler {
// the Grammar Pool // the Grammar Pool
private XMLGrammarPool fGrammarPool; private XMLGrammarPool fGrammarPool;
// the security property manager
private XMLSecurityPropertyManager fSecurityPropertyMgr = null;
//************ Traversers ********** //************ Traversers **********
XSDAttributeGroupTraverser fAttributeGroupTraverser; XSDAttributeGroupTraverser fAttributeGroupTraverser;
XSDAttributeTraverser fAttributeTraverser; XSDAttributeTraverser fAttributeTraverser;
@ -638,7 +645,7 @@ public class XSDHandler {
// for all grammars with <import>s // for all grammars with <import>s
for (int i = fAllTNSs.size() - 1; i >= 0; i--) { for (int i = fAllTNSs.size() - 1; i >= 0; i--) {
// get its target namespace // get its target namespace
String tns = (String)fAllTNSs.elementAt(i); String tns = fAllTNSs.elementAt(i);
// get all namespaces it imports // get all namespaces it imports
Vector ins = (Vector)fImportMap.get(tns); Vector ins = (Vector)fImportMap.get(tns);
// get the grammar // get the grammar
@ -696,12 +703,13 @@ public class XSDHandler {
fAnnotationValidator.setFeature(VALIDATION, true); fAnnotationValidator.setFeature(VALIDATION, true);
fAnnotationValidator.setFeature(XMLSCHEMA_VALIDATION, true); fAnnotationValidator.setFeature(XMLSCHEMA_VALIDATION, true);
fAnnotationValidator.setProperty(XMLGRAMMAR_POOL, fGrammarBucketAdapter); fAnnotationValidator.setProperty(XMLGRAMMAR_POOL, fGrammarBucketAdapter);
/** set security manager and XML Security Property Manager **/
fAnnotationValidator.setProperty(SECURITY_MANAGER, (fSecurityManager != null) ? fSecurityManager : new XMLSecurityManager(true));
fAnnotationValidator.setProperty(XML_SECURITY_PROPERTY_MANAGER, fSecurityPropertyMgr);
/** Set error handler. **/ /** Set error handler. **/
XMLErrorHandler errorHandler = fErrorReporter.getErrorHandler(); fAnnotationValidator.setProperty(ERROR_HANDLER, (fErrorHandler != null) ? fErrorHandler : new DefaultErrorHandler());
fAnnotationValidator.setProperty(ERROR_HANDLER, (errorHandler != null) ? errorHandler : new DefaultErrorHandler());
/** Set locale. **/ /** Set locale. **/
Locale locale = fErrorReporter.getLocale(); fAnnotationValidator.setProperty(LOCALE, fLocale);
fAnnotationValidator.setProperty(LOCALE, locale);
} }
/** /**
@ -880,10 +888,10 @@ public class XSDHandler {
// store the document and its location // store the document and its location
// REVISIT: don't expose the DOM tree // REVISIT: don't expose the DOM tree
sg.addDocument(null, (String)fDoc2SystemId.get(currSchemaInfo.fSchemaElement)); sg.addDocument(null, fDoc2SystemId.get(currSchemaInfo.fSchemaElement));
fDoc2XSDocumentMap.put(schemaRoot, currSchemaInfo); fDoc2XSDocumentMap.put(schemaRoot, currSchemaInfo);
Vector dependencies = new Vector(); Vector<XSDocumentInfo> dependencies = new Vector<>();
Element rootNode = schemaRoot; Element rootNode = schemaRoot;
Element newSchemaRoot = null; Element newSchemaRoot = null;
@ -1336,7 +1344,7 @@ public class XSDHandler {
// now we're done with this one! // now we're done with this one!
DOMUtil.setHidden(currDoc, fHiddenNodes); DOMUtil.setHidden(currDoc, fHiddenNodes);
// now add the schemas this guy depends on // now add the schemas this guy depends on
Vector currSchemaDepends = (Vector)fDependencyMap.get(currSchemaDoc); Vector<XSDocumentInfo> currSchemaDepends = fDependencyMap.get(currSchemaDoc);
for (int i = 0; i < currSchemaDepends.size(); i++) { for (int i = 0; i < currSchemaDepends.size(); i++) {
schemasToProcess.push(currSchemaDepends.elementAt(i)); schemasToProcess.push(currSchemaDepends.elementAt(i));
} }
@ -1466,7 +1474,7 @@ public class XSDHandler {
DOMUtil.setHidden(currDoc, fHiddenNodes); DOMUtil.setHidden(currDoc, fHiddenNodes);
// now add the schemas this guy depends on // now add the schemas this guy depends on
Vector currSchemaDepends = (Vector)fDependencyMap.get(currSchemaDoc); Vector<XSDocumentInfo> currSchemaDepends = fDependencyMap.get(currSchemaDoc);
for (int i = 0; i < currSchemaDepends.size(); i++) { for (int i = 0; i < currSchemaDepends.size(); i++) {
schemasToProcess.push(currSchemaDepends.elementAt(i)); schemasToProcess.push(currSchemaDepends.elementAt(i));
} }
@ -1915,7 +1923,7 @@ public class XSDHandler {
} }
public String schemaDocument2SystemId(XSDocumentInfo schemaDoc) { public String schemaDocument2SystemId(XSDocumentInfo schemaDoc) {
return (String)fDoc2SystemId.get(schemaDoc.fSchemaElement); return fDoc2SystemId.get(schemaDoc.fSchemaElement);
} }
// This method determines whether there is a group // This method determines whether there is a group
@ -2044,7 +2052,7 @@ public class XSDHandler {
XMLInputSource schemaSource = null; XMLInputSource schemaSource = null;
try { try {
Map<String, XMLSchemaLoader.LocationArray> pairs = usePairs ? fLocationPairs : Collections.emptyMap(); Map<String, XMLSchemaLoader.LocationArray> pairs = usePairs ? fLocationPairs : Collections.emptyMap();
schemaSource = XMLSchemaLoader.resolveDocument(desc, pairs, fEntityResolver); schemaSource = XMLSchemaLoader.resolveDocument(desc, pairs, fEntityManager);
} }
catch (IOException ex) { catch (IOException ex) {
if (mustResolve) { if (mustResolve) {
@ -2097,7 +2105,7 @@ public class XSDHandler {
XMLInputSource schemaSource = null; XMLInputSource schemaSource = null;
try { try {
Map<String, XMLSchemaLoader.LocationArray> pairs = usePairs ? fLocationPairs : Collections.emptyMap(); Map<String, XMLSchemaLoader.LocationArray> pairs = usePairs ? fLocationPairs : Collections.emptyMap();
schemaSource = XMLSchemaLoader.resolveDocument(desc, pairs, fEntityResolver); schemaSource = XMLSchemaLoader.resolveDocument(desc, pairs, fEntityManager);
} }
catch (IOException ex) { catch (IOException ex) {
if (mustResolve) { if (mustResolve) {
@ -2152,7 +2160,7 @@ public class XSDHandler {
if (referType != XSDDescription.CONTEXT_PREPARSE){ if (referType != XSDDescription.CONTEXT_PREPARSE){
schemaId = XMLEntityManager.expandSystemId(schemaSource.getSystemId(), schemaSource.getBaseSystemId(), false); schemaId = XMLEntityManager.expandSystemId(schemaSource.getSystemId(), schemaSource.getBaseSystemId(), false);
key = new XSDKey(schemaId, referType, schemaNamespace); key = new XSDKey(schemaId, referType, schemaNamespace);
if((schemaElement = (Element)fTraversed.get(key)) != null) { if((schemaElement = fTraversed.get(key)) != null) {
fLastSchemaWasDuplicate = true; fLastSchemaWasDuplicate = true;
return schemaElement; return schemaElement;
} }
@ -2211,7 +2219,7 @@ public class XSDHandler {
if (referType != XSDDescription.CONTEXT_PREPARSE) { if (referType != XSDDescription.CONTEXT_PREPARSE) {
schemaId = XMLEntityManager.expandSystemId(inputSource.getSystemId(), schemaSource.getBaseSystemId(), false); schemaId = XMLEntityManager.expandSystemId(inputSource.getSystemId(), schemaSource.getBaseSystemId(), false);
key = new XSDKey(schemaId, referType, schemaNamespace); key = new XSDKey(schemaId, referType, schemaNamespace);
if ((schemaElement = (Element) fTraversed.get(key)) != null) { if ((schemaElement = fTraversed.get(key)) != null) {
fLastSchemaWasDuplicate = true; fLastSchemaWasDuplicate = true;
return schemaElement; return schemaElement;
} }
@ -2238,9 +2246,8 @@ public class XSDHandler {
namespacePrefixes = true; namespacePrefixes = true;
// If this is a Xerces SAX parser set the security manager if there is one // If this is a Xerces SAX parser set the security manager if there is one
if (parser instanceof SAXParser) { if (parser instanceof SAXParser) {
Object securityManager = fSchemaParser.getProperty(SECURITY_MANAGER); if (fSecurityManager != null) {
if (securityManager != null) { parser.setProperty(SECURITY_MANAGER, fSecurityManager);
parser.setProperty(SECURITY_MANAGER, securityManager);
} }
} }
} }
@ -2347,7 +2354,7 @@ public class XSDHandler {
} }
if (isDocument) { if (isDocument) {
key = new XSDKey(schemaId, referType, schemaNamespace); key = new XSDKey(schemaId, referType, schemaNamespace);
if ((schemaElement = (Element) fTraversed.get(key)) != null) { if ((schemaElement = fTraversed.get(key)) != null) {
fLastSchemaWasDuplicate = true; fLastSchemaWasDuplicate = true;
return schemaElement; return schemaElement;
} }
@ -2402,7 +2409,7 @@ public class XSDHandler {
} }
if (isDocument) { if (isDocument) {
key = new XSDKey(schemaId, referType, schemaNamespace); key = new XSDKey(schemaId, referType, schemaNamespace);
if ((schemaElement = (Element) fTraversed.get(key)) != null) { if ((schemaElement = fTraversed.get(key)) != null) {
fLastSchemaWasDuplicate = true; fLastSchemaWasDuplicate = true;
return schemaElement; return schemaElement;
} }
@ -3502,40 +3509,21 @@ public class XSDHandler {
// set symbol table // set symbol table
fSymbolTable = (SymbolTable) componentManager.getProperty(SYMBOL_TABLE); fSymbolTable = (SymbolTable) componentManager.getProperty(SYMBOL_TABLE);
fSecureProcessing = null; // set security manager
if( componentManager!=null ) { fSecurityManager = (XMLSecurityManager) componentManager.getProperty(SECURITY_MANAGER, null);
fSecureProcessing = (XMLSecurityManager) componentManager.getProperty(SECURE_PROCESSING, null);
} //set entity manager
fEntityManager = (XMLEntityResolver) componentManager.getProperty(ENTITY_MANAGER);
//set entity resolver //set entity resolver
fEntityResolver = (XMLEntityResolver) componentManager.getProperty(ENTITY_MANAGER);
XMLEntityResolver er = (XMLEntityResolver)componentManager.getProperty(ENTITY_RESOLVER); XMLEntityResolver er = (XMLEntityResolver)componentManager.getProperty(ENTITY_RESOLVER);
if (er != null) if (er != null)
fSchemaParser.setEntityResolver(er); fSchemaParser.setEntityResolver(er);
// set error reporter // set error reporter
fErrorReporter = fErrorReporter = (XMLErrorReporter) componentManager.getProperty(ERROR_REPORTER);
(XMLErrorReporter) componentManager.getProperty(ERROR_REPORTER); fErrorHandler = fErrorReporter.getErrorHandler();
try { fLocale = fErrorReporter.getLocale();
XMLErrorHandler currErrorHandler = fErrorReporter.getErrorHandler();
// Setting a parser property can be much more expensive
// than checking its value. Don't set the ERROR_HANDLER
// or LOCALE properties unless they've actually changed.
if (currErrorHandler != fSchemaParser.getProperty(ERROR_HANDLER)) {
fSchemaParser.setProperty(ERROR_HANDLER, (currErrorHandler != null) ? currErrorHandler : new DefaultErrorHandler());
if (fAnnotationValidator != null) {
fAnnotationValidator.setProperty(ERROR_HANDLER, (currErrorHandler != null) ? currErrorHandler : new DefaultErrorHandler());
}
}
Locale currentLocale = fErrorReporter.getLocale();
if (currentLocale != fSchemaParser.getProperty(LOCALE)) {
fSchemaParser.setProperty(LOCALE, currentLocale);
if (fAnnotationValidator != null) {
fAnnotationValidator.setProperty(LOCALE, currentLocale);
}
}
}
catch (XMLConfigurationException e) {}
fValidateAnnotations = componentManager.getFeature(VALIDATE_ANNOTATIONS, false); fValidateAnnotations = componentManager.getFeature(VALIDATE_ANNOTATIONS, false);
fHonourAllSchemaLocations = componentManager.getFeature(HONOUR_ALL_SCHEMALOCATIONS, false); fHonourAllSchemaLocations = componentManager.getFeature(HONOUR_ALL_SCHEMALOCATIONS, false);
@ -3543,56 +3531,66 @@ public class XSDHandler {
fTolerateDuplicates = componentManager.getFeature(TOLERATE_DUPLICATES, false); fTolerateDuplicates = componentManager.getFeature(TOLERATE_DUPLICATES, false);
try { try {
fSchemaParser.setFeature( // Setting a parser property can be much more expensive
CONTINUE_AFTER_FATAL_ERROR, // than checking its value. Don't set the ERROR_HANDLER
fErrorReporter.getFeature(CONTINUE_AFTER_FATAL_ERROR)); // or LOCALE properties unless they've actually changed.
} catch (XMLConfigurationException e) { if (fErrorHandler != fSchemaParser.getProperty(ERROR_HANDLER)) {
fSchemaParser.setProperty(ERROR_HANDLER, (fErrorHandler != null) ? fErrorHandler : new DefaultErrorHandler());
if (fAnnotationValidator != null) {
fAnnotationValidator.setProperty(ERROR_HANDLER, (fErrorHandler != null) ? fErrorHandler : new DefaultErrorHandler());
} }
}
if (fLocale != fSchemaParser.getProperty(LOCALE)) {
fSchemaParser.setProperty(LOCALE, fLocale);
if (fAnnotationValidator != null) {
fAnnotationValidator.setProperty(LOCALE, fLocale);
}
}
}
catch (XMLConfigurationException e) {}
try {
fSchemaParser.setFeature(CONTINUE_AFTER_FATAL_ERROR, fErrorReporter.getFeature(CONTINUE_AFTER_FATAL_ERROR));
} catch (XMLConfigurationException e) {}
try { try {
if (componentManager.getFeature(ALLOW_JAVA_ENCODINGS, false)) { if (componentManager.getFeature(ALLOW_JAVA_ENCODINGS, false)) {
fSchemaParser.setFeature(ALLOW_JAVA_ENCODINGS, true); fSchemaParser.setFeature(ALLOW_JAVA_ENCODINGS, true);
} }
} catch (XMLConfigurationException e) { } catch (XMLConfigurationException e) {}
}
try { try {
if (componentManager.getFeature(STANDARD_URI_CONFORMANT_FEATURE, false)) { if (componentManager.getFeature(STANDARD_URI_CONFORMANT_FEATURE, false)) {
fSchemaParser.setFeature(STANDARD_URI_CONFORMANT_FEATURE, true); fSchemaParser.setFeature(STANDARD_URI_CONFORMANT_FEATURE, true);
} }
} catch (XMLConfigurationException e) { } catch (XMLConfigurationException e) {}
}
try { try {
fGrammarPool = fGrammarPool = (XMLGrammarPool) componentManager.getProperty(XMLGRAMMAR_POOL);
(XMLGrammarPool) componentManager.getProperty(XMLGRAMMAR_POOL);
} catch (XMLConfigurationException e) { } catch (XMLConfigurationException e) {
fGrammarPool = null; fGrammarPool = null;
} }
// security features // security features
try { try {
if (componentManager.getFeature(DISALLOW_DOCTYPE, false)) { if (componentManager.getFeature(DISALLOW_DOCTYPE, false)) {
fSchemaParser.setFeature(DISALLOW_DOCTYPE, true); fSchemaParser.setFeature(DISALLOW_DOCTYPE, true);
} }
} catch (XMLConfigurationException e) { } catch (XMLConfigurationException e) {}
}
try { try {
Object security = componentManager.getProperty(SECURITY_MANAGER, null); if (fSecurityManager != null) {
if (security != null){ fSchemaParser.setProperty(SECURITY_MANAGER, fSecurityManager);
fSchemaParser.setProperty(SECURITY_MANAGER, security);
}
} catch (XMLConfigurationException e) {
} }
} catch (XMLConfigurationException e) {}
fSecurityPropertyMgr = (XMLSecurityPropertyManager) componentManager.getProperty(XML_SECURITY_PROPERTY_MANAGER);
XMLSecurityPropertyManager securityPropertyMgr = (XMLSecurityPropertyManager)
componentManager.getProperty(XML_SECURITY_PROPERTY_MANAGER);
//Passing on the setting to the parser //Passing on the setting to the parser
fSchemaParser.setProperty(XML_SECURITY_PROPERTY_MANAGER, securityPropertyMgr); fSchemaParser.setProperty(XML_SECURITY_PROPERTY_MANAGER, fSecurityPropertyMgr);
fAccessExternalDTD = securityPropertyMgr.getValue( fAccessExternalDTD = fSecurityPropertyMgr.getValue(XMLSecurityPropertyManager.Property.ACCESS_EXTERNAL_DTD);
XMLSecurityPropertyManager.Property.ACCESS_EXTERNAL_DTD); fAccessExternalSchema = fSecurityPropertyMgr.getValue(XMLSecurityPropertyManager.Property.ACCESS_EXTERNAL_SCHEMA);
fAccessExternalSchema = securityPropertyMgr.getValue(
XMLSecurityPropertyManager.Property.ACCESS_EXTERNAL_SCHEMA);
} // reset(XMLComponentManager) } // reset(XMLComponentManager)
@ -4051,7 +4049,7 @@ public class XSDHandler {
so long as there's some include/import/redefine path amongst them. so long as there's some include/import/redefine path amongst them.
If they rver reverse this decision the code's right here though... - neilg If they rver reverse this decision the code's right here though... - neilg
// now look in fDependencyMap to see if this is reachable // now look in fDependencyMap to see if this is reachable
if(((Vector)fDependencyMap.get(currSchema)).contains(declDocInfo)) { if((fDependencyMap.get(currSchema)).contains(declDocInfo)) {
return declDocInfo; return declDocInfo;
} }
// obviously the requesting doc didn't include, redefine or // obviously the requesting doc didn't include, redefine or
@ -4072,9 +4070,9 @@ public class XSDHandler {
if (DOMUtil.isHidden(startSchema.fSchemaElement, fHiddenNodes)) { if (DOMUtil.isHidden(startSchema.fSchemaElement, fHiddenNodes)) {
// make it visible // make it visible
DOMUtil.setVisible(startSchema.fSchemaElement, fHiddenNodes); DOMUtil.setVisible(startSchema.fSchemaElement, fHiddenNodes);
Vector dependingSchemas = (Vector)fDependencyMap.get(startSchema); Vector<XSDocumentInfo> dependingSchemas = fDependencyMap.get(startSchema);
for (int i = 0; i < dependingSchemas.size(); i++) { for (int i = 0; i < dependingSchemas.size(); i++) {
setSchemasVisible((XSDocumentInfo)dependingSchemas.elementAt(i)); setSchemasVisible(dependingSchemas.elementAt(i));
} }
} }
// if it's visible already than so must be its children // if it's visible already than so must be its children
@ -4107,7 +4105,7 @@ public class XSDHandler {
ElementImpl ele = (ElementImpl)e; ElementImpl ele = (ElementImpl)e;
// get system id from document object // get system id from document object
Document doc = ele.getOwnerDocument(); Document doc = ele.getOwnerDocument();
String sid = (String)fDoc2SystemId.get(DOMUtil.getRoot(doc)); String sid = fDoc2SystemId.get(DOMUtil.getRoot(doc));
// line/column numbers are stored in the element node // line/column numbers are stored in the element node
int line = ele.getLineNumber(); int line = ele.getLineNumber();
int column = ele.getColumnNumber(); int column = ele.getColumnNumber();

View file

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2008, 2014, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2008, 2016, Oracle and/or its affiliates. All rights reserved.
*/ */
/* /*
* Licensed to the Apache Software Foundation (ASF) under one or more * Licensed to the Apache Software Foundation (ASF) under one or more
@ -52,7 +52,6 @@ import com.sun.org.apache.xerces.internal.util.FeatureState;
import com.sun.org.apache.xerces.internal.util.ParserConfigurationSettings; import com.sun.org.apache.xerces.internal.util.ParserConfigurationSettings;
import com.sun.org.apache.xerces.internal.util.PropertyState; import com.sun.org.apache.xerces.internal.util.PropertyState;
import com.sun.org.apache.xerces.internal.util.SymbolTable; import com.sun.org.apache.xerces.internal.util.SymbolTable;
import com.sun.org.apache.xerces.internal.utils.XMLSecurityManager;
import com.sun.org.apache.xerces.internal.utils.XMLSecurityPropertyManager; import com.sun.org.apache.xerces.internal.utils.XMLSecurityPropertyManager;
import com.sun.org.apache.xerces.internal.xni.XMLDTDContentModelHandler; import com.sun.org.apache.xerces.internal.xni.XMLDTDContentModelHandler;
import com.sun.org.apache.xerces.internal.xni.XMLDTDHandler; import com.sun.org.apache.xerces.internal.xni.XMLDTDHandler;
@ -202,7 +201,6 @@ public class XML11Configuration extends ParserConfigurationSettings
// property identifiers // property identifiers
/** Property identifier: xml string. */ /** Property identifier: xml string. */
protected static final String XML_STRING = protected static final String XML_STRING =
Constants.SAX_PROPERTY_PREFIX + Constants.XML_STRING_PROPERTY; Constants.SAX_PROPERTY_PREFIX + Constants.XML_STRING_PROPERTY;
@ -219,7 +217,6 @@ public class XML11Configuration extends ParserConfigurationSettings
protected static final String ENTITY_RESOLVER = protected static final String ENTITY_RESOLVER =
Constants.XERCES_PROPERTY_PREFIX + Constants.ENTITY_RESOLVER_PROPERTY; Constants.XERCES_PROPERTY_PREFIX + Constants.ENTITY_RESOLVER_PROPERTY;
/** Property identifier: XML Schema validator. */ /** Property identifier: XML Schema validator. */
protected static final String SCHEMA_VALIDATOR = protected static final String SCHEMA_VALIDATOR =
Constants.XERCES_PROPERTY_PREFIX + Constants.SCHEMA_VALIDATOR_PROPERTY; Constants.XERCES_PROPERTY_PREFIX + Constants.SCHEMA_VALIDATOR_PROPERTY;
@ -232,8 +229,6 @@ public class XML11Configuration extends ParserConfigurationSettings
protected static final String SCHEMA_NONS_LOCATION = protected static final String SCHEMA_NONS_LOCATION =
Constants.XERCES_PROPERTY_PREFIX + Constants.SCHEMA_NONS_LOCATION; Constants.XERCES_PROPERTY_PREFIX + Constants.SCHEMA_NONS_LOCATION;
// property identifiers
/** Property identifier: error reporter. */ /** Property identifier: error reporter. */
protected static final String ERROR_REPORTER = protected static final String ERROR_REPORTER =
Constants.XERCES_PROPERTY_PREFIX + Constants.ERROR_REPORTER_PROPERTY; Constants.XERCES_PROPERTY_PREFIX + Constants.ERROR_REPORTER_PROPERTY;
@ -321,13 +316,13 @@ public class XML11Configuration extends ParserConfigurationSettings
protected Locale fLocale; protected Locale fLocale;
/** XML 1.0 Components. */ /** XML 1.0 Components. */
protected ArrayList fComponents; protected ArrayList<XMLComponent> fComponents;
/** XML 1.1. Components. */ /** XML 1.1. Components. */
protected ArrayList fXML11Components = null; protected ArrayList<XMLComponent> fXML11Components = null;
/** Common components: XMLEntityManager, XMLErrorReporter, XMLSchemaValidator */ /** Common components: XMLEntityManager, XMLErrorReporter, XMLSchemaValidator */
protected ArrayList fCommonComponents = null; protected ArrayList<XMLComponent> fCommonComponents = null;
/** The document handler. */ /** The document handler. */
protected XMLDocumentHandler fDocumentHandler; protected XMLDocumentHandler fDocumentHandler;
@ -477,15 +472,15 @@ public class XML11Configuration extends ParserConfigurationSettings
// create a vector to hold all the components in use // create a vector to hold all the components in use
// XML 1.0 specialized components // XML 1.0 specialized components
fComponents = new ArrayList(); fComponents = new ArrayList<>();
// XML 1.1 specialized components // XML 1.1 specialized components
fXML11Components = new ArrayList(); fXML11Components = new ArrayList<>();
// Common components for XML 1.1. and XML 1.0 // Common components for XML 1.1. and XML 1.0
fCommonComponents = new ArrayList(); fCommonComponents = new ArrayList<>();
// create table for features and properties // create table for features and properties
fFeatures = new HashMap(); fFeatures = new HashMap<>();
fProperties = new HashMap(); fProperties = new HashMap<>();
// add default recognized features // add default recognized features
final String[] recognizedFeatures = final String[] recognizedFeatures =
@ -935,20 +930,20 @@ public class XML11Configuration extends ParserConfigurationSettings
// forward to every XML 1.0 component // forward to every XML 1.0 component
int count = fComponents.size(); int count = fComponents.size();
for (int i = 0; i < count; i++) { for (int i = 0; i < count; i++) {
XMLComponent c = (XMLComponent) fComponents.get(i); XMLComponent c = fComponents.get(i);
c.setFeature(featureId, state); c.setFeature(featureId, state);
} }
// forward it to common components // forward it to common components
count = fCommonComponents.size(); count = fCommonComponents.size();
for (int i = 0; i < count; i++) { for (int i = 0; i < count; i++) {
XMLComponent c = (XMLComponent) fCommonComponents.get(i); XMLComponent c = fCommonComponents.get(i);
c.setFeature(featureId, state); c.setFeature(featureId, state);
} }
// forward to every XML 1.1 component // forward to every XML 1.1 component
count = fXML11Components.size(); count = fXML11Components.size();
for (int i = 0; i < count; i++) { for (int i = 0; i < count; i++) {
XMLComponent c = (XMLComponent) fXML11Components.get(i); XMLComponent c = fXML11Components.get(i);
try{ try{
c.setFeature(featureId, state); c.setFeature(featureId, state);
} }
@ -996,19 +991,19 @@ public class XML11Configuration extends ParserConfigurationSettings
// forward to every XML 1.0 component // forward to every XML 1.0 component
int count = fComponents.size(); int count = fComponents.size();
for (int i = 0; i < count; i++) { for (int i = 0; i < count; i++) {
XMLComponent c = (XMLComponent) fComponents.get(i); XMLComponent c = fComponents.get(i);
c.setProperty(propertyId, value); c.setProperty(propertyId, value);
} }
// forward it to every common Component // forward it to every common Component
count = fCommonComponents.size(); count = fCommonComponents.size();
for (int i = 0; i < count; i++) { for (int i = 0; i < count; i++) {
XMLComponent c = (XMLComponent) fCommonComponents.get(i); XMLComponent c = fCommonComponents.get(i);
c.setProperty(propertyId, value); c.setProperty(propertyId, value);
} }
// forward it to every XML 1.1 component // forward it to every XML 1.1 component
count = fXML11Components.size(); count = fXML11Components.size();
for (int i = 0; i < count; i++) { for (int i = 0; i < count; i++) {
XMLComponent c = (XMLComponent) fXML11Components.get(i); XMLComponent c = fXML11Components.get(i);
try{ try{
c.setProperty(propertyId, value); c.setProperty(propertyId, value);
} }
@ -1034,7 +1029,7 @@ public class XML11Configuration extends ParserConfigurationSettings
protected void reset() throws XNIException { protected void reset() throws XNIException {
int count = fComponents.size(); int count = fComponents.size();
for (int i = 0; i < count; i++) { for (int i = 0; i < count; i++) {
XMLComponent c = (XMLComponent) fComponents.get(i); XMLComponent c = fComponents.get(i);
c.reset(this); c.reset(this);
} }
@ -1047,7 +1042,7 @@ public class XML11Configuration extends ParserConfigurationSettings
// reset common components // reset common components
int count = fCommonComponents.size(); int count = fCommonComponents.size();
for (int i = 0; i < count; i++) { for (int i = 0; i < count; i++) {
XMLComponent c = (XMLComponent) fCommonComponents.get(i); XMLComponent c = fCommonComponents.get(i);
c.reset(this); c.reset(this);
} }
@ -1061,7 +1056,7 @@ public class XML11Configuration extends ParserConfigurationSettings
// reset every component // reset every component
int count = fXML11Components.size(); int count = fXML11Components.size();
for (int i = 0; i < count; i++) { for (int i = 0; i < count; i++) {
XMLComponent c = (XMLComponent) fXML11Components.get(i); XMLComponent c = fXML11Components.get(i);
c.reset(this); c.reset(this);
} }

View file

@ -51,7 +51,7 @@ public final class HTTPInputSource extends XMLInputSource {
protected boolean fFollowRedirects = true; protected boolean fFollowRedirects = true;
/** HTTP request properties. **/ /** HTTP request properties. **/
protected Map fHTTPRequestProperties = new HashMap(); protected Map<String, String> fHTTPRequestProperties = new HashMap<>();
// //
// Constructors // Constructors
@ -159,7 +159,7 @@ public final class HTTPInputSource extends XMLInputSource {
* been set * been set
*/ */
public String getHTTPRequestProperty(String key) { public String getHTTPRequestProperty(String key) {
return (String) fHTTPRequestProperties.get(key); return fHTTPRequestProperties.get(key);
} // getHTTPRequestProperty(String):String } // getHTTPRequestProperty(String):String
/** /**
@ -172,7 +172,7 @@ public final class HTTPInputSource extends XMLInputSource {
* @return an iterator for the request properties this * @return an iterator for the request properties this
* input source contains * input source contains
*/ */
public Iterator getHTTPRequestProperties() { public Iterator<Map.Entry<String, String>> getHTTPRequestProperties() {
return fHTTPRequestProperties.entrySet().iterator(); return fHTTPRequestProperties.entrySet().iterator();
} // getHTTPRequestProperties():Iterator } // getHTTPRequestProperties():Iterator

View file

@ -0,0 +1,7 @@
<?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>

View file

@ -0,0 +1,50 @@
/*
* Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package validation;
import java.io.File;
import javax.xml.XMLConstants;
import javax.xml.validation.SchemaFactory;
import org.testng.annotations.Test;
/*
* @summary Test Schema creation
* @bug 8149915
*/
public class SchemaTest {
/*
* @bug 8149915
* Verifies that the annotation validator is initialized with the security manager for schema
* creation with http://apache.org/xml/features/validate-annotations=true.
*/
@Test
public void testValidation() throws Exception {
SchemaFactory factory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
factory.setFeature("http://apache.org/xml/features/validate-annotations", true);
factory.newSchema(new File(getClass().getResource("Bug8149915.xsd").getFile()));
}
}