From 5b5e0a63e76a979ee2e3db3adf3c76151320406a Mon Sep 17 00:00:00 2001 From: Christoph Langer Date: Mon, 22 Feb 2016 11:00:06 -0800 Subject: 8149915: enabling validate-annotations feature for xsd schema with annotation causes NPE Reviewed-by: joehw --- .../xerces/internal/impl/XML11DTDScannerImpl.java | 10 - .../xerces/internal/impl/XMLDTDScannerImpl.java | 3 +- .../impl/XMLDocumentFragmentScannerImpl.java | 19 +- .../internal/impl/XMLDocumentScannerImpl.java | 6 +- .../xerces/internal/impl/XMLEntityManager.java | 21 +- .../internal/impl/XMLNSDocumentScannerImpl.java | 8 +- .../apache/xerces/internal/impl/XMLScanner.java | 9 +- .../impl/xs/traversers/XSAttributeChecker.java | 8 +- .../internal/impl/xs/traversers/XSDHandler.java | 212 ++++++++++----------- .../internal/parsers/XML11Configuration.java | 159 ++++++++-------- .../xerces/internal/util/HTTPInputSource.java | 6 +- .../xml/jaxp/unittest/validation/Bug8149915.xsd | 7 + .../xml/jaxp/unittest/validation/SchemaTest.java | 50 +++++ 13 files changed, 264 insertions(+), 254 deletions(-) create mode 100644 jaxp/test/javax/xml/jaxp/unittest/validation/Bug8149915.xsd create mode 100644 jaxp/test/javax/xml/jaxp/unittest/validation/SchemaTest.java (limited to 'jaxp') diff --git a/jaxp/src/java.xml/share/classes/com/sun/org/apache/xerces/internal/impl/XML11DTDScannerImpl.java b/jaxp/src/java.xml/share/classes/com/sun/org/apache/xerces/internal/impl/XML11DTDScannerImpl.java index e3336e3bee4..d6648b75bcb 100644 --- a/jaxp/src/java.xml/share/classes/com/sun/org/apache/xerces/internal/impl/XML11DTDScannerImpl.java +++ b/jaxp/src/java.xml/share/classes/com/sun/org/apache/xerces/internal/impl/XML11DTDScannerImpl.java @@ -97,19 +97,9 @@ import com.sun.org.apache.xerces.internal.xni.XNIException; public class XML11DTDScannerImpl extends XMLDTDScannerImpl { - /** Array of 3 strings. */ - private String[] fStrings = new String[3]; - - /** String. */ - private XMLString fString = new XMLString(); - /** String buffer. */ private XMLStringBuffer fStringBuffer = new XMLStringBuffer(); - /** String buffer. */ - private XMLStringBuffer fStringBuffer2 = new XMLStringBuffer(); - private XMLStringBuffer fStringBuffer3 = new XMLStringBuffer(); - // // Constructors // diff --git a/jaxp/src/java.xml/share/classes/com/sun/org/apache/xerces/internal/impl/XMLDTDScannerImpl.java b/jaxp/src/java.xml/share/classes/com/sun/org/apache/xerces/internal/impl/XMLDTDScannerImpl.java index 591e4601efe..4daa5f0e333 100644 --- a/jaxp/src/java.xml/share/classes/com/sun/org/apache/xerces/internal/impl/XMLDTDScannerImpl.java +++ b/jaxp/src/java.xml/share/classes/com/sun/org/apache/xerces/internal/impl/XMLDTDScannerImpl.java @@ -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.utils.XMLLimitAnalyzer; 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 diff --git a/jaxp/src/java.xml/share/classes/com/sun/org/apache/xerces/internal/impl/XMLDocumentFragmentScannerImpl.java b/jaxp/src/java.xml/share/classes/com/sun/org/apache/xerces/internal/impl/XMLDocumentFragmentScannerImpl.java index 1ea57877573..e31e838c8e8 100644 --- a/jaxp/src/java.xml/share/classes/com/sun/org/apache/xerces/internal/impl/XMLDocumentFragmentScannerImpl.java +++ b/jaxp/src/java.xml/share/classes/com/sun/org/apache/xerces/internal/impl/XMLDocumentFragmentScannerImpl.java @@ -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.XMLEntityStorage; -import com.sun.xml.internal.stream.XMLInputFactoryImpl; import com.sun.xml.internal.stream.dtd.DTDGrammarUtil; 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.impl.Constants; 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.XMLLimitAnalyzer; 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.State; 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.events.XMLEvent; /** * @@ -210,12 +203,12 @@ public class XMLDocumentFragmentScannerImpl null, null, null, - EXTERNAL_ACCESS_DEFAULT + null }; private static final char [] cdata = {'[','C','D','A','T','A','['}; static final char [] xmlDecl = {'<','?','x','m','l'}; - private static final char [] endTag = {'<','/'}; + // private static final char [] endTag = {'<','/'}; // debugging /** Debug scanner state. */ @@ -2066,7 +2059,7 @@ public class XMLDocumentFragmentScannerImpl */ String checkAccess(String systemId, String allowedProtocols) throws IOException { 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); } @@ -2602,8 +2595,6 @@ public class XMLDocumentFragmentScannerImpl // // Driver methods // - private boolean fContinueDispatching = true; - private boolean fScanningForMarkup = true; /** * decides the appropriate state of the parser @@ -3266,7 +3257,7 @@ public class XMLDocumentFragmentScannerImpl protected XMLString getString(){ if(fAttributeCacheUsedCount < initialCacheCount || fAttributeCacheUsedCount < attributeValueCache.size()){ - return (XMLString)attributeValueCache.get(fAttributeCacheUsedCount++); + return attributeValueCache.get(fAttributeCacheUsedCount++); } else{ XMLString str = new XMLString(); fAttributeCacheUsedCount++; diff --git a/jaxp/src/java.xml/share/classes/com/sun/org/apache/xerces/internal/impl/XMLDocumentScannerImpl.java b/jaxp/src/java.xml/share/classes/com/sun/org/apache/xerces/internal/impl/XMLDocumentScannerImpl.java index 5a48b73aa52..7f1bbf10226 100644 --- a/jaxp/src/java.xml/share/classes/com/sun/org/apache/xerces/internal/impl/XMLDocumentScannerImpl.java +++ b/jaxp/src/java.xml/share/classes/com/sun/org/apache/xerces/internal/impl/XMLDocumentScannerImpl.java @@ -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.NamespaceContext; 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.parser.XMLComponentManager; import com.sun.org.apache.xerces.internal.xni.parser.XMLConfigurationException; @@ -224,9 +223,6 @@ public class XMLDocumentScannerImpl /** A DTD Description. */ 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 [] COMMENTSTRING = {'-','-'}; diff --git a/jaxp/src/java.xml/share/classes/com/sun/org/apache/xerces/internal/impl/XMLEntityManager.java b/jaxp/src/java.xml/share/classes/com/sun/org/apache/xerces/internal/impl/XMLEntityManager.java index ff96275c433..f08a1275dfa 100644 --- a/jaxp/src/java.xml/share/classes/com/sun/org/apache/xerces/internal/impl/XMLEntityManager.java +++ b/jaxp/src/java.xml/share/classes/com/sun/org/apache/xerces/internal/impl/XMLEntityManager.java @@ -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 @@ -370,7 +370,7 @@ public class XMLEntityManager implements XMLComponent, XMLEntityResolver { protected Map fEntities = new HashMap<>(); /** Entity stack. */ - protected Stack fEntityStack = new Stack(); + protected Stack fEntityStack = new Stack<>(); /** Current entity. */ protected Entity.ScannedEntity fCurrentEntity = null; @@ -633,10 +633,10 @@ public class XMLEntityManager implements XMLComponent, XMLEntityResolver { final HTTPInputSource httpInputSource = (HTTPInputSource) xmlInputSource; // set request properties - Iterator propIter = httpInputSource.getHTTPRequestProperties(); + Iterator> propIter = httpInputSource.getHTTPRequestProperties(); while (propIter.hasNext()) { - Map.Entry entry = (Map.Entry) propIter.next(); - urlConnection.setRequestProperty((String) entry.getKey(), (String) entry.getValue()); + Map.Entry entry = propIter.next(); + urlConnection.setRequestProperty(entry.getKey(), entry.getValue()); } // set preference for redirection @@ -1057,7 +1057,6 @@ public class XMLEntityManager implements XMLComponent, XMLEntityResolver { String literalSystemId = resourceIdentifier.getLiteralSystemId(); String baseSystemId = resourceIdentifier.getBaseSystemId(); String expandedSystemId = resourceIdentifier.getExpandedSystemId(); - String namespace = resourceIdentifier.getNamespace(); // if no base systemId given, assume that it's relative // 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 if (strict) { - - - // check if there is a system id before - // trying to expand it. - if (systemId == null) { - return null; - } - try { // if it's already an absolute one, return it new URI(systemId); @@ -2968,7 +2959,7 @@ public class XMLEntityManager implements XMLComponent, XMLEntityResolver { if (!fCurrentEntity.xmlDeclChunkRead) { fCurrentEntity.xmlDeclChunkRead = true; - len = fCurrentEntity.DEFAULT_XMLDECL_BUFFER_SIZE; + len = DEFAULT_XMLDECL_BUFFER_SIZE; } return fInputStream.read(b, off, len); } diff --git a/jaxp/src/java.xml/share/classes/com/sun/org/apache/xerces/internal/impl/XMLNSDocumentScannerImpl.java b/jaxp/src/java.xml/share/classes/com/sun/org/apache/xerces/internal/impl/XMLNSDocumentScannerImpl.java index 8badd36d876..2cdb0001322 100644 --- a/jaxp/src/java.xml/share/classes/com/sun/org/apache/xerces/internal/impl/XMLNSDocumentScannerImpl.java +++ b/jaxp/src/java.xml/share/classes/com/sun/org/apache/xerces/internal/impl/XMLNSDocumentScannerImpl.java @@ -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.msg.XMLMessageFormatter; 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.xni.NamespaceContext; 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.XMLConfigurationException; 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.util.XMLAttributesImpl; 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; /** diff --git a/jaxp/src/java.xml/share/classes/com/sun/org/apache/xerces/internal/impl/XMLScanner.java b/jaxp/src/java.xml/share/classes/com/sun/org/apache/xerces/internal/impl/XMLScanner.java index 10c484ac3a3..5ead2dd1fc6 100644 --- a/jaxp/src/java.xml/share/classes/com/sun/org/apache/xerces/internal/impl/XMLScanner.java +++ b/jaxp/src/java.xml/share/classes/com/sun/org/apache/xerces/internal/impl/XMLScanner.java @@ -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 java.io.IOException; import java.util.ArrayList; -import java.util.HashMap; import javax.xml.stream.events.XMLEvent; import com.sun.org.apache.xerces.internal.impl.msg.XMLMessageFormatter; 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 private boolean fNeedNonNormalizedValue = false; - protected ArrayList attributeValueCache = new ArrayList(); - protected ArrayList stringBufferCache = new ArrayList(); + protected ArrayList attributeValueCache = new ArrayList<>(); + protected ArrayList stringBufferCache = new ArrayList<>(); protected int fStringBufferIndex = 0; protected boolean fAttributeCacheInitDone = false; protected int fAttributeCacheUsedCount = 0; @@ -1470,7 +1469,7 @@ public abstract class XMLScanner XMLStringBuffer getStringBuffer(){ if((fStringBufferIndex < initialCacheCount )|| (fStringBufferIndex < stringBufferCache.size())){ - return (XMLStringBuffer)stringBufferCache.get(fStringBufferIndex++); + return stringBufferCache.get(fStringBufferIndex++); }else{ XMLStringBuffer tmpObj = new XMLStringBuffer(); fStringBufferIndex++; diff --git a/jaxp/src/java.xml/share/classes/com/sun/org/apache/xerces/internal/impl/xs/traversers/XSAttributeChecker.java b/jaxp/src/java.xml/share/classes/com/sun/org/apache/xerces/internal/impl/xs/traversers/XSAttributeChecker.java index f9a9fe309ac..816cdaa4757 100644 --- a/jaxp/src/java.xml/share/classes/com/sun/org/apache/xerces/internal/impl/xs/traversers/XSAttributeChecker.java +++ b/jaxp/src/java.xml/share/classes/com/sun/org/apache/xerces/internal/impl/xs/traversers/XSAttributeChecker.java @@ -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 @@ -1172,7 +1172,7 @@ public class XSAttributeChecker { if (max != SchemaSymbols.OCCURRENCE_UNBOUNDED) { // maxOccurLimit is only check in secure mode - if (fSchemaHandler.fSecureProcessing != null) { + if (fSchemaHandler.fSecurityManager != null) { String localName = element.getLocalName(); // The maxOccurs restriction no longer applies to elements @@ -1191,8 +1191,8 @@ public class XSAttributeChecker { if (!optimize) { //Revisit :: IMO this is not right place to check // maxOccurNodeLimit. - int maxOccurNodeLimit = fSchemaHandler.fSecureProcessing.getLimit(XMLSecurityManager.Limit.MAX_OCCUR_NODE_LIMIT); - if (max > maxOccurNodeLimit && !fSchemaHandler.fSecureProcessing.isNoLimit(maxOccurNodeLimit)) { + int maxOccurNodeLimit = fSchemaHandler.fSecurityManager.getLimit(XMLSecurityManager.Limit.MAX_OCCUR_NODE_LIMIT); + if (max > maxOccurNodeLimit && !fSchemaHandler.fSecurityManager.isNoLimit(maxOccurNodeLimit)) { reportSchemaFatalError("MaxOccurLimit", new Object[] {new Integer(maxOccurNodeLimit)}, element); // reset max values in case processing continues on error diff --git a/jaxp/src/java.xml/share/classes/com/sun/org/apache/xerces/internal/impl/xs/traversers/XSDHandler.java b/jaxp/src/java.xml/share/classes/com/sun/org/apache/xerces/internal/impl/xs/traversers/XSDHandler.java index 852a09fb87f..d1671179b00 100644 --- a/jaxp/src/java.xml/share/classes/com/sun/org/apache/xerces/internal/impl/xs/traversers/XSDHandler.java +++ b/jaxp/src/java.xml/share/classes/com/sun/org/apache/xerces/internal/impl/xs/traversers/XSDHandler.java @@ -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 @@ -194,6 +194,7 @@ public class XSDHandler { /** Property identifier: entity resolver. */ public static final String ENTITY_RESOLVER = Constants.XERCES_PROPERTY_PREFIX + Constants.ENTITY_RESOLVER_PROPERTY; + /** Property identifier: entity manager. */ protected static final String ENTITY_MANAGER = Constants.XERCES_PROPERTY_PREFIX + Constants.ENTITY_MANAGER_PROPERTY; @@ -214,16 +215,13 @@ public class XSDHandler { protected static final String SECURITY_MANAGER = 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. */ protected static final String LOCALE = Constants.XERCES_PROPERTY_PREFIX + Constants.LOCALE_PROPERTY; - /** Property identifier: Security property manager. */ + /** Property identifier: Security property manager. */ private static final String XML_SECURITY_PROPERTY_MANAGER = - Constants.XML_SECURITY_PROPERTY_MANAGER; + Constants.XML_SECURITY_PROPERTY_MANAGER; protected static final boolean DEBUG_NODE_POOL = false; @@ -243,17 +241,12 @@ public class XSDHandler { // as unlikely as possible to cause collisions. public final static String REDEF_IDENTIFIER = "_fn3dktizrknc9pi"; - // - //protected data that can be accessable by any traverser + //protected data that can be accessible by any traverser protected XSDeclarationPool fDeclPool = null; - /** - *

Security manager in effect.

- * - *

Protected to allow access by any traverser.

- */ - protected XMLSecurityManager fSecureProcessing = null; + // the Security manager in effect. + protected XMLSecurityManager fSecurityManager = null; private String fAccessExternalSchema; private String fAccessExternalDTD; @@ -266,27 +259,28 @@ public class XSDHandler { // XSDocumentInfoRegistry we can easily get the corresponding // XSDocumentInfo object. private boolean registryEmpty = true; - private Map fUnparsedAttributeRegistry = new HashMap(); - private Map fUnparsedAttributeGroupRegistry = new HashMap(); - private Map fUnparsedElementRegistry = new HashMap(); - private Map fUnparsedGroupRegistry = new HashMap(); - private Map fUnparsedIdentityConstraintRegistry = new HashMap(); - private Map fUnparsedNotationRegistry = new HashMap(); - private Map fUnparsedTypeRegistry = new HashMap(); + private Map fUnparsedAttributeRegistry = new HashMap<>(); + private Map fUnparsedAttributeGroupRegistry = new HashMap<>(); + private Map fUnparsedElementRegistry = new HashMap<>(); + private Map fUnparsedGroupRegistry = new HashMap<>(); + private Map fUnparsedIdentityConstraintRegistry = new HashMap<>(); + private Map fUnparsedNotationRegistry = new HashMap<>(); + private Map fUnparsedTypeRegistry = new HashMap<>(); // Compensation for the above maps to locate XSDocumentInfo, // Since we may take Schema Element directly, so can not get the // corresponding XSDocumentInfo object just using above maps. - private Map fUnparsedAttributeRegistrySub = new HashMap(); - private Map fUnparsedAttributeGroupRegistrySub = new HashMap(); - private Map fUnparsedElementRegistrySub = new HashMap(); - private Map fUnparsedGroupRegistrySub = new HashMap(); - private Map fUnparsedIdentityConstraintRegistrySub = new HashMap(); - private Map fUnparsedNotationRegistrySub = new HashMap(); - private Map fUnparsedTypeRegistrySub = new HashMap(); + private Map fUnparsedAttributeRegistrySub = new HashMap<>(); + private Map fUnparsedAttributeGroupRegistrySub = new HashMap<>(); + private Map fUnparsedElementRegistrySub = new HashMap<>(); + private Map fUnparsedGroupRegistrySub = new HashMap<>(); + private Map fUnparsedIdentityConstraintRegistrySub = new HashMap<>(); + private Map fUnparsedNotationRegistrySub = new HashMap<>(); + private Map fUnparsedTypeRegistrySub = new HashMap<>(); // Stores XSDocumentInfo (keyed by component name), to check for duplicate // components declared within the same xsd document - private Map fUnparsedRegistriesExt[] = new HashMap[] { + @SuppressWarnings("unchecked") + private Map fUnparsedRegistriesExt[] = new HashMap[] { null, null, // ATTRIBUTE_TYPE null, // ATTRIBUTEGROUP_TYPE @@ -300,17 +294,19 @@ public class XSDHandler { // this map is keyed on by XSDocumentInfo objects. Its values // are Vectors containing the XSDocumentInfo objects d, // ed or d by the key XSDocumentInfo. - private Map fDependencyMap = new HashMap(); + private Map> fDependencyMap = new HashMap<>(); // this map is keyed on by a target namespace. Its values // are Vectors containing namespaces imported by schema documents // with the key target namespace. - // if an imprted schema has absent namespace, the value "null" is stored. - private Map fImportMap = new HashMap(); + // if an imported schema has absent namespace, the value "null" is stored. + private Map fImportMap = new HashMap<> (); + // all namespaces that imports other namespaces // if the importing schema has absent namespace, empty string is stored. // (because the key of a map can't be null.) - private Vector fAllTNSs = new Vector(); + private Vector fAllTNSs = new Vector<>(); + // stores instance document mappings between namespaces and schema hints private Map fLocationPairs = null; @@ -333,7 +329,7 @@ public class XSDHandler { 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(); } - return documentURI != null ? documentURI : (String) fDoc2SystemId.get(ele); + return documentURI != null ? documentURI : fDoc2SystemId.get(ele); } // 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 // EntityResolver can provide a consistent way of identifying a // schema document that is included in multiple other schemas. - private Map fTraversed = new HashMap(); + private Map fTraversed = new HashMap<>(); // this map contains a mapping from Schema Element to its systemId // this is useful to resolve a uri relative to the referring document - private Map fDoc2SystemId = new HashMap(); + private Map fDoc2SystemId = new HashMap<>(); // the primary XSDocumentInfo we were called to parse private XSDocumentInfo fRoot = null; @@ -387,7 +383,15 @@ public class XSDHandler { // the XMLErrorReporter private XMLErrorReporter fErrorReporter; - private XMLEntityResolver fEntityResolver; + + // the XMLErrorHandler + private XMLErrorHandler fErrorHandler; + + // the Locale + private Locale fLocale; + + // the XMLEntityManager + private XMLEntityResolver fEntityManager; // the XSAttributeChecker private XSAttributeChecker fAttributeChecker; @@ -404,6 +408,9 @@ public class XSDHandler { // the Grammar Pool private XMLGrammarPool fGrammarPool; + // the security property manager + private XMLSecurityPropertyManager fSecurityPropertyMgr = null; + //************ Traversers ********** XSDAttributeGroupTraverser fAttributeGroupTraverser; XSDAttributeTraverser fAttributeTraverser; @@ -638,7 +645,7 @@ public class XSDHandler { // for all grammars with s for (int i = fAllTNSs.size() - 1; i >= 0; i--) { // get its target namespace - String tns = (String)fAllTNSs.elementAt(i); + String tns = fAllTNSs.elementAt(i); // get all namespaces it imports Vector ins = (Vector)fImportMap.get(tns); // get the grammar @@ -696,12 +703,13 @@ public class XSDHandler { fAnnotationValidator.setFeature(VALIDATION, true); fAnnotationValidator.setFeature(XMLSCHEMA_VALIDATION, true); 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. **/ - XMLErrorHandler errorHandler = fErrorReporter.getErrorHandler(); - fAnnotationValidator.setProperty(ERROR_HANDLER, (errorHandler != null) ? errorHandler : new DefaultErrorHandler()); + fAnnotationValidator.setProperty(ERROR_HANDLER, (fErrorHandler != null) ? fErrorHandler : new DefaultErrorHandler()); /** Set locale. **/ - Locale locale = fErrorReporter.getLocale(); - fAnnotationValidator.setProperty(LOCALE, locale); + fAnnotationValidator.setProperty(LOCALE, fLocale); } /** @@ -880,10 +888,10 @@ public class XSDHandler { // store the document and its location // 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); - Vector dependencies = new Vector(); + Vector dependencies = new Vector<>(); Element rootNode = schemaRoot; Element newSchemaRoot = null; @@ -1334,9 +1342,9 @@ public class XSDHandler { } // end for // now we're done with this one! - DOMUtil.setHidden(currDoc, fHiddenNodes); + DOMUtil.setHidden(currDoc, fHiddenNodes); // now add the schemas this guy depends on - Vector currSchemaDepends = (Vector)fDependencyMap.get(currSchemaDoc); + Vector currSchemaDepends = fDependencyMap.get(currSchemaDoc); for (int i = 0; i < currSchemaDepends.size(); i++) { schemasToProcess.push(currSchemaDepends.elementAt(i)); } @@ -1466,7 +1474,7 @@ public class XSDHandler { DOMUtil.setHidden(currDoc, fHiddenNodes); // now add the schemas this guy depends on - Vector currSchemaDepends = (Vector)fDependencyMap.get(currSchemaDoc); + Vector currSchemaDepends = fDependencyMap.get(currSchemaDoc); for (int i = 0; i < currSchemaDepends.size(); i++) { schemasToProcess.push(currSchemaDepends.elementAt(i)); } @@ -1915,7 +1923,7 @@ public class XSDHandler { } public String schemaDocument2SystemId(XSDocumentInfo schemaDoc) { - return (String)fDoc2SystemId.get(schemaDoc.fSchemaElement); + return fDoc2SystemId.get(schemaDoc.fSchemaElement); } // This method determines whether there is a group @@ -2044,7 +2052,7 @@ public class XSDHandler { XMLInputSource schemaSource = null; try { Map pairs = usePairs ? fLocationPairs : Collections.emptyMap(); - schemaSource = XMLSchemaLoader.resolveDocument(desc, pairs, fEntityResolver); + schemaSource = XMLSchemaLoader.resolveDocument(desc, pairs, fEntityManager); } catch (IOException ex) { if (mustResolve) { @@ -2097,7 +2105,7 @@ public class XSDHandler { XMLInputSource schemaSource = null; try { Map pairs = usePairs ? fLocationPairs : Collections.emptyMap(); - schemaSource = XMLSchemaLoader.resolveDocument(desc, pairs, fEntityResolver); + schemaSource = XMLSchemaLoader.resolveDocument(desc, pairs, fEntityManager); } catch (IOException ex) { if (mustResolve) { @@ -2152,7 +2160,7 @@ public class XSDHandler { if (referType != XSDDescription.CONTEXT_PREPARSE){ schemaId = XMLEntityManager.expandSystemId(schemaSource.getSystemId(), schemaSource.getBaseSystemId(), false); key = new XSDKey(schemaId, referType, schemaNamespace); - if((schemaElement = (Element)fTraversed.get(key)) != null) { + if((schemaElement = fTraversed.get(key)) != null) { fLastSchemaWasDuplicate = true; return schemaElement; } @@ -2211,7 +2219,7 @@ public class XSDHandler { if (referType != XSDDescription.CONTEXT_PREPARSE) { schemaId = XMLEntityManager.expandSystemId(inputSource.getSystemId(), schemaSource.getBaseSystemId(), false); key = new XSDKey(schemaId, referType, schemaNamespace); - if ((schemaElement = (Element) fTraversed.get(key)) != null) { + if ((schemaElement = fTraversed.get(key)) != null) { fLastSchemaWasDuplicate = true; return schemaElement; } @@ -2238,9 +2246,8 @@ public class XSDHandler { namespacePrefixes = true; // If this is a Xerces SAX parser set the security manager if there is one if (parser instanceof SAXParser) { - Object securityManager = fSchemaParser.getProperty(SECURITY_MANAGER); - if (securityManager != null) { - parser.setProperty(SECURITY_MANAGER, securityManager); + if (fSecurityManager != null) { + parser.setProperty(SECURITY_MANAGER, fSecurityManager); } } } @@ -2347,7 +2354,7 @@ public class XSDHandler { } if (isDocument) { key = new XSDKey(schemaId, referType, schemaNamespace); - if ((schemaElement = (Element) fTraversed.get(key)) != null) { + if ((schemaElement = fTraversed.get(key)) != null) { fLastSchemaWasDuplicate = true; return schemaElement; } @@ -2402,7 +2409,7 @@ public class XSDHandler { } if (isDocument) { key = new XSDKey(schemaId, referType, schemaNamespace); - if ((schemaElement = (Element) fTraversed.get(key)) != null) { + if ((schemaElement = fTraversed.get(key)) != null) { fLastSchemaWasDuplicate = true; return schemaElement; } @@ -3502,97 +3509,88 @@ public class XSDHandler { // set symbol table fSymbolTable = (SymbolTable) componentManager.getProperty(SYMBOL_TABLE); - fSecureProcessing = null; - if( componentManager!=null ) { - fSecureProcessing = (XMLSecurityManager) componentManager.getProperty(SECURE_PROCESSING, null); - } + // set security manager + fSecurityManager = (XMLSecurityManager) componentManager.getProperty(SECURITY_MANAGER, null); + + //set entity manager + fEntityManager = (XMLEntityResolver) componentManager.getProperty(ENTITY_MANAGER); //set entity resolver - fEntityResolver = (XMLEntityResolver) componentManager.getProperty(ENTITY_MANAGER); XMLEntityResolver er = (XMLEntityResolver)componentManager.getProperty(ENTITY_RESOLVER); if (er != null) fSchemaParser.setEntityResolver(er); // set error reporter - fErrorReporter = - (XMLErrorReporter) componentManager.getProperty(ERROR_REPORTER); + fErrorReporter = (XMLErrorReporter) componentManager.getProperty(ERROR_REPORTER); + fErrorHandler = fErrorReporter.getErrorHandler(); + fLocale = fErrorReporter.getLocale(); + + fValidateAnnotations = componentManager.getFeature(VALIDATE_ANNOTATIONS, false); + fHonourAllSchemaLocations = componentManager.getFeature(HONOUR_ALL_SCHEMALOCATIONS, false); + fNamespaceGrowth = componentManager.getFeature(NAMESPACE_GROWTH, false); + fTolerateDuplicates = componentManager.getFeature(TOLERATE_DUPLICATES, false); + try { - 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 (fErrorHandler != fSchemaParser.getProperty(ERROR_HANDLER)) { + fSchemaParser.setProperty(ERROR_HANDLER, (fErrorHandler != null) ? fErrorHandler : new DefaultErrorHandler()); if (fAnnotationValidator != null) { - fAnnotationValidator.setProperty(ERROR_HANDLER, (currErrorHandler != null) ? currErrorHandler : new DefaultErrorHandler()); + fAnnotationValidator.setProperty(ERROR_HANDLER, (fErrorHandler != null) ? fErrorHandler : new DefaultErrorHandler()); } } - Locale currentLocale = fErrorReporter.getLocale(); - if (currentLocale != fSchemaParser.getProperty(LOCALE)) { - fSchemaParser.setProperty(LOCALE, currentLocale); + if (fLocale != fSchemaParser.getProperty(LOCALE)) { + fSchemaParser.setProperty(LOCALE, fLocale); if (fAnnotationValidator != null) { - fAnnotationValidator.setProperty(LOCALE, currentLocale); + fAnnotationValidator.setProperty(LOCALE, fLocale); } } } catch (XMLConfigurationException e) {} - fValidateAnnotations = componentManager.getFeature(VALIDATE_ANNOTATIONS, false); - fHonourAllSchemaLocations = componentManager.getFeature(HONOUR_ALL_SCHEMALOCATIONS, false); - fNamespaceGrowth = componentManager.getFeature(NAMESPACE_GROWTH, false); - fTolerateDuplicates = componentManager.getFeature(TOLERATE_DUPLICATES, false); - try { - fSchemaParser.setFeature( - CONTINUE_AFTER_FATAL_ERROR, - fErrorReporter.getFeature(CONTINUE_AFTER_FATAL_ERROR)); - } catch (XMLConfigurationException e) { - } + fSchemaParser.setFeature(CONTINUE_AFTER_FATAL_ERROR, fErrorReporter.getFeature(CONTINUE_AFTER_FATAL_ERROR)); + } catch (XMLConfigurationException e) {} try { if (componentManager.getFeature(ALLOW_JAVA_ENCODINGS, false)) { fSchemaParser.setFeature(ALLOW_JAVA_ENCODINGS, true); } - } catch (XMLConfigurationException e) { - } + } catch (XMLConfigurationException e) {} + try { if (componentManager.getFeature(STANDARD_URI_CONFORMANT_FEATURE, false)) { fSchemaParser.setFeature(STANDARD_URI_CONFORMANT_FEATURE, true); } - } catch (XMLConfigurationException e) { - } + } catch (XMLConfigurationException e) {} try { - fGrammarPool = - (XMLGrammarPool) componentManager.getProperty(XMLGRAMMAR_POOL); + fGrammarPool = (XMLGrammarPool) componentManager.getProperty(XMLGRAMMAR_POOL); } catch (XMLConfigurationException e) { fGrammarPool = null; } + // security features try { if (componentManager.getFeature(DISALLOW_DOCTYPE, false)) { fSchemaParser.setFeature(DISALLOW_DOCTYPE, true); } - } catch (XMLConfigurationException e) { - } + } catch (XMLConfigurationException e) {} + try { - Object security = componentManager.getProperty(SECURITY_MANAGER, null); - if (security != null){ - fSchemaParser.setProperty(SECURITY_MANAGER, security); + if (fSecurityManager != null) { + fSchemaParser.setProperty(SECURITY_MANAGER, fSecurityManager); } - } catch (XMLConfigurationException e) { - } + } catch (XMLConfigurationException e) {} - XMLSecurityPropertyManager securityPropertyMgr = (XMLSecurityPropertyManager) - componentManager.getProperty(XML_SECURITY_PROPERTY_MANAGER); - //Passing on the setting to the parser - fSchemaParser.setProperty(XML_SECURITY_PROPERTY_MANAGER, securityPropertyMgr); + fSecurityPropertyMgr = (XMLSecurityPropertyManager) componentManager.getProperty(XML_SECURITY_PROPERTY_MANAGER); - fAccessExternalDTD = securityPropertyMgr.getValue( - XMLSecurityPropertyManager.Property.ACCESS_EXTERNAL_DTD); + //Passing on the setting to the parser + fSchemaParser.setProperty(XML_SECURITY_PROPERTY_MANAGER, fSecurityPropertyMgr); - fAccessExternalSchema = securityPropertyMgr.getValue( - XMLSecurityPropertyManager.Property.ACCESS_EXTERNAL_SCHEMA); + fAccessExternalDTD = fSecurityPropertyMgr.getValue(XMLSecurityPropertyManager.Property.ACCESS_EXTERNAL_DTD); + fAccessExternalSchema = fSecurityPropertyMgr.getValue(XMLSecurityPropertyManager.Property.ACCESS_EXTERNAL_SCHEMA); } // reset(XMLComponentManager) @@ -4051,7 +4049,7 @@ public class XSDHandler { 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 // 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; } // obviously the requesting doc didn't include, redefine or @@ -4072,9 +4070,9 @@ public class XSDHandler { if (DOMUtil.isHidden(startSchema.fSchemaElement, fHiddenNodes)) { // make it visible DOMUtil.setVisible(startSchema.fSchemaElement, fHiddenNodes); - Vector dependingSchemas = (Vector)fDependencyMap.get(startSchema); + Vector dependingSchemas = fDependencyMap.get(startSchema); 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 @@ -4107,7 +4105,7 @@ public class XSDHandler { ElementImpl ele = (ElementImpl)e; // get system id from document object 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 int line = ele.getLineNumber(); int column = ele.getColumnNumber(); diff --git a/jaxp/src/java.xml/share/classes/com/sun/org/apache/xerces/internal/parsers/XML11Configuration.java b/jaxp/src/java.xml/share/classes/com/sun/org/apache/xerces/internal/parsers/XML11Configuration.java index 459067067a1..3c4dd4f810e 100644 --- a/jaxp/src/java.xml/share/classes/com/sun/org/apache/xerces/internal/parsers/XML11Configuration.java +++ b/jaxp/src/java.xml/share/classes/com/sun/org/apache/xerces/internal/parsers/XML11Configuration.java @@ -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 @@ -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.PropertyState; 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.xni.XMLDTDContentModelHandler; import com.sun.org.apache.xerces.internal.xni.XMLDTDHandler; @@ -166,59 +165,57 @@ public class XML11Configuration extends ParserConfigurationSettings protected static final String USE_GRAMMAR_POOL_ONLY = Constants.XERCES_FEATURE_PREFIX + Constants.USE_GRAMMAR_POOL_ONLY_FEATURE; - // feature identifiers + // feature identifiers - /** Feature identifier: validation. */ - protected static final String VALIDATION = - Constants.SAX_FEATURE_PREFIX + Constants.VALIDATION_FEATURE; + /** Feature identifier: validation. */ + protected static final String VALIDATION = + Constants.SAX_FEATURE_PREFIX + Constants.VALIDATION_FEATURE; - /** Feature identifier: namespaces. */ - protected static final String NAMESPACES = - Constants.SAX_FEATURE_PREFIX + Constants.NAMESPACES_FEATURE; + /** Feature identifier: namespaces. */ + protected static final String NAMESPACES = + Constants.SAX_FEATURE_PREFIX + Constants.NAMESPACES_FEATURE; - /** Feature identifier: external general entities. */ - protected static final String EXTERNAL_GENERAL_ENTITIES = - Constants.SAX_FEATURE_PREFIX + Constants.EXTERNAL_GENERAL_ENTITIES_FEATURE; + /** Feature identifier: external general entities. */ + protected static final String EXTERNAL_GENERAL_ENTITIES = + Constants.SAX_FEATURE_PREFIX + Constants.EXTERNAL_GENERAL_ENTITIES_FEATURE; - /** Feature identifier: external parameter entities. */ - protected static final String EXTERNAL_PARAMETER_ENTITIES = - Constants.SAX_FEATURE_PREFIX + Constants.EXTERNAL_PARAMETER_ENTITIES_FEATURE; + /** Feature identifier: external parameter entities. */ + protected static final String EXTERNAL_PARAMETER_ENTITIES = + Constants.SAX_FEATURE_PREFIX + Constants.EXTERNAL_PARAMETER_ENTITIES_FEATURE; - /** Feature identifier: whether to ignore xsi:type attributes until a global element declaration is encountered */ - protected static final String IGNORE_XSI_TYPE = - Constants.XERCES_FEATURE_PREFIX + Constants.IGNORE_XSI_TYPE_FEATURE; + /** Feature identifier: whether to ignore xsi:type attributes until a global element declaration is encountered */ + protected static final String IGNORE_XSI_TYPE = + Constants.XERCES_FEATURE_PREFIX + Constants.IGNORE_XSI_TYPE_FEATURE; - /** Feature identifier: whether to ignore ID/IDREF errors */ - protected static final String ID_IDREF_CHECKING = - Constants.XERCES_FEATURE_PREFIX + Constants.ID_IDREF_CHECKING_FEATURE; + /** Feature identifier: whether to ignore ID/IDREF errors */ + protected static final String ID_IDREF_CHECKING = + Constants.XERCES_FEATURE_PREFIX + Constants.ID_IDREF_CHECKING_FEATURE; - /** Feature identifier: whether to ignore unparsed entity errors */ - protected static final String UNPARSED_ENTITY_CHECKING = - Constants.XERCES_FEATURE_PREFIX + Constants.UNPARSED_ENTITY_CHECKING_FEATURE; + /** Feature identifier: whether to ignore unparsed entity errors */ + protected static final String UNPARSED_ENTITY_CHECKING = + Constants.XERCES_FEATURE_PREFIX + Constants.UNPARSED_ENTITY_CHECKING_FEATURE; - /** Feature identifier: whether to ignore identity constraint errors */ - protected static final String IDENTITY_CONSTRAINT_CHECKING = - Constants.XERCES_FEATURE_PREFIX + Constants.IDC_CHECKING_FEATURE; + /** Feature identifier: whether to ignore identity constraint errors */ + protected static final String IDENTITY_CONSTRAINT_CHECKING = + Constants.XERCES_FEATURE_PREFIX + Constants.IDC_CHECKING_FEATURE; // property identifiers + /** Property identifier: xml string. */ + protected static final String XML_STRING = + Constants.SAX_PROPERTY_PREFIX + Constants.XML_STRING_PROPERTY; - /** Property identifier: xml string. */ - protected static final String XML_STRING = - Constants.SAX_PROPERTY_PREFIX + Constants.XML_STRING_PROPERTY; - - /** Property identifier: symbol table. */ - protected static final String SYMBOL_TABLE = - Constants.XERCES_PROPERTY_PREFIX + Constants.SYMBOL_TABLE_PROPERTY; - - /** Property identifier: error handler. */ - protected static final String ERROR_HANDLER = - Constants.XERCES_PROPERTY_PREFIX + Constants.ERROR_HANDLER_PROPERTY; + /** Property identifier: symbol table. */ + protected static final String SYMBOL_TABLE = + Constants.XERCES_PROPERTY_PREFIX + Constants.SYMBOL_TABLE_PROPERTY; - /** Property identifier: entity resolver. */ - protected static final String ENTITY_RESOLVER = - Constants.XERCES_PROPERTY_PREFIX + Constants.ENTITY_RESOLVER_PROPERTY; + /** Property identifier: error handler. */ + protected static final String ERROR_HANDLER = + Constants.XERCES_PROPERTY_PREFIX + Constants.ERROR_HANDLER_PROPERTY; + /** Property identifier: entity resolver. */ + protected static final String ENTITY_RESOLVER = + Constants.XERCES_PROPERTY_PREFIX + Constants.ENTITY_RESOLVER_PROPERTY; /** Property identifier: XML Schema validator. */ protected static final String SCHEMA_VALIDATOR = @@ -232,8 +229,6 @@ public class XML11Configuration extends ParserConfigurationSettings protected static final String SCHEMA_NONS_LOCATION = Constants.XERCES_PROPERTY_PREFIX + Constants.SCHEMA_NONS_LOCATION; - // property identifiers - /** Property identifier: error reporter. */ protected static final String ERROR_REPORTER = Constants.XERCES_PROPERTY_PREFIX + Constants.ERROR_REPORTER_PROPERTY; @@ -313,33 +308,33 @@ public class XML11Configuration extends ParserConfigurationSettings // Data // - protected SymbolTable fSymbolTable; + protected SymbolTable fSymbolTable; protected XMLInputSource fInputSource; protected ValidationManager fValidationManager; - protected XMLVersionDetector fVersionDetector; + protected XMLVersionDetector fVersionDetector; protected XMLLocator fLocator; - protected Locale fLocale; + protected Locale fLocale; - /** XML 1.0 Components. */ - protected ArrayList fComponents; + /** XML 1.0 Components. */ + protected ArrayList fComponents; - /** XML 1.1. Components. */ - protected ArrayList fXML11Components = null; + /** XML 1.1. Components. */ + protected ArrayList fXML11Components = null; - /** Common components: XMLEntityManager, XMLErrorReporter, XMLSchemaValidator */ - protected ArrayList fCommonComponents = null; + /** Common components: XMLEntityManager, XMLErrorReporter, XMLSchemaValidator */ + protected ArrayList fCommonComponents = null; - /** The document handler. */ - protected XMLDocumentHandler fDocumentHandler; + /** The document handler. */ + protected XMLDocumentHandler fDocumentHandler; - /** The DTD handler. */ - protected XMLDTDHandler fDTDHandler; + /** The DTD handler. */ + protected XMLDTDHandler fDTDHandler; - /** The DTD content model handler. */ - protected XMLDTDContentModelHandler fDTDContentModelHandler; + /** The DTD content model handler. */ + protected XMLDTDContentModelHandler fDTDContentModelHandler; - /** Last component in the document pipeline */ - protected XMLDocumentSource fLastComponent; + /** Last component in the document pipeline */ + protected XMLDocumentSource fLastComponent; /** * True if a parse is in progress. This state is needed because @@ -477,15 +472,15 @@ public class XML11Configuration extends ParserConfigurationSettings // create a vector to hold all the components in use // XML 1.0 specialized components - fComponents = new ArrayList(); + fComponents = new ArrayList<>(); // XML 1.1 specialized components - fXML11Components = new ArrayList(); + fXML11Components = new ArrayList<>(); // Common components for XML 1.1. and XML 1.0 - fCommonComponents = new ArrayList(); + fCommonComponents = new ArrayList<>(); // create table for features and properties - fFeatures = new HashMap(); - fProperties = new HashMap(); + fFeatures = new HashMap<>(); + fProperties = new HashMap<>(); // add default recognized features final String[] recognizedFeatures = @@ -580,35 +575,35 @@ public class XML11Configuration extends ParserConfigurationSettings } fEntityManager = new XMLEntityManager(); - fProperties.put(ENTITY_MANAGER, fEntityManager); + fProperties.put(ENTITY_MANAGER, fEntityManager); addCommonComponent(fEntityManager); fErrorReporter = new XMLErrorReporter(); fErrorReporter.setDocumentLocator(fEntityManager.getEntityScanner()); - fProperties.put(ERROR_REPORTER, fErrorReporter); + fProperties.put(ERROR_REPORTER, fErrorReporter); addCommonComponent(fErrorReporter); fNamespaceScanner = new XMLNSDocumentScannerImpl(); - fProperties.put(DOCUMENT_SCANNER, fNamespaceScanner); + fProperties.put(DOCUMENT_SCANNER, fNamespaceScanner); addComponent((XMLComponent) fNamespaceScanner); fDTDScanner = new XMLDTDScannerImpl(); - fProperties.put(DTD_SCANNER, fDTDScanner); + fProperties.put(DTD_SCANNER, fDTDScanner); addComponent((XMLComponent) fDTDScanner); fDTDProcessor = new XMLDTDProcessor(); - fProperties.put(DTD_PROCESSOR, fDTDProcessor); + fProperties.put(DTD_PROCESSOR, fDTDProcessor); addComponent((XMLComponent) fDTDProcessor); fDTDValidator = new XMLNSDTDValidator(); - fProperties.put(DTD_VALIDATOR, fDTDValidator); + fProperties.put(DTD_VALIDATOR, fDTDValidator); addComponent(fDTDValidator); fDatatypeValidatorFactory = DTDDVFactory.getInstance(); - fProperties.put(DATATYPE_VALIDATOR_FACTORY, fDatatypeValidatorFactory); + fProperties.put(DATATYPE_VALIDATOR_FACTORY, fDatatypeValidatorFactory); fValidationManager = new ValidationManager(); - fProperties.put(VALIDATION_MANAGER, fValidationManager); + fProperties.put(VALIDATION_MANAGER, fValidationManager); fVersionDetector = new XMLVersionDetector(); @@ -935,20 +930,20 @@ public class XML11Configuration extends ParserConfigurationSettings // forward to every XML 1.0 component int count = fComponents.size(); for (int i = 0; i < count; i++) { - XMLComponent c = (XMLComponent) fComponents.get(i); + XMLComponent c = fComponents.get(i); c.setFeature(featureId, state); } // forward it to common components count = fCommonComponents.size(); for (int i = 0; i < count; i++) { - XMLComponent c = (XMLComponent) fCommonComponents.get(i); + XMLComponent c = fCommonComponents.get(i); c.setFeature(featureId, state); } // forward to every XML 1.1 component count = fXML11Components.size(); for (int i = 0; i < count; i++) { - XMLComponent c = (XMLComponent) fXML11Components.get(i); + XMLComponent c = fXML11Components.get(i); try{ c.setFeature(featureId, state); } @@ -996,19 +991,19 @@ public class XML11Configuration extends ParserConfigurationSettings // forward to every XML 1.0 component int count = fComponents.size(); for (int i = 0; i < count; i++) { - XMLComponent c = (XMLComponent) fComponents.get(i); + XMLComponent c = fComponents.get(i); c.setProperty(propertyId, value); } // forward it to every common Component count = fCommonComponents.size(); for (int i = 0; i < count; i++) { - XMLComponent c = (XMLComponent) fCommonComponents.get(i); + XMLComponent c = fCommonComponents.get(i); c.setProperty(propertyId, value); } // forward it to every XML 1.1 component count = fXML11Components.size(); for (int i = 0; i < count; i++) { - XMLComponent c = (XMLComponent) fXML11Components.get(i); + XMLComponent c = fXML11Components.get(i); try{ c.setProperty(propertyId, value); } @@ -1034,7 +1029,7 @@ public class XML11Configuration extends ParserConfigurationSettings protected void reset() throws XNIException { int count = fComponents.size(); for (int i = 0; i < count; i++) { - XMLComponent c = (XMLComponent) fComponents.get(i); + XMLComponent c = fComponents.get(i); c.reset(this); } @@ -1047,7 +1042,7 @@ public class XML11Configuration extends ParserConfigurationSettings // reset common components int count = fCommonComponents.size(); for (int i = 0; i < count; i++) { - XMLComponent c = (XMLComponent) fCommonComponents.get(i); + XMLComponent c = fCommonComponents.get(i); c.reset(this); } @@ -1061,7 +1056,7 @@ public class XML11Configuration extends ParserConfigurationSettings // reset every component int count = fXML11Components.size(); for (int i = 0; i < count; i++) { - XMLComponent c = (XMLComponent) fXML11Components.get(i); + XMLComponent c = fXML11Components.get(i); c.reset(this); } diff --git a/jaxp/src/java.xml/share/classes/com/sun/org/apache/xerces/internal/util/HTTPInputSource.java b/jaxp/src/java.xml/share/classes/com/sun/org/apache/xerces/internal/util/HTTPInputSource.java index f4e29a3a856..bdd0750d0fa 100644 --- a/jaxp/src/java.xml/share/classes/com/sun/org/apache/xerces/internal/util/HTTPInputSource.java +++ b/jaxp/src/java.xml/share/classes/com/sun/org/apache/xerces/internal/util/HTTPInputSource.java @@ -51,7 +51,7 @@ public final class HTTPInputSource extends XMLInputSource { protected boolean fFollowRedirects = true; /** HTTP request properties. **/ - protected Map fHTTPRequestProperties = new HashMap(); + protected Map fHTTPRequestProperties = new HashMap<>(); // // Constructors @@ -159,7 +159,7 @@ public final class HTTPInputSource extends XMLInputSource { * been set */ public String getHTTPRequestProperty(String key) { - return (String) fHTTPRequestProperties.get(key); + return fHTTPRequestProperties.get(key); } // getHTTPRequestProperty(String):String /** @@ -172,7 +172,7 @@ public final class HTTPInputSource extends XMLInputSource { * @return an iterator for the request properties this * input source contains */ - public Iterator getHTTPRequestProperties() { + public Iterator> getHTTPRequestProperties() { return fHTTPRequestProperties.entrySet().iterator(); } // getHTTPRequestProperties():Iterator diff --git a/jaxp/test/javax/xml/jaxp/unittest/validation/Bug8149915.xsd b/jaxp/test/javax/xml/jaxp/unittest/validation/Bug8149915.xsd new file mode 100644 index 00000000000..872033f5d1a --- /dev/null +++ b/jaxp/test/javax/xml/jaxp/unittest/validation/Bug8149915.xsd @@ -0,0 +1,7 @@ + + + + Testapp for XSD annotation issue + This is an XSD annotation, just for the sake of it. + + diff --git a/jaxp/test/javax/xml/jaxp/unittest/validation/SchemaTest.java b/jaxp/test/javax/xml/jaxp/unittest/validation/SchemaTest.java new file mode 100644 index 00000000000..f8a5e62ac55 --- /dev/null +++ b/jaxp/test/javax/xml/jaxp/unittest/validation/SchemaTest.java @@ -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())); + } +} -- cgit v1.2.3 From 4087262c5886bc9170b6de029af1ad0ae89532be Mon Sep 17 00:00:00 2001 From: Christoph Langer Date: Wed, 24 Feb 2016 19:25:16 +0300 Subject: 8150470: JCK: api/xsl/conf/copy/copy19 test failure Reviewed-by: joehw, aefimov --- .../com/sun/org/apache/xerces/internal/impl/XMLEntityManager.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'jaxp') diff --git a/jaxp/src/java.xml/share/classes/com/sun/org/apache/xerces/internal/impl/XMLEntityManager.java b/jaxp/src/java.xml/share/classes/com/sun/org/apache/xerces/internal/impl/XMLEntityManager.java index f08a1275dfa..d405a33cdcd 100644 --- a/jaxp/src/java.xml/share/classes/com/sun/org/apache/xerces/internal/impl/XMLEntityManager.java +++ b/jaxp/src/java.xml/share/classes/com/sun/org/apache/xerces/internal/impl/XMLEntityManager.java @@ -2959,7 +2959,7 @@ public class XMLEntityManager implements XMLComponent, XMLEntityResolver { if (!fCurrentEntity.xmlDeclChunkRead) { fCurrentEntity.xmlDeclChunkRead = true; - len = DEFAULT_XMLDECL_BUFFER_SIZE; + len = Entity.ScannedEntity.DEFAULT_XMLDECL_BUFFER_SIZE; } return fInputStream.read(b, off, len); } -- cgit v1.2.3