Skip to content

Commit

Permalink
Fix jmxtrans#80 "Agent fails to load configuration from opaque classp…
Browse files Browse the repository at this point in the history
…ath resource"
  • Loading branch information
cyrille-leclerc committed May 26, 2016
1 parent 971bd3c commit 8d853c8
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
14 changes: 12 additions & 2 deletions src/main/java/org/jmxtrans/agent/util/io/ClasspathResource.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.net.URI;
import java.net.URL;

import javax.annotation.Nonnull;
Expand Down Expand Up @@ -59,13 +60,22 @@ public boolean exists() {
@Nonnull
@Override
public URL getURL() {
return classLoader.getResource(path);
URL resource = classLoader.getResource(path);
if (resource == null) {
throw new NullPointerException("No resource '" + path + "' found in classloader " + classLoader);
}
return resource;
}

@Nonnull
@Override
public File getFile() {
return new File(getURI());
URI uri = getURI();
try {
return new File(uri);
} catch (RuntimeException e) {
throw new FileNotFoundRuntimeException("Resource '" + uri + "' can not be resolved as a file", e);
}
}

@Nonnull
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/jmxtrans/agent/util/io/IoUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ public static Document getFileAsDocument(@Nonnull Resource resource) throws IoRu
try {
File configurationFile = resource.getFile();
return dBuilder.parse(configurationFile);
} catch(FileNotFoundRuntimeException e) {
} catch(IoRuntimeException e) {
try (InputStream in = resource.getInputStream()) {
return dBuilder.parse(in);
}
Expand Down

0 comments on commit 8d853c8

Please sign in to comment.