1 /* 2 * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 24 package sax; 25 26 import java.io.StringReader; 27 28 import javax.xml.parsers.SAXParser; 29 import javax.xml.parsers.SAXParserFactory; 30 31 import org.testng.Assert; 32 import org.testng.annotations.Listeners; 33 import org.testng.annotations.Test; 34 import org.xml.sax.InputSource; 35 import org.xml.sax.helpers.DefaultHandler; 36 37 /* 38 * @test 39 * @bug 8173390 40 * @library /javax/xml/jaxp/libs /javax/xml/jaxp/unittest 41 * @run testng/othervm -DrunSecMngr=true sax.SymbolTableResetTest 42 * @run testng/othervm sax.SymbolTableResetTest 43 * @summary Test that SAXParser reallocates symbol table during 44 * subsequent parse operations 45 */ 46 @Listeners({jaxp.library.BasePolicy.class}) 47 public class SymbolTableResetTest { 48 49 /* 50 * Test mimics the SAXParser usage in SAAJ-RI that reuses the 51 * parsers from the internal pool. To avoid memory leaks, symbol 52 * table associated with the parser should be reallocated during each 53 * parse() operation. 54 */ 55 @Test 56 public void testReset() throws Exception { 57 // Dummy xml input for parser 58 String input = "<dummy>Test</dummy>"; 59 // Create SAXParser 60 SAXParserFactory spf = SAXParserFactory.newInstance(); 61 SAXParser p = spf.newSAXParser(); 62 // First parse iteration 63 p.parse(new InputSource(new StringReader(input)), new DefaultHandler()); 64 // Get first symbol table reference 65 Object symTable1 = p.getProperty(SYMBOL_TABLE_PROPERTY); 66 p.reset(); 67 // Second parse iteration 68 p.parse(new InputSource(new StringReader(input)), new DefaultHandler()); 69 // Get second symbol table reference 70 Object symTable2 = p.getProperty(SYMBOL_TABLE_PROPERTY); 71 // Output symbol table references to log 72 System.out.println("Symbol table reference after first parse operation:"+symTable1); 73 System.out.println("Symbol table reference after second parse operation:"+symTable2); 74 // Symbol table references should be different 75 Assert.assertNotEquals(symTable1, symTable2, "Symbol table refence is the same"); 76 } 77 78 // Symbol table property 79 private static final String SYMBOL_TABLE_PROPERTY = "http://apache.org/xml/properties/internal/symbol-table"; 80 81 }