8168968: Two jaxp tests failing after JDK-8167646
authorfyuan
Wed, 02 Nov 2016 14:16:13 +0800
changeset 41847 e444f2f9dc8a
parent 41846 dd1e92025fd3
child 41848 64fe0dd6f558
8168968: Two jaxp tests failing after JDK-8167646 Reviewed-by: joehw, weijun
jaxp/test/javax/xml/jaxp/functional/javax/xml/parsers/ptests/SAXParserTest.java
jaxp/test/javax/xml/jaxp/unittest/catalog/CatalogInvalidPathTest.java
jaxp/test/javax/xml/jaxp/unittest/catalog/CatalogTest.java
--- a/jaxp/test/javax/xml/jaxp/functional/javax/xml/parsers/ptests/SAXParserTest.java	Mon Oct 31 09:29:05 2016 -0700
+++ b/jaxp/test/javax/xml/jaxp/functional/javax/xml/parsers/ptests/SAXParserTest.java	Wed Nov 02 14:16:13 2016 +0800
@@ -24,20 +24,16 @@
 package javax.xml.parsers.ptests;
 
 import static javax.xml.parsers.ptests.ParserTestConst.XML_DIR;
-import static jaxp.library.JAXPTestUtilities.USER_DIR;
 import static jaxp.library.JAXPTestUtilities.tryRunWithTmpPermission;
 
 import java.io.File;
 import java.io.FileInputStream;
-import java.io.FilePermission;
 import java.io.IOException;
 import java.util.PropertyPermission;
 
 import javax.xml.parsers.SAXParser;
 import javax.xml.parsers.SAXParserFactory;
 
-import jaxp.library.JAXPTestUtilities;
-
 import org.testng.annotations.DataProvider;
 import org.testng.annotations.Listeners;
 import org.testng.annotations.Test;
@@ -189,8 +185,7 @@
      */
     @Test(expectedExceptions = { SAXException.class, IOException.class }, dataProvider = "parser-provider")
     public void testParse09(SAXParser saxparser) throws Exception {
-        JAXPTestUtilities.tryRunWithTmpPermission(() -> saxparser.parse(" ", new DefaultHandler()),
-                new FilePermission(USER_DIR + " ", "read"));
+        saxparser.parse("no-such-file", new DefaultHandler());
     }
 
     /**
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/jaxp/test/javax/xml/jaxp/unittest/catalog/CatalogInvalidPathTest.java	Wed Nov 02 14:16:13 2016 +0800
@@ -0,0 +1,66 @@
+/*
+ * Copyright (c) 2016, 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 catalog;
+
+import javax.xml.catalog.CatalogFeatures;
+
+import org.testng.annotations.DataProvider;
+import org.testng.annotations.Test;
+
+/*
+ * @test
+ * @bug 8151154
+ * @run testng/othervm catalog.CatalogInvalidPathTest
+ * @summary Verifies that the CatalogFeatures' builder throws
+ *          IllegalArgumentException on invalid file inputs.
+ *          This test was splitted from CatalogTest.java due to
+ *          JDK-8168968, it has to only run without SecurityManager
+ *          because an ACE will be thrown for invalid path.
+ */
+public class CatalogInvalidPathTest {
+    /*
+       DataProvider: for testing the verification of file paths by
+                     the CatalogFeatures builder
+     */
+    @DataProvider(name = "invalidPaths")
+    public Object[][] getFiles() {
+        return new Object[][]{
+            {null},
+            {""},
+            {"file:a/b\\c"},
+            {"file:/../../.."},
+            {"c:/te:t"},
+            {"c:/te?t"},
+            {"c/te*t"},
+            {"in|valid.txt"},
+            {"shema:invalid.txt"},
+        };
+    }
+
+    @Test(dataProvider = "invalidPaths", expectedExceptions = IllegalArgumentException.class)
+    public void testFileInput(String file) {
+        CatalogFeatures features = CatalogFeatures.builder()
+            .with(CatalogFeatures.Feature.FILES, file)
+            .build();
+    }
+}
--- a/jaxp/test/javax/xml/jaxp/unittest/catalog/CatalogTest.java	Mon Oct 31 09:29:05 2016 -0700
+++ b/jaxp/test/javax/xml/jaxp/unittest/catalog/CatalogTest.java	Wed Nov 02 14:16:13 2016 +0800
@@ -23,18 +23,16 @@
 package catalog;
 
 import static jaxp.library.JAXPTestUtilities.clearSystemProperty;
-import static jaxp.library.JAXPTestUtilities.getSystemProperty;
 import static jaxp.library.JAXPTestUtilities.setSystemProperty;
 
 import java.io.File;
 import java.io.FileInputStream;
-import java.io.FilePermission;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.StringReader;
 import java.io.StringWriter;
 import java.nio.file.Paths;
-import java.util.PropertyPermission;
+
 import javax.xml.XMLConstants;
 import javax.xml.catalog.Catalog;
 import javax.xml.catalog.CatalogException;
@@ -57,7 +55,6 @@
 import javax.xml.validation.Schema;
 import javax.xml.validation.SchemaFactory;
 import javax.xml.validation.Validator;
-import jaxp.library.JAXPTestUtilities;
 
 import org.testng.Assert;
 import org.testng.annotations.BeforeClass;
@@ -73,7 +70,7 @@
 
 /*
  * @test
- * @bug 8081248 8144966 8146606 8146237 8151154 8150969 8151162 8152527 8154220 8163232
+ * @bug 8081248 8144966 8146606 8146237 8150969 8151162 8152527 8154220 8163232
  * @library /javax/xml/jaxp/libs /javax/xml/jaxp/unittest
  * @run testng/othervm -DrunSecMngr=true catalog.CatalogTest
  * @run testng/othervm catalog.CatalogTest
@@ -459,21 +456,6 @@
         Catalog catalog = CatalogManager.catalog(features, catalogFile);
     }
 
-    /**
-     * @bug 8151154
-     * Verifies that the CatalogFeatures' builder throws IllegalArgumentException
-     * on invalid file inputs.
-     * @param file the file path
-     */
-    @Test(dataProvider = "invalidPaths", expectedExceptions = IllegalArgumentException.class)
-    public void testFileInput(String file) {
-        JAXPTestUtilities.runWithTmpPermission(() -> {
-            CatalogFeatures features = CatalogFeatures.builder()
-                .with(CatalogFeatures.Feature.FILES, file)
-                .build();
-        }, new FilePermission("/../../..", "read"), new FilePermission("c:\\te:t", "read"),
-                new FilePermission("c:\\te?t", "read"), new PropertyPermission("user.dir", "read"));
-    }
 
     /**
      * @bug 8146237
@@ -736,24 +718,6 @@
         };
     }
 
-    /*
-       DataProvider: for testing the verification of file paths by
-                     the CatalogFeatures builder
-     */
-    @DataProvider(name = "invalidPaths")
-    public Object[][] getFiles() {
-        return new Object[][]{
-            {null},
-            {""},
-            {"file:a/b\\c"},
-            {"file:/../../.."},
-            {"c:/te:t"},
-            {"c:/te?t"},
-            {"c/te*t"},
-            {"in|valid.txt"},
-            {"shema:invalid.txt"},
-        };
-    }
 
     /*
        DataProvider: provides test name, expected string, the catalog, and XML