From 7f164ef7e2cc536754ecdd6a26ddc3dabaa398ec Mon Sep 17 00:00:00 2001 From: benyu Date: Mon, 28 Sep 2020 12:44:14 -0700 Subject: [PATCH] Fix ClassPathTest on Android JDK 11. RELNOTES=n/a ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=334217434 --- .../com/google/common/reflect/ClassPathTest.java | 12 ++++-------- .../src/com/google/common/reflect/ClassPath.java | 3 ++- .../com/google/common/reflect/ClassPathTest.java | 12 ++++-------- guava/src/com/google/common/reflect/ClassPath.java | 3 ++- 4 files changed, 12 insertions(+), 18 deletions(-) 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 49a41edc8a6c..8bccae7c3896 100644 --- a/android/guava-tests/test/com/google/common/reflect/ClassPathTest.java +++ b/android/guava-tests/test/com/google/common/reflect/ClassPathTest.java @@ -45,6 +45,7 @@ import java.util.HashSet; import java.util.Set; import java.util.jar.Attributes; +import java.util.jar.JarFile; import java.util.jar.JarOutputStream; import java.util.jar.Manifest; import java.util.logging.Logger; @@ -543,18 +544,13 @@ static File pickAnyJarFile() throws IOException { } @Override - protected void scanFrom(File file, ClassLoader loader) throws IOException { - if (file.isDirectory()) { - return; - } - this.found = file; + void scanJarFile(ClassLoader classloader, JarFile file) throws IOException { + this.found = new File(file.getName()); throw new StopScanningException(); } @Override - protected void scanResource(ResourceInfo resource) throws IOException { - throw new IllegalStateException(); - } + protected void scanResource(ResourceInfo resource) {} // Special exception just to terminate the scanning when we get any jar file to use. private static final class StopScanningException extends RuntimeException {} diff --git a/android/guava/src/com/google/common/reflect/ClassPath.java b/android/guava/src/com/google/common/reflect/ClassPath.java index aedd85954cd7..427914c3936d 100644 --- a/android/guava/src/com/google/common/reflect/ClassPath.java +++ b/android/guava/src/com/google/common/reflect/ClassPath.java @@ -508,7 +508,8 @@ static URL getClassPathEntry(File jarFile, String path) throws MalformedURLExcep return new URL(jarFile.toURI().toURL(), path); } - private void scanJarFile(ClassLoader classloader, JarFile file) throws IOException { + @VisibleForTesting + void scanJarFile(ClassLoader classloader, JarFile file) throws IOException { Enumeration entries = file.entries(); while (entries.hasMoreElements()) { JarEntry entry = entries.nextElement(); diff --git a/guava-tests/test/com/google/common/reflect/ClassPathTest.java b/guava-tests/test/com/google/common/reflect/ClassPathTest.java index c970a0d73e18..1d210027f244 100644 --- a/guava-tests/test/com/google/common/reflect/ClassPathTest.java +++ b/guava-tests/test/com/google/common/reflect/ClassPathTest.java @@ -52,6 +52,7 @@ import java.util.HashSet; import java.util.Set; import java.util.jar.Attributes; +import java.util.jar.JarFile; import java.util.jar.JarOutputStream; import java.util.jar.Manifest; import java.util.logging.Logger; @@ -610,18 +611,13 @@ static File pickAnyJarFile() throws IOException { } @Override - protected void scanFrom(File file, ClassLoader loader) throws IOException { - if (file.isDirectory()) { - return; - } - this.found = file; + void scanJarFile(ClassLoader classloader, JarFile file) throws IOException { + this.found = new File(file.getName()); throw new StopScanningException(); } @Override - protected void scanResource(ResourceInfo resource) throws IOException { - throw new IllegalStateException(); - } + protected void scanResource(ResourceInfo resource) {} // Special exception just to terminate the scanning when we get any jar file to use. private static final class StopScanningException extends RuntimeException {} diff --git a/guava/src/com/google/common/reflect/ClassPath.java b/guava/src/com/google/common/reflect/ClassPath.java index 76dc2fe7b8b1..c4f9d0f5b301 100644 --- a/guava/src/com/google/common/reflect/ClassPath.java +++ b/guava/src/com/google/common/reflect/ClassPath.java @@ -507,7 +507,8 @@ static URL getClassPathEntry(File jarFile, String path) throws MalformedURLExcep return new URL(jarFile.toURI().toURL(), path); } - private void scanJarFile(ClassLoader classloader, JarFile file) throws IOException { + @VisibleForTesting + void scanJarFile(ClassLoader classloader, JarFile file) throws IOException { Enumeration entries = file.entries(); while (entries.hasMoreElements()) { JarEntry entry = entries.nextElement();