8288436: Improve Xalan supports

Reviewed-by: andrew
Backport-of: 6899dff264c9030a3016e292c3f3f6738bde97cc
This commit is contained in:
Martin Balao 2023-03-02 19:58:00 -05:00 committed by Andrew John Hughes
parent 1cf3efb037
commit f7f196685f

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2007, 2022, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2007, 2023, Oracle and/or its affiliates. All rights reserved.
*/
/*
* Copyright 1999-2004 The Apache Software Foundation.
@ -16,9 +16,6 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
* $Id: XMLReaderManager.java,v 1.2.4.1 2005/09/15 08:16:02 suresh_emailid Exp $
*/
package com.sun.org.apache.xml.internal.utils;
import com.sun.org.apache.xalan.internal.XalanConstants;
@ -29,17 +26,23 @@ import javax.xml.XMLConstants;
import jdk.xml.internal.JdkXmlUtils;
import jdk.xml.internal.XMLSecurityManager;
import org.xml.sax.SAXException;
import org.xml.sax.SAXNotRecognizedException;
import org.xml.sax.SAXNotSupportedException;
import org.xml.sax.XMLReader;
/**
* Creates XMLReader objects and caches them for re-use.
* This class follows the singleton pattern.
*
* @LastModified: Jan 2023
*/
public class XMLReaderManager {
private static final XMLReaderManager m_singletonManager =
new XMLReaderManager();
private static final String property = "org.xml.sax.driver";
private final static String LEXICAL_HANDLER_PROPERTY =
"http://xml.org/sax/properties/lexical-handler";
/**
* Cache of XMLReader objects
@ -159,12 +162,22 @@ public class XMLReaderManager {
*/
public synchronized void releaseXMLReader(XMLReader reader) {
// If the reader that's being released is the cached reader
// for this thread, remove it from the m_isUse list.
// for this thread, remove it from the m_inUse list.
ReaderWrapper rw = m_readers.get();
if (rw.reader == reader && reader != null) {
if (rw != null && rw.reader == reader && reader != null) {
// reset the reader for reuse
reader.setContentHandler(null);
reader.setDTDHandler(null);
reader.setEntityResolver(null);
try {
reader.setProperty(LEXICAL_HANDLER_PROPERTY, null);
} catch (SAXNotRecognizedException | SAXNotSupportedException ex) {
// shouldn't happen as the property is supported.
}
m_inUse.remove(reader);
}
}
/**
* Return the state of the services mechanism feature.
*/