changeset 59299:748fedeb7cc1

8209774: Refactor shell test javax/xml/jaxp/common/8035437/run.sh to java Reviewed-by: dfuchs, joehw, alanb Contributed-by: Fernando Guallini <fernando.guallini@oracle.com>
author fyuan
date Fri, 15 May 2020 09:49:54 +0800
parents bf77476840f1
children b3a871b1dc3f
files test/jdk/javax/xml/jaxp/common/8035437/AbstractMethodErrorTest.java test/jdk/javax/xml/jaxp/common/8035437/com/sun/org/apache/xerces/internal/dom/DocumentImpl.java test/jdk/javax/xml/jaxp/common/8035437/org/w3c/dom/Document.java test/jdk/javax/xml/jaxp/common/8035437/org/w3c/dom/Node.java test/jdk/javax/xml/jaxp/common/8035437/patch-src1/org/w3c/dom/Document.java test/jdk/javax/xml/jaxp/common/8035437/patch-src1/org/w3c/dom/Node.java test/jdk/javax/xml/jaxp/common/8035437/patch-src2/com/sun/org/apache/xerces/internal/dom/DocumentImpl.java test/jdk/javax/xml/jaxp/common/8035437/run.sh
diffstat 8 files changed, 155 insertions(+), 215 deletions(-) [+]
line wrap: on
line diff
--- a/test/jdk/javax/xml/jaxp/common/8035437/AbstractMethodErrorTest.java	Thu May 14 17:05:41 2020 -0700
+++ b/test/jdk/javax/xml/jaxp/common/8035437/AbstractMethodErrorTest.java	Fri May 15 09:49:54 2020 +0800
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2014, 2020, 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
@@ -28,7 +28,26 @@
 import org.w3c.dom.ls.DOMImplementationLS;
 import org.w3c.dom.ls.LSSerializer;
 
-class AbstractMethodErrorTest {
+/*
+ * @test
+ * @bug 8035437
+ * @summary Verifies that java.lang.AbstractMethodError is not thrown when
+ *          serializing improper version of DocumentImpl class as reported in XERCESJ-1007.
+ *          Test preconditions and steps:
+ *          - Compiles test version of org.w3c.dom.Node and org.w3c.dom.Document
+ *          - Compiles DocumentImpl overriding java.xml module with Node and Document
+ *          - Runs AbstractMethodErrorTest overriding java.xml only with DocumentImpl class
+ *            Hence, the interfaces compiled in the first step need to be removed
+ *            from the test folder in order to reproduce the bug scenario. At the time of writing,
+ *            the clean command was not able to resolve paths generated by compile/module
+ * @library /test/lib
+ * @compile --patch-module java.xml=${test.src} org/w3c/dom/Document.java
+ * org/w3c/dom/Node.java com/sun/org/apache/xerces/internal/dom/DocumentImpl.java
+ * @clean org.w3c.dom.*
+ * @run main/othervm --patch-module java.xml=${test.class.path} AbstractMethodErrorTest
+ */
+
+public class AbstractMethodErrorTest {
 
     public static void main(String[] args) throws Exception {
         DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
@@ -39,11 +58,7 @@
         DOMImplementationLS implLS = (DOMImplementationLS) impl.getFeature("LS", "3.0");
         LSSerializer dsi = implLS.createLSSerializer();
 
-        /* We should have here incorrect document without getXmlVersion() method:
-         * Such Document is generated by replacing the JDK bootclasses with it's
-         * own Node,Document and DocumentImpl classes (see run.sh). According to
-         * XERCESJ-1007 the AbstractMethodError should be thrown in such case.
-         */
+        // We should have here incorrect document without getXmlVersion() method
         String result = dsi.writeToString(document);
         System.out.println("Result:" + result);
     }
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/jdk/javax/xml/jaxp/common/8035437/com/sun/org/apache/xerces/internal/dom/DocumentImpl.java	Fri May 15 09:49:54 2020 +0800
@@ -0,0 +1,67 @@
+/*
+ * Copyright (c) 2014, 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 com.sun.org.apache.xerces.internal.dom;
+
+import org.w3c.dom.Document;
+import org.w3c.dom.Node;
+import org.w3c.dom.DOMImplementation;
+
+public class DocumentImpl implements Document, Node {
+
+    public short getNodeType() {
+        return 9; //DOCUMENT_NODE = 9
+    }
+
+    public org.w3c.dom.Document getOwnerDocument() {
+        return null;
+    }
+
+    public Node getFirstChild() {
+        return null;
+    }
+
+    public String getPrefix() {
+        return "TestPrefix";
+    }
+
+    public String getLocalName() {
+        return "LocalName";
+    }
+
+    public boolean hasAttributes() {
+        return false;
+    }
+
+    public Node renameNode(Node n, String namespaceURI, String name) {
+        return n;
+    }
+
+    public org.w3c.dom.DocumentType getDoctype() {
+        return null;
+    }
+
+    public DOMImplementation getImplementation() {
+        return DOMImplementationImpl.getDOMImplementation();
+    }
+
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/jdk/javax/xml/jaxp/common/8035437/org/w3c/dom/Document.java	Fri May 15 09:49:54 2020 +0800
@@ -0,0 +1,28 @@
+/*
+ * Copyright (c) 2014, 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 org.w3c.dom;
+
+public interface Document {
+
+    public org.w3c.dom.DocumentType getDoctype();
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/jdk/javax/xml/jaxp/common/8035437/org/w3c/dom/Node.java	Fri May 15 09:49:54 2020 +0800
@@ -0,0 +1,38 @@
+/*
+ * Copyright (c) 2014, 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 org.w3c.dom;
+
+public interface Node {
+
+    public short getNodeType();
+
+    public org.w3c.dom.Document getOwnerDocument();
+
+    public Node getFirstChild();
+
+    public String getPrefix();
+
+    public String getLocalName();
+
+    public boolean hasAttributes();
+}
--- a/test/jdk/javax/xml/jaxp/common/8035437/patch-src1/org/w3c/dom/Document.java	Thu May 14 17:05:41 2020 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,28 +0,0 @@
-/*
- * Copyright (c) 2014, 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 org.w3c.dom;
-
-public interface Document {
-
-    public org.w3c.dom.DocumentType getDoctype();
-}
--- a/test/jdk/javax/xml/jaxp/common/8035437/patch-src1/org/w3c/dom/Node.java	Thu May 14 17:05:41 2020 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,38 +0,0 @@
-/*
- * Copyright (c) 2014, 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 org.w3c.dom;
-
-public interface Node {
-
-    public short getNodeType();
-
-    public org.w3c.dom.Document getOwnerDocument();
-
-    public Node getFirstChild();
-
-    public String getPrefix();
-
-    public String getLocalName();
-
-    public boolean hasAttributes();
-}
--- a/test/jdk/javax/xml/jaxp/common/8035437/patch-src2/com/sun/org/apache/xerces/internal/dom/DocumentImpl.java	Thu May 14 17:05:41 2020 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,67 +0,0 @@
-/*
- * Copyright (c) 2014, 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 com.sun.org.apache.xerces.internal.dom;
-
-import org.w3c.dom.Document;
-import org.w3c.dom.Node;
-import org.w3c.dom.DOMImplementation;
-
-public class DocumentImpl implements Document, Node {
-
-    public short getNodeType() {
-        return 9; //DOCUMENT_NODE = 9
-    }
-
-    public org.w3c.dom.Document getOwnerDocument() {
-        return null;
-    }
-
-    public Node getFirstChild() {
-        return null;
-    }
-
-    public String getPrefix() {
-        return "TestPrefix";
-    }
-
-    public String getLocalName() {
-        return "LocalName";
-    }
-
-    public boolean hasAttributes() {
-        return false;
-    }
-
-    public Node renameNode(Node n, String namespaceURI, String name) {
-        return n;
-    }
-
-    public org.w3c.dom.DocumentType getDoctype() {
-        return null;
-    }
-
-    public DOMImplementation getImplementation() {
-        return DOMImplementationImpl.getDOMImplementation();
-    }
-
-}
--- a/test/jdk/javax/xml/jaxp/common/8035437/run.sh	Thu May 14 17:05:41 2020 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,75 +0,0 @@
-#!/bin/sh
-
-##
-# Copyright (c) 2014, 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.
-##
-
-# @test
-# @bug 8035437
-# @summary Tests that java.lang.AbstractMethodError is not thrown when
-#    serializing improper version of DocumentImpl class.
-
-OS=`uname -s`
-case "$OS" in
-  SunOS )
-    PS=":"
-    ;;
-  Linux )
-    PS=":"
-    ;;
-  Darwin )
-    PS=":"
-    ;;
-  AIX )
-    PS=":"
-    ;;
-  Windows*)
-    PS=";"
-    ;;
-  CYGWIN*)
-    PS=";"
-    ;;
-  * )
-    echo "Unrecognized system!"
-    exit 1;
-    ;;
-esac
-
-mkdir -p exec/java.xml compile/java.xml
-
-$COMPILEJAVA/bin/javac ${TESTJAVACOPTS} ${TESTTOOLVMOPTS} \
-   -d compile/java.xml --patch-module java.xml=$TESTSRC/patch-src1 \
-   $TESTSRC/patch-src1/org/w3c/dom/Document.java \
-   $TESTSRC/patch-src1/org/w3c/dom/Node.java || exit 1
-
-$COMPILEJAVA/bin/javac ${TESTJAVACOPTS} ${TESTTOOLVMOPTS} \
-   -d exec/java.xml --patch-module java.xml=compile/java.xml${PS}$TESTSRC/patch-src2 \
-   $TESTSRC/patch-src2/com/sun/org/apache/xerces/internal/dom/DocumentImpl.java \
-   || exit 2
-
-$COMPILEJAVA/bin/javac ${TESTJAVACOPTS} ${TESTTOOLVMOPTS} \
-   $TESTSRC/AbstractMethodErrorTest.java -d exec || exit 3
-
-$TESTJAVA/bin/java ${TESTVMOPTS} --patch-module java.xml=exec -cp exec AbstractMethodErrorTest || exit 4
-
-exit 0
-