Merge "Avoid NullPointerException on non-existing file."

This commit is contained in:
Treehugger Robot
2020-11-05 18:13:18 +00:00
committed by Gerrit Code Review

View File

@@ -186,7 +186,7 @@ public class SystemPreparer extends ExternalResource {
private File copyResourceToTemp(String resourcePath) throws IOException { private File copyResourceToTemp(String resourcePath) throws IOException {
final File tempFile = mHostTempFolder.newFile(); final File tempFile = mHostTempFolder.newFile();
final ClassLoader classLoader = getClass().getClassLoader(); final ClassLoader classLoader = getClass().getClassLoader();
try (InputStream assetIs = classLoader.getResource(resourcePath).openStream(); try (InputStream assetIs = classLoader.getResourceAsStream(resourcePath);
FileOutputStream assetOs = new FileOutputStream(tempFile)) { FileOutputStream assetOs = new FileOutputStream(tempFile)) {
if (assetIs == null) { if (assetIs == null) {
throw new IllegalStateException("Failed to find resource " + resourcePath); throw new IllegalStateException("Failed to find resource " + resourcePath);