--- old/src/java.xml/share/classes/com/sun/org/apache/xerces/internal/parsers/XML11Configuration.java 2017-02-15 18:49:28.870956646 +0300 +++ new/src/java.xml/share/classes/com/sun/org/apache/xerces/internal/parsers/XML11Configuration.java 2017-02-15 18:49:28.762956649 +0300 @@ -415,9 +415,12 @@ /** Current DTD scanner. */ protected XMLDTDScanner fCurrentDTDScanner; - /** Flag indiciating whether XML11 components have been initialized. */ + /** Flag indicating whether XML11 components have been initialized. */ private boolean f11Initialized = false; + /** Flag indicating whether the symbol table instance was specified during construction **/ + private boolean fSymbolTableProvided = false; + // // Constructors // @@ -566,15 +569,18 @@ }; addRecognizedProperties(recognizedProperties); - if (symbolTable == null) { - symbolTable = new SymbolTable(); + // Remember if symbolTable was provided from outside + fSymbolTableProvided = symbolTable != null; + if (!fSymbolTableProvided) { + fSymbolTable = new SymbolTable(); + } else { + fSymbolTable = symbolTable; } - fSymbolTable = symbolTable; fProperties.put(SYMBOL_TABLE, fSymbolTable); fGrammarPool = grammarPool; if (fGrammarPool != null) { - fProperties.put(XMLGRAMMAR_POOL, fGrammarPool); + fProperties.put(XMLGRAMMAR_POOL, fGrammarPool); } fEntityManager = new XMLEntityManager(); @@ -840,6 +846,13 @@ fValidationManager.reset(); fVersionDetector.reset(this); fConfigUpdated = true; + + // Reset the symbol table if it wasn't provided during construction + if (!fSymbolTableProvided) { + fSymbolTable = new SymbolTable(); + } + fProperties.put(SYMBOL_TABLE, fSymbolTable); + resetCommon(); short version = fVersionDetector.determineDocVersion(fInputSource); --- /dev/null 2017-02-15 13:45:39.063316729 +0300 +++ new/test/javax/xml/jaxp/unittest/sax/SymbolTableResetTest.java 2017-02-15 18:49:29.342956637 +0300 @@ -0,0 +1,81 @@ +/* + * Copyright (c) 2017, 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 sax; + +import java.io.StringReader; + +import javax.xml.parsers.SAXParser; +import javax.xml.parsers.SAXParserFactory; + +import org.testng.Assert; +import org.testng.annotations.Listeners; +import org.testng.annotations.Test; +import org.xml.sax.InputSource; +import org.xml.sax.helpers.DefaultHandler; + +/* + * @test + * @bug 8173390 + * @library /javax/xml/jaxp/libs /javax/xml/jaxp/unittest + * @run testng/othervm -DrunSecMngr=true sax.SymbolTableResetTest + * @run testng/othervm sax.SymbolTableResetTest + * @summary Test that SAXParser reallocates symbol table during + * subsequent parse operations + */ +@Listeners({jaxp.library.BasePolicy.class}) +public class SymbolTableResetTest { + + /* + * Test mimics the SAXParser usage in SAAJ-RI that reuses the + * parsers from the internal pool. To avoid memory leaks, symbol + * table associated with the parser should be reallocated during each + * parse() operation. + */ + @Test + public void testReset() throws Exception { + // Dummy xml input for parser + String input = "Test"; + // Create SAXParser + SAXParserFactory spf = SAXParserFactory.newInstance(); + SAXParser p = spf.newSAXParser(); + // First parse iteration + p.parse(new InputSource(new StringReader(input)), new DefaultHandler()); + // Get first symbol table reference + Object symTable1 = p.getProperty(SYMBOL_TABLE_PROPERTY); + p.reset(); + // Second parse iteration + p.parse(new InputSource(new StringReader(input)), new DefaultHandler()); + // Get second symbol table reference + Object symTable2 = p.getProperty(SYMBOL_TABLE_PROPERTY); + // Output symbol table references to log + System.out.println("Symbol table reference after first parse operation:"+symTable1); + System.out.println("Symbol table reference after second parse operation:"+symTable2); + // Symbol table references should be different + Assert.assertNotEquals(symTable1, symTable2, "Symbol table refence is the same"); + } + + // Symbol table property + private static final String SYMBOL_TABLE_PROPERTY = "http://apache.org/xml/properties/internal/symbol-table"; + +}