From ff4aa3dcfd660028d88f432c18da248e8b870ee6 Mon Sep 17 00:00:00 2001 From: TopchetoEU <36534413+TopchetoEU@users.noreply.github.com> Date: Wed, 11 Dec 2024 11:53:29 +0200 Subject: [PATCH] fix: return null when loading an inexistent resource --- src/main/java/me/topchetoeu/jscript/common/Reading.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/main/java/me/topchetoeu/jscript/common/Reading.java b/src/main/java/me/topchetoeu/jscript/common/Reading.java index 61c61bb..efa3e68 100644 --- a/src/main/java/me/topchetoeu/jscript/common/Reading.java +++ b/src/main/java/me/topchetoeu/jscript/common/Reading.java @@ -17,6 +17,8 @@ public class Reading { } public static byte[] streamToBytes(InputStream in) { + if (in == null) return null; + try { List bufs = null; byte[] result = null; @@ -73,7 +75,9 @@ public class Reading { catch (IOException e) { throw new UncheckedIOException(e); } } public static String streamToString(InputStream in) { - return new String(streamToBytes(in)); + var bytes = streamToBytes(in); + if (bytes == null) return null; + else return new String(bytes); } public static InputStream resourceToStream(String name) {