OpenRefine icon indicating copy to clipboard operation
OpenRefine copied to clipboard

Fix: close FileInputStream in loadLanguage to prevent file handle leak

Open Manishnemade12 opened this issue 6 months ago • 1 comments

Pull Request: Fix language file handle leak

Closes: #7759

Summary

  • Fixes a file-handle leak when loading translation files in LoadLanguageCommand.loadLanguage().

What I changed

  • File: main/src/com/google/refine/commands/lang/LoadLanguageCommand.java
  • Replaced manual FileInputStream handling with a try-with-resources block so the FileInputStream and Reader are always closed on success or error.

Why

  • Previously the FileInputStream could remain open when parsing failed or on early returns, which can exhaust file descriptors under repeated requests.

How to reproduce (before)

  1. Start OpenRefine.
  2. Trigger the language-load path for a module (e.g., load translation-XX.json).
  3. Force a parse error or repeat the request many times and observe open file handles (e.g., with lsof -p <pid>).

How this fixes it

  • Using try-with-resources ensures the FileInputStream and wrapped Reader are closed automatically even on exceptions.

Testing performed

  • Compiled the edited file locally with the project classpath; javac produced LoadLanguageCommand.class.
  • Verified a commit was created with Signed-off-by and pushed the branch fix/close-language-file-handle to origin.

Notes for reviewer

  • Run a full project build mvn -DskipTests -pl main -am package to validate.
  • Optionally run OpenRefine and exercise the language loading endpoint; observe file descriptor counts before/after.

Manishnemade12 avatar May 14 '26 14:05 Manishnemade12

@tfmorris i fixed all the bugs . please verify it

Manishnemade12 avatar Jun 19 '26 07:06 Manishnemade12