This is an automated email from the ASF dual-hosted git repository.
pawan pushed a commit to branch trunk in repository https://gitbox.apache.org/repos/asf/ofbiz-plugins.git The following commit(s) were added to refs/heads/trunk by this push: new 32f3e46 Improved: Replace try-finally with try with resources(OFBIZ-11826) 32f3e46 is described below commit 32f3e468da726c056c8bd84bad6070c6847e504a Author: Pawan Verma <[hidden email]> AuthorDate: Mon Jun 22 21:37:00 2020 +0530 Improved: Replace try-finally with try with resources(OFBIZ-11826) Set checkstyleMain.maxErrors to 26678 (-4) Thanks: Jacques for the review. --- ldap/src/main/java/org/apache/ofbiz/ldap/LdapLoginWorker.java | 11 +---------- .../org/apache/ofbiz/solr/webapp/OFBizSolrContextFilter.java | 10 ++-------- 2 files changed, 3 insertions(+), 18 deletions(-) diff --git a/ldap/src/main/java/org/apache/ofbiz/ldap/LdapLoginWorker.java b/ldap/src/main/java/org/apache/ofbiz/ldap/LdapLoginWorker.java index 6e1bdb4..89b28b2 100644 --- a/ldap/src/main/java/org/apache/ofbiz/ldap/LdapLoginWorker.java +++ b/ldap/src/main/java/org/apache/ofbiz/ldap/LdapLoginWorker.java @@ -181,10 +181,8 @@ public final class LdapLoginWorker { Debug.logInfo("LDAP config file: " + LDAP_CONFIG, MODULE); } File configFile = new File(LDAP_CONFIG); - FileInputStream configFileIS = null; Element rootElement = null; - try { - configFileIS = new FileInputStream(configFile); + try (FileInputStream configFileIS = new FileInputStream(configFile)) { Document configDoc = UtilXml.readXmlDocument(configFileIS, "LDAP configuration file " + LDAP_CONFIG); rootElement = configDoc.getDocumentElement(); } catch (FileNotFoundException e) { @@ -207,13 +205,6 @@ public final class LdapLoginWorker { Map<String, String> messageMap = UtilMisc.toMap("errorMessage", e.getMessage()); String errMsg = UtilProperties.getMessage(RESOURCE, "loginevents.following_error_occurred_during_login", messageMap, UtilHttp.getLocale(request)); request.setAttribute("_ERROR_MESSAGE_", errMsg); - } finally { - if (configFileIS != null) { - try { - configFileIS.close(); - } catch (IOException e) { - } - } } return rootElement; diff --git a/solr/src/main/java/org/apache/ofbiz/solr/webapp/OFBizSolrContextFilter.java b/solr/src/main/java/org/apache/ofbiz/solr/webapp/OFBizSolrContextFilter.java index cd01204..ee3ff8b 100644 --- a/solr/src/main/java/org/apache/ofbiz/solr/webapp/OFBizSolrContextFilter.java +++ b/solr/src/main/java/org/apache/ofbiz/solr/webapp/OFBizSolrContextFilter.java @@ -181,10 +181,8 @@ public class OFBizSolrContextFilter extends SolrDispatchFilter { Map<String, Object> responseHeader = new HashMap<>(); JSON json; String message = ""; - OutputStream os = null; - - try { - os = httpResponse.getOutputStream(); + + try (OutputStream os = httpResponse.getOutputStream()) { if (UtilValidate.isEmpty(userLogin)) { httpResponse.setStatus(HttpServletResponse.SC_UNAUTHORIZED); responseHeader.put("status", HttpServletResponse.SC_UNAUTHORIZED); @@ -202,10 +200,6 @@ public class OFBizSolrContextFilter extends SolrDispatchFilter { Debug.logInfo("[" + httpRequest.getRequestURI().substring(1) + "(Domain:" + httpRequest.getScheme() + "://" + httpRequest.getServerName() + ")] Request error: " + message, MODULE); } catch (ConversionException e) { Debug.logError("Error while converting responseHeader map to JSON.", MODULE); - } finally { - if (os != null) { - os.close(); - } } } } |
Free forum by Nabble | Edit this page |