Avoid NullPointerException on non-existing file.

This change allows the method to throw a more informative exception
containing the file name that has not been found.

Test: used the library in sharedlibs_host_tests
Change-Id: I196385486ef4c121f1c655cd76c3ea5233e2a722
This commit is contained in:
Dario Freni
2020-11-05 14:30:00 +00:00
parent 97f35bbbef
commit 2d510d9b6c

View File

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