From 2d510d9b6cd99875fd1e808c82b4d08e72cc3fbd Mon Sep 17 00:00:00 2001 From: Dario Freni Date: Thu, 5 Nov 2020 14:30:00 +0000 Subject: [PATCH] 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 --- .../src/com/android/internal/util/test/SystemPreparer.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/utils/hostutils/src/com/android/internal/util/test/SystemPreparer.java b/tests/utils/hostutils/src/com/android/internal/util/test/SystemPreparer.java index f30c35aca8da6..1733386601139 100644 --- a/tests/utils/hostutils/src/com/android/internal/util/test/SystemPreparer.java +++ b/tests/utils/hostutils/src/com/android/internal/util/test/SystemPreparer.java @@ -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);