Skip to content

Commit

Permalink
Fix ClassPathTest on Android JDK 11.
Browse files Browse the repository at this point in the history
RELNOTES=n/a

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=334217434
  • Loading branch information
benyu authored and cgdecker committed Sep 29, 2020
1 parent 44b6fcf commit 7f164ef
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 18 deletions.
Expand Up @@ -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;
Expand Down Expand Up @@ -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 {}
Expand Down
3 changes: 2 additions & 1 deletion android/guava/src/com/google/common/reflect/ClassPath.java
Expand Up @@ -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<JarEntry> entries = file.entries();
while (entries.hasMoreElements()) {
JarEntry entry = entries.nextElement();
Expand Down
12 changes: 4 additions & 8 deletions guava-tests/test/com/google/common/reflect/ClassPathTest.java
Expand Up @@ -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;
Expand Down Expand Up @@ -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 {}
Expand Down
3 changes: 2 additions & 1 deletion guava/src/com/google/common/reflect/ClassPath.java
Expand Up @@ -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<JarEntry> entries = file.entries();
while (entries.hasMoreElements()) {
JarEntry entry = entries.nextElement();
Expand Down

0 comments on commit 7f164ef

Please sign in to comment.