Skip to content

Commit

Permalink
Fix decoding of jar file paths for coverage runs of java
Browse files Browse the repository at this point in the history
File paths that contain special characters (such as % or @) will be escaped using the URL encoding.

The previous implementation did not decode these paths before passing it to the file system, leading to
file-not-found errors.

This bug was triggered by having a maven dependency being placed in the following path (note the %40):

```
$HOME/.cache/bazel/_bazel_patrick/$HASH/external/maven/v1/https/user%40repo.provider.com/
```

Closes bazelbuild#8270.

PiperOrigin-RevId: 247572901
  • Loading branch information
TheMarex authored and copybara-github committed May 10, 2019
1 parent b677702 commit 77b5658
Showing 1 changed file with 7 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import java.lang.reflect.Method;
import java.net.URL;
import java.net.URLClassLoader;
import java.net.URLDecoder;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.HashSet;
Expand Down Expand Up @@ -384,17 +385,17 @@ public static void main(String[] args) throws Exception {
URL[] urls = ((URLClassLoader) classLoader).getURLs();
metadataFiles = new File[urls.length];
for (int i = 0; i < urls.length; i++) {
URL url = urls[i];
metadataFiles[i] = new File(url.getFile());
String file = URLDecoder.decode(urls[i].getFile(), "UTF-8");
metadataFiles[i] = new File(file);
// Special case for deploy jars.
if (url.getFile().endsWith("_deploy.jar")) {
metadataFile = url.getFile();
} else if (url.getFile().endsWith(".jar")) {
if (file.endsWith("_deploy.jar")) {
metadataFile = file;
} else if (file.endsWith(".jar")) {
// Collect
// - uninstrumented class files for coverage before starting the actual test
// - paths considered for coverage
// Collecting these in the shutdown hook is too expensive (we only have a 5s budget).
JarFile jarFile = new JarFile(url.getFile());
JarFile jarFile = new JarFile(file);
Enumeration<JarEntry> jarFileEntries = jarFile.entries();
while (jarFileEntries.hasMoreElements()) {
JarEntry jarEntry = jarFileEntries.nextElement();
Expand Down

0 comments on commit 77b5658

Please sign in to comment.