diff --git a/alluxio/src/test/java/org/apache/zeppelin/alluxio/AlluxioInterpreterTest.java b/alluxio/src/test/java/org/apache/zeppelin/alluxio/AlluxioInterpreterTest.java index 00405113a28..6c0f29df57b 100644 --- a/alluxio/src/test/java/org/apache/zeppelin/alluxio/AlluxioInterpreterTest.java +++ b/alluxio/src/test/java/org/apache/zeppelin/alluxio/AlluxioInterpreterTest.java @@ -224,9 +224,12 @@ void mkdirTest() throws IOException, AlluxioException { private void fileReadTest(String fileName, int size) throws IOException { File testFile = new File(PathUtils.concatPath(mLocalAlluxioCluster.getAlluxioHome(), fileName)); FileInputStream fis = new FileInputStream(testFile); - byte[] read = new byte[size]; - fis.read(read); - fis.close(); - assertTrue(BufferUtils.equalIncreasingByteArray(size, read)); + try { + byte[] read = new byte[size]; + fis.read(read); + assertTrue(BufferUtils.equalIncreasingByteArray(size, read)); + } finally { + fis.close(); + } } } diff --git a/python/src/main/java/org/apache/zeppelin/python/IPythonInterpreter.java b/python/src/main/java/org/apache/zeppelin/python/IPythonInterpreter.java index d40cef49b81..858fbf6c227 100644 --- a/python/src/main/java/org/apache/zeppelin/python/IPythonInterpreter.java +++ b/python/src/main/java/org/apache/zeppelin/python/IPythonInterpreter.java @@ -134,6 +134,9 @@ private void setupJVMGateway(String gatewayHost, int gatewayPort) throws IOExcep private void initPythonInterpreter(String gatewayHost, int gatewayPort) throws IOException { InputStream input = getClass().getClassLoader().getResourceAsStream("python/zeppelin_ipython.py"); + if (input == null) { + throw new IOException("Cannot find resource: python/zeppelin_ipython.py"); + } List lines = IOUtils.readLines(input, StandardCharsets.UTF_8); ExecuteResponse response = jupyterKernelClient.block_execute(ExecuteRequest.newBuilder() .setCode(StringUtils.join(lines, System.lineSeparator()) @@ -145,6 +148,9 @@ private void initPythonInterpreter(String gatewayHost, int gatewayPort) throws I input = getClass().getClassLoader().getResourceAsStream("python/zeppelin_context.py"); + if (input == null) { + throw new IOException("Cannot find resource: python/zeppelin_context.py"); + } lines = IOUtils.readLines(input, StandardCharsets.UTF_8); response = jupyterKernelClient.block_execute(ExecuteRequest.newBuilder() .setCode(StringUtils.join(lines, System.lineSeparator())).build()); @@ -161,6 +167,9 @@ private void initPythonInterpreter(String gatewayHost, int gatewayPort) throws I if (additionalPythonInitFile != null) { input = getClass().getClassLoader().getResourceAsStream(additionalPythonInitFile); + if (input == null) { + throw new IOException("Cannot find resource: " + additionalPythonInitFile); + } lines = IOUtils.readLines(input, StandardCharsets.UTF_8); response = jupyterKernelClient.block_execute(ExecuteRequest.newBuilder() .setCode(StringUtils.join(lines, System.lineSeparator()) diff --git a/python/src/main/java/org/apache/zeppelin/python/PythonInterpreter.java b/python/src/main/java/org/apache/zeppelin/python/PythonInterpreter.java index 46dbf8baddd..320fe69c1ff 100644 --- a/python/src/main/java/org/apache/zeppelin/python/PythonInterpreter.java +++ b/python/src/main/java/org/apache/zeppelin/python/PythonInterpreter.java @@ -43,6 +43,7 @@ import java.io.File; import java.io.FileOutputStream; import java.io.IOException; +import java.io.InputStream; import java.nio.file.Files; import java.util.LinkedList; import java.util.List; @@ -196,15 +197,21 @@ protected boolean useIPython() { private void copyResourceToPythonWorkDir(String srcResourceName, String dstFileName) throws IOException { FileOutputStream out = null; + InputStream in = null; try { out = new FileOutputStream(pythonWorkDir.getAbsoluteFile() + "/" + dstFileName); - IOUtils.copy( - getClass().getClassLoader().getResourceAsStream(srcResourceName), - out); + in = getClass().getClassLoader().getResourceAsStream(srcResourceName); + if (in == null) { + throw new IOException("Cannot find resource: " + srcResourceName); + } + IOUtils.copy(in, out); } finally { if (out != null) { out.close(); } + if (in != null) { + in.close(); + } } } diff --git a/rlang/src/main/java/org/apache/zeppelin/r/IRInterpreter.java b/rlang/src/main/java/org/apache/zeppelin/r/IRInterpreter.java index 6407459354e..8536a3b3691 100644 --- a/rlang/src/main/java/org/apache/zeppelin/r/IRInterpreter.java +++ b/rlang/src/main/java/org/apache/zeppelin/r/IRInterpreter.java @@ -129,6 +129,9 @@ protected void initIRKernel() throws IOException, InterpreterException { String timeout = getProperty("spark.r.backendConnectionTimeout", "6000"); InputStream input = getClass().getClassLoader().getResourceAsStream("R/zeppelin_isparkr.R"); + if (input == null) { + throw new IOException("Cannot find resource: R/zeppelin_isparkr.R"); + } String code = IOUtils.toString(input, StandardCharsets.UTF_8) .replace("${Port}", sparkRBackend.port() + "") .replace("${version}", sparkVersion() + "") diff --git a/rlang/src/main/java/org/apache/zeppelin/r/ZeppelinR.java b/rlang/src/main/java/org/apache/zeppelin/r/ZeppelinR.java index 436da005106..3c03ecc8290 100644 --- a/rlang/src/main/java/org/apache/zeppelin/r/ZeppelinR.java +++ b/rlang/src/main/java/org/apache/zeppelin/r/ZeppelinR.java @@ -97,6 +97,9 @@ public void open() throws IOException, InterpreterException { try { out = new FileOutputStream(scriptFile); in = getClass().getClassLoader().getResourceAsStream("R/zeppelin_sparkr.R"); + if (in == null) { + throw new InterpreterException("Cannot find resource: R/zeppelin_sparkr.R"); + } IOUtils.copy(in, out); } catch (IOException e) { throw new InterpreterException(e);