diff --git a/android/guava-tests/test/com/google/common/reflect/ClassPathTest.java b/android/guava-tests/test/com/google/common/reflect/ClassPathTest.java index 354f182a9c92..923a18e1afa1 100644 --- a/android/guava-tests/test/com/google/common/reflect/ClassPathTest.java +++ b/android/guava-tests/test/com/google/common/reflect/ClassPathTest.java @@ -34,15 +34,12 @@ import java.io.ByteArrayInputStream; import java.io.File; import java.io.FileOutputStream; -import java.io.FilePermission; import java.io.IOException; import java.io.InputStream; import java.net.MalformedURLException; import java.net.URISyntaxException; import java.net.URL; import java.net.URLClassLoader; -import java.security.Permission; -import java.security.PermissionCollection; import java.util.jar.Attributes; import java.util.jar.JarOutputStream; import java.util.jar.Manifest; @@ -456,50 +453,6 @@ public void testScanAllResources() throws IOException { .contains("com/google/common/reflect/ClassPathTest.class"); } - - public void testExistsThrowsSecurityException() throws IOException, URISyntaxException { - SecurityManager oldSecurityManager = System.getSecurityManager(); - try { - doTestExistsThrowsSecurityException(); - } finally { - System.setSecurityManager(oldSecurityManager); - } - } - - private void doTestExistsThrowsSecurityException() throws IOException, URISyntaxException { - File file = null; - // In Java 9, Logger may read the TZ database. Only disallow reading the class path URLs. - final PermissionCollection readClassPathFiles = - new FilePermission("", "read").newPermissionCollection(); - for (URL url : ClassPath.parseJavaClassPath()) { - if (url.getProtocol().equalsIgnoreCase("file")) { - file = new File(url.toURI()); - readClassPathFiles.add(new FilePermission(file.getAbsolutePath(), "read")); - } - } - assertThat(file).isNotNull(); - SecurityManager disallowFilesSecurityManager = - new SecurityManager() { - @Override - public void checkPermission(Permission p) { - if (readClassPathFiles.implies(p)) { - throw new SecurityException("Disallowed: " + p); - } - } - }; - System.setSecurityManager(disallowFilesSecurityManager); - try { - file.exists(); - fail("Did not get expected SecurityException"); - } catch (SecurityException expected) { - } - ClassPath classPath = ClassPath.from(getClass().getClassLoader()); - // ClassPath may contain resources from the boot class loader; just not from the class path. - for (ResourceInfo resource : classPath.getResources()) { - assertThat(resource.getResourceName()).doesNotContain("com/google/common/reflect/"); - } - } - private static ClassPath.ClassInfo findClass( Iterable classes, Class cls) { for (ClassPath.ClassInfo classInfo : classes) { diff --git a/guava-tests/test/com/google/common/reflect/ClassPathTest.java b/guava-tests/test/com/google/common/reflect/ClassPathTest.java index 70156e12340c..36ba6ba6171a 100644 --- a/guava-tests/test/com/google/common/reflect/ClassPathTest.java +++ b/guava-tests/test/com/google/common/reflect/ClassPathTest.java @@ -40,7 +40,6 @@ import java.io.ByteArrayInputStream; import java.io.File; import java.io.FileOutputStream; -import java.io.FilePermission; import java.io.IOException; import java.io.InputStream; import java.net.MalformedURLException; @@ -48,8 +47,6 @@ import java.net.URL; import java.net.URLClassLoader; import java.nio.file.Path; -import java.security.Permission; -import java.security.PermissionCollection; import java.util.jar.Attributes; import java.util.jar.JarOutputStream; import java.util.jar.Manifest; @@ -522,50 +519,6 @@ public void testScanAllResources() throws IOException { .contains("com/google/common/reflect/ClassPathTest.class"); } - - public void testExistsThrowsSecurityException() throws IOException, URISyntaxException { - SecurityManager oldSecurityManager = System.getSecurityManager(); - try { - doTestExistsThrowsSecurityException(); - } finally { - System.setSecurityManager(oldSecurityManager); - } - } - - private void doTestExistsThrowsSecurityException() throws IOException, URISyntaxException { - File file = null; - // In Java 9, Logger may read the TZ database. Only disallow reading the class path URLs. - final PermissionCollection readClassPathFiles = - new FilePermission("", "read").newPermissionCollection(); - for (URL url : ClassPath.parseJavaClassPath()) { - if (url.getProtocol().equalsIgnoreCase("file")) { - file = new File(url.toURI()); - readClassPathFiles.add(new FilePermission(file.getAbsolutePath(), "read")); - } - } - assertThat(file).isNotNull(); - SecurityManager disallowFilesSecurityManager = - new SecurityManager() { - @Override - public void checkPermission(Permission p) { - if (readClassPathFiles.implies(p)) { - throw new SecurityException("Disallowed: " + p); - } - } - }; - System.setSecurityManager(disallowFilesSecurityManager); - try { - file.exists(); - fail("Did not get expected SecurityException"); - } catch (SecurityException expected) { - } - ClassPath classPath = ClassPath.from(getClass().getClassLoader()); - // ClassPath may contain resources from the boot class loader; just not from the class path. - for (ResourceInfo resource : classPath.getResources()) { - assertThat(resource.getResourceName()).doesNotContain("com/google/common/reflect/"); - } - } - private static ClassPath.ClassInfo findClass( Iterable classes, Class cls) { for (ClassPath.ClassInfo classInfo : classes) {