You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@zeppelin.apache.org by "renechoi (via GitHub)" <gi...@apache.org> on 2025/08/04 12:55:35 UTC
[PR] [ZEPPELIN-6268] Fix resource leaks and add null checks for getResourceAsStream [zeppelin]
renechoi opened a new pull request, #5010:
URL: https://github.com/apache/zeppelin/pull/5010
## What is this PR for?
This PR fixes resource management issues throughout the Zeppelin codebase, specifically addressing resource leaks and potential NullPointerExceptions.
## What type of PR is it?
Bug Fix / Improvement
## What is the Jira issue?
(Please create a JIRA issue if needed)
## How should this be tested?
- All modified files compile successfully
- Existing tests should pass without modification
- The changes maintain backward compatibility
## Screenshots (if appropriate)
N/A
## Questions:
* Does the license files need update? No
* Is there breaking changes for older versions? No
* Does this need documentation? No (internal improvements only)
## Changes Made:
### 1. AlluxioInterpreterTest.java
- Fixed FileInputStream resource leak by using try-finally block
- Ensures stream is closed even when exceptions occur
### 2. Resource Loading Null Checks
Added null checks for `getResourceAsStream()` calls in:
- **ZeppelinR.java**: Loading R/zeppelin_sparkr.R
- **PythonInterpreter.java**: Loading Python resources (also fixed missing InputStream import)
- **IPythonInterpreter.java**: Loading python/zeppelin_ipython.py, python/zeppelin_context.py, and additional init files
- **IRInterpreter.java**: Loading R/zeppelin_isparkr.R
### Benefits:
- Prevents resource leaks that could cause memory issues in long-running processes
- Prevents NullPointerException when resources are missing
- Provides clear error messages when resources cannot be found
- Improves overall stability and reliability
### Testing Notes:
While I couldn't run all tests due to environment setup issues, all files compile successfully and the changes are minimal and safe - they only add defensive programming practices without changing any business logic.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: reviews-unsubscribe@zeppelin.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [ZEPPELIN-6268] Fix resource leaks and add null checks for getResourceAsStream [zeppelin]
Posted by "Reamer (via GitHub)" <gi...@apache.org>.
Reamer commented on code in PR #5010:
URL: https://github.com/apache/zeppelin/pull/5010#discussion_r2278371744
##########
python/src/main/java/org/apache/zeppelin/python/PythonInterpreter.java:
##########
@@ -196,15 +197,21 @@ protected boolean useIPython() {
private void copyResourceToPythonWorkDir(String srcResourceName,
String dstFileName) throws IOException {
FileOutputStream out = null;
+ InputStream in = null;
try {
Review Comment:
Please use try-with-resources, also here
##########
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 =
Review Comment:
Here, closing the input stream is missing; this can be done directly with try-with-resource.
##########
rlang/src/main/java/org/apache/zeppelin/r/ZeppelinR.java:
##########
@@ -97,6 +97,9 @@ public void open() throws IOException, InterpreterException {
try {
Review Comment:
Same use try-with-resource for the input and FileOutputStream
##########
python/src/main/java/org/apache/zeppelin/python/IPythonInterpreter.java:
##########
@@ -161,6 +167,9 @@ private void initPythonInterpreter(String gatewayHost, int gatewayPort) throws I
if (additionalPythonInitFile != null) {
input = getClass().getClassLoader().getResourceAsStream(additionalPythonInitFile);
Review Comment:
Here, closing the input stream is missing; this can be done directly with try-with-resource.
##########
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 {
Review Comment:
Please use try-with-resources. This is more elegant.
https://docs.oracle.com/javase/tutorial/essential/exceptions/tryResourceClose.html
##########
python/src/main/java/org/apache/zeppelin/python/IPythonInterpreter.java:
##########
@@ -145,6 +148,9 @@ private void initPythonInterpreter(String gatewayHost, int gatewayPort) throws I
input =
Review Comment:
Here, closing the input stream is missing; this can be done directly with try-with-resource.
##########
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 =
Review Comment:
Same please use try-with-resource do close the stream.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: reviews-unsubscribe@zeppelin.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [ZEPPELIN-6268] Fix resource leaks and add null checks for getResourceAsStream [zeppelin]
Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #5010:
URL: https://github.com/apache/zeppelin/pull/5010#issuecomment-5305336014
This pull request has been inactive for over a year. If no further activity occurs within the next 30 days, it will be automatically closed. If you believe this PR is still relevant, please feel free to leave a comment or make an update. Thank you!
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: reviews-unsubscribe@zeppelin.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [ZEPPELIN-6268] Fix resource leaks and add null checks for getResourceAsStream [zeppelin]
Posted by "renechoi (via GitHub)" <gi...@apache.org>.
renechoi commented on PR #5010:
URL: https://github.com/apache/zeppelin/pull/5010#issuecomment-5569490770
Rebased onto current master and pushed 348bc8d. The try-with-resources requests that still apply are in: `PythonInterpreter.copyResourceToPythonWorkDir`, and the three `getResourceAsStream` sites in `IPythonInterpreter`, each with a null check on the stream.
The other three files you reviewed are no longer in the diff. `alluxio` was dropped by ZEPPELIN-6420 (1a6a8e3) and `rlang` by ZEPPELIN-6430 (0f0a2d5). The PR is now python-only: 2 files, +29/-17, 18/18 checks green.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: reviews-unsubscribe@zeppelin.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org