Path: blob/master/test/jdk/javax/xml/jaxp/common/8035437/AbstractMethodErrorTest.java
41154 views
/*1* Copyright (c) 2014, 2020, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223import javax.xml.parsers.DocumentBuilder;24import javax.xml.parsers.DocumentBuilderFactory;25import org.w3c.dom.DOMImplementation;26import org.w3c.dom.Document;27import org.w3c.dom.ls.DOMImplementationLS;28import org.w3c.dom.ls.LSSerializer;2930/*31* @test32* @bug 803543733* @summary Verifies that java.lang.AbstractMethodError is not thrown when34* serializing improper version of DocumentImpl class as reported in XERCESJ-1007.35* Test preconditions and steps:36* - Compiles test version of org.w3c.dom.Node and org.w3c.dom.Document37* - Compiles DocumentImpl overriding java.xml module with Node and Document38* - Runs AbstractMethodErrorTest overriding java.xml only with DocumentImpl class39* Hence, the interfaces compiled in the first step need to be removed40* from the test folder in order to reproduce the bug scenario. At the time of writing,41* the clean command was not able to resolve paths generated by compile/module42* @library /test/lib43* @compile --patch-module java.xml=${test.src} org/w3c/dom/Document.java44* org/w3c/dom/Node.java com/sun/org/apache/xerces/internal/dom/DocumentImpl.java45* @clean org.w3c.dom.*46* @run main/othervm --patch-module java.xml=${test.class.path} AbstractMethodErrorTest47*/4849public class AbstractMethodErrorTest {5051public static void main(String[] args) throws Exception {52DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();53DocumentBuilder builder = factory.newDocumentBuilder();54Document document = builder.newDocument();5556DOMImplementation impl = document.getImplementation();57DOMImplementationLS implLS = (DOMImplementationLS) impl.getFeature("LS", "3.0");58LSSerializer dsi = implLS.createLSSerializer();5960// We should have here incorrect document without getXmlVersion() method61String result = dsi.writeToString(document);62System.out.println("Result:" + result);63}6465}666768