From c4c6b9d715d9342b024b4e2eccd8e6370fa28a9f Mon Sep 17 00:00:00 2001 From: offa Date: Thu, 21 Oct 2021 18:30:31 +0000 Subject: [PATCH] Use try-with-resource (#322) * Use try-with-resource * Add missing @NonNull annotation --- .../plugins/content/JellyScriptContent.java | 16 +++------------- .../emailext/watching/EmailExtWatchAction.java | 2 +- 2 files changed, 4 insertions(+), 14 deletions(-) diff --git a/src/main/java/hudson/plugins/emailext/plugins/content/JellyScriptContent.java b/src/main/java/hudson/plugins/emailext/plugins/content/JellyScriptContent.java index 175cd7342..33b4efbbe 100644 --- a/src/main/java/hudson/plugins/emailext/plugins/content/JellyScriptContent.java +++ b/src/main/java/hudson/plugins/emailext/plugins/content/JellyScriptContent.java @@ -44,24 +44,14 @@ public JellyScriptContent() { } @Override - public String evaluate(@NonNull Run run, FilePath workspace, @NonNull TaskListener listener, String macroName) throws MacroEvaluationException, IOException, InterruptedException { - InputStream inputStream = null; - - try { - inputStream = getFileInputStream(run, workspace, template, JELLY_EXTENSION); + public String evaluate(@NonNull Run run, FilePath workspace, @NonNull TaskListener listener, String macroName) + throws MacroEvaluationException, IOException, InterruptedException { + try (InputStream inputStream = getFileInputStream(run, workspace, template, JELLY_EXTENSION)) { return renderContent(run, inputStream, listener); } catch (JellyException e) { return "JellyException: " + e.getMessage(); } catch (FileNotFoundException e) { return generateMissingFile("Jelly", template); - } finally { - try { - if (inputStream != null) { - inputStream.close(); - } - } catch (IOException e) { - // ignore - } } } diff --git a/src/main/java/hudson/plugins/emailext/watching/EmailExtWatchAction.java b/src/main/java/hudson/plugins/emailext/watching/EmailExtWatchAction.java index 16959e63d..0a1da59d9 100644 --- a/src/main/java/hudson/plugins/emailext/watching/EmailExtWatchAction.java +++ b/src/main/java/hudson/plugins/emailext/watching/EmailExtWatchAction.java @@ -67,7 +67,7 @@ public UserProperty newInstance(User user) { @NonNull @Override - public UserProperty newInstance(StaplerRequest req, JSONObject json) throws FormException { + public UserProperty newInstance(StaplerRequest req, @NonNull JSONObject json) throws FormException { List triggers = req != null ? req.bindJSONToList(EmailTrigger.class, json) : Collections.emptyList(); return new UserProperty(triggers); }