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
commit 1f97f89bae0db49da2facf0be28f0cf7ebe4c8e7 Author: Pawan Verma <pawan.ve...@hotwaxsystems.com> AuthorDate: Sat Jun 27 11:24:33 2020 +0530 Improved: Merge identical catch blocks in single catch block(OFBIZ-11827) In Java SE 7 and later, a single catch block can handle more than one type of exception. This feature can reduce code duplication and lessen the temptation to catch an overly broad exception. Thanks: Jacques for the review. --- .../java/org/apache/ofbiz/ebay/EbayHelper.java | 10 +----- .../java/org/apache/ofbiz/ebaystore/EbayStore.java | 12 ++----- .../ofbiz/ebaystore/EbayStoreAutoPreferences.java | 31 ++++------------- .../apache/ofbiz/ebaystore/EbayStoreHelper.java | 27 +++------------ .../ebaystore/EbayStoreInventoryServices.java | 40 ++++------------------ .../apache/ofbiz/ebaystore/EbayStoreOptions.java | 24 +++---------- .../ofbiz/ecommerce/janrain/JanrainHelper.java | 4 +-- .../ldap/cas/OFBizCasAuthenticationHandler.java | 1 - .../ofbiz/content/search/ContentDocument.java | 5 +-- .../ofbiz/content/search/ProductDocument.java | 4 +-- .../ofbiz/content/search/SearchServices.java | 4 +-- .../apache/ofbiz/passport/event/GitHubEvents.java | 21 +++--------- .../ofbiz/passport/event/LinkedInEvents.java | 32 +++-------------- .../ofbiz/passport/user/GitHubAuthenticator.java | 8 ++--- .../ofbiz/passport/user/LinkedInAuthenticator.java | 16 ++------- .../org/apache/ofbiz/htmlreport/HtmlReport.java | 4 +-- .../apache/ofbiz/pricat/AbstractPricatParser.java | 8 +---- .../java/org/apache/ofbiz/pricat/PricatEvents.java | 14 +------- .../ofbiz/pricat/sample/SamplePricatEvents.java | 3 -- .../java/org/apache/ofbiz/scrum/ScrumServices.java | 8 +---- .../java/org/apache/ofbiz/solr/ProductUtil.java | 2 -- .../org/apache/ofbiz/solr/SolrProductSearch.java | 37 ++------------------ 22 files changed, 51 insertions(+), 264 deletions(-) diff --git a/ebay/src/main/java/org/apache/ofbiz/ebay/EbayHelper.java b/ebay/src/main/java/org/apache/ofbiz/ebay/EbayHelper.java index 01ac795..329f179 100644 --- a/ebay/src/main/java/org/apache/ofbiz/ebay/EbayHelper.java +++ b/ebay/src/main/java/org/apache/ofbiz/ebay/EbayHelper.java @@ -224,9 +224,6 @@ public class EbayHelper { } catch (GenericEntityException gee) { Debug.logError(gee, "Cannot get payment preferences for order #" + orderId, MODULE); return false; - } catch (Exception e) { - Debug.logError(e, "Cannot get payment preferences for order #" + orderId, MODULE); - return false; } return true; } @@ -262,10 +259,7 @@ public class EbayHelper { return false; } return true; - } catch (GenericEntityException e) { - Debug.logError(e, "Failed to create the payment for order " + orderId, MODULE); - return false; - } catch (GenericServiceException e) { + } catch (GenericEntityException | GenericServiceException e) { Debug.logError(e, "Failed to create the payment for order " + orderId, MODULE); return false; } @@ -327,8 +321,6 @@ public class EbayHelper { } } catch (GenericServiceException e) { Debug.logError(e, "Failed to createPerson", MODULE); - } catch (Exception e) { - Debug.logError(e, "Failed to createPerson", MODULE); } return partyId; } diff --git a/ebaystore/src/main/java/org/apache/ofbiz/ebaystore/EbayStore.java b/ebaystore/src/main/java/org/apache/ofbiz/ebaystore/EbayStore.java index 96cdcb2..76de7e1 100644 --- a/ebaystore/src/main/java/org/apache/ofbiz/ebaystore/EbayStore.java +++ b/ebaystore/src/main/java/org/apache/ofbiz/ebaystore/EbayStore.java @@ -1324,13 +1324,7 @@ public class EbayStore { result.put("ebayStore", results.get("ebayStore")); } } - } catch (ApiException e) { - result.put(ModelService.RESPONSE_MESSAGE, ModelService.RESPOND_ERROR); - result.put(ModelService.ERROR_MESSAGE, e.getMessage()); - } catch (SdkSoapException e) { - result.put(ModelService.RESPONSE_MESSAGE, ModelService.RESPOND_ERROR); - result.put(ModelService.ERROR_MESSAGE, e.getMessage()); - } catch (SdkException e) { + } catch (ApiException | SdkException | SdkSoapException e) { result.put(ModelService.RESPONSE_MESSAGE, ModelService.RESPOND_ERROR); result.put(ModelService.ERROR_MESSAGE, e.getMessage()); } @@ -1651,10 +1645,8 @@ public class EbayStore { result.put(ModelService.RESPONSE_MESSAGE, ModelService.RESPOND_FAIL); result.put(ModelService.ERROR_MESSAGE_LIST, ProductsExportToEbay.getproductExportFailureMessageList()); } - } catch (GenericEntityException|GenericServiceException ge) { + } catch (GenericEntityException | GenericServiceException ge) { return ServiceUtil.returnError(ge.getMessage()); - } catch (Exception e) { - return ServiceUtil.returnError(e.getMessage()); } return result; } diff --git a/ebaystore/src/main/java/org/apache/ofbiz/ebaystore/EbayStoreAutoPreferences.java b/ebaystore/src/main/java/org/apache/ofbiz/ebaystore/EbayStoreAutoPreferences.java index 43d2373..ec307c4 100644 --- a/ebaystore/src/main/java/org/apache/ofbiz/ebaystore/EbayStoreAutoPreferences.java +++ b/ebaystore/src/main/java/org/apache/ofbiz/ebaystore/EbayStoreAutoPreferences.java @@ -300,10 +300,7 @@ public class EbayStoreAutoPreferences { } request.setAttribute("_EVENT_MESSAGE_", "Setting Automated Positive Feedback for Buyers Success with site " + apiContext.getSite().value()); - } catch (GenericEntityException e) { - request.setAttribute("_ERROR_MESSAGE_", e.getMessage()); - return "error"; - } catch (GenericServiceException e) { + } catch (GenericEntityException | GenericServiceException e) { request.setAttribute("_ERROR_MESSAGE_", e.getMessage()); return "error"; } @@ -523,10 +520,8 @@ public class EbayStoreAutoPreferences { } } } - } catch (GenericEntityException|GenericServiceException ge) { + } catch (GenericEntityException | GenericServiceException ge) { return ServiceUtil.returnError(ge.getMessage()); - } catch (Exception e) { - return ServiceUtil.returnError(e.getMessage()); } return ServiceUtil.returnSuccess(); } @@ -598,10 +593,8 @@ public class EbayStoreAutoPreferences { } } } - } catch (GenericEntityException|GenericServiceException ge) { + } catch (GenericEntityException | GenericServiceException ge) { return ServiceUtil.returnError(ge.getMessage()); - } catch (Exception e) { - return ServiceUtil.returnError(e.getMessage()); } return ServiceUtil.returnSuccess(); } @@ -673,10 +666,8 @@ public class EbayStoreAutoPreferences { } } } - } catch (GenericEntityException|GenericServiceException ge) { + } catch (GenericEntityException | GenericServiceException ge) { return ServiceUtil.returnError(ge.getMessage()); - } catch (Exception e) { - return ServiceUtil.returnError(e.getMessage()); } return ServiceUtil.returnSuccess(); } @@ -908,9 +899,7 @@ public class EbayStoreAutoPreferences { } } result = ServiceUtil.returnSuccess(); - } catch (GenericEntityException e) { - result = ServiceUtil.returnError(e.getMessage()); - } catch (GenericServiceException e) { + } catch (GenericEntityException | GenericServiceException e) { result = ServiceUtil.returnError(e.getMessage()); } catch (Exception e) { return ServiceUtil.returnError(e.getMessage()); @@ -1129,11 +1118,7 @@ public class EbayStoreAutoPreferences { EbayStoreHelper.createErrorLogMessage(userLogin, dctx.getDispatcher(), context.get("productStoreId").toString(), resp.getAck().toString(), "Get selling manager inventory : autoBlockItemsOutOfStock", resp.getErrors(0).getLongMessage()); } result = ServiceUtil.returnSuccess(); - } catch (ApiException e) { - e.printStackTrace(); - } catch (SdkSoapException e) { - e.printStackTrace(); - } catch (SdkException e) { + } catch (ApiException | SdkException | SdkSoapException e) { e.printStackTrace(); } } @@ -1183,10 +1168,8 @@ public class EbayStoreAutoPreferences { } } } - } catch (GenericEntityException|GenericServiceException ge) { + } catch (GenericEntityException | GenericServiceException ge) { return ServiceUtil.returnError(ge.getMessage()); - } catch (Exception e) { - return ServiceUtil.returnError(e.getMessage()); } return ServiceUtil.returnSuccess(); } diff --git a/ebaystore/src/main/java/org/apache/ofbiz/ebaystore/EbayStoreHelper.java b/ebaystore/src/main/java/org/apache/ofbiz/ebaystore/EbayStoreHelper.java index 4119b1e..fa20add 100644 --- a/ebaystore/src/main/java/org/apache/ofbiz/ebaystore/EbayStoreHelper.java +++ b/ebaystore/src/main/java/org/apache/ofbiz/ebaystore/EbayStoreHelper.java @@ -332,17 +332,8 @@ public class EbayStoreHelper { runtimeData.set("runtimeInfo", XmlSerializer.serialize(infoData)); runtimeData.store(); } - } catch (GenericEntityException e) { - return ServiceUtil.returnError(e.getMessage()); - } catch (GenericServiceException e) { - return ServiceUtil.returnError(e.getMessage()); - } catch (SerializeException e) { - return ServiceUtil.returnError(e.getMessage()); - } catch (IOException e) { - return ServiceUtil.returnError(e.getMessage()); - }catch (RecurrenceInfoException e) { - return ServiceUtil.returnError(e.getMessage()); - } catch (GenericConfigException e) { + } catch (GenericEntityException | GenericConfigException | RecurrenceInfoException | IOException | SerializeException + | GenericServiceException e) { return ServiceUtil.returnError(e.getMessage()); } return result; @@ -369,9 +360,7 @@ public class EbayStoreHelper { return ServiceUtil.returnError(ServiceUtil.getErrorMessage(result)); } } - } catch (GenericEntityException e) { - return ServiceUtil.returnError(e.getMessage()); - } catch (GenericServiceException e) { + } catch (GenericEntityException | GenericServiceException e) { return ServiceUtil.returnError(e.getMessage()); } return result; @@ -466,9 +455,7 @@ public class EbayStoreHelper { } } result = ServiceUtil.returnSuccess(); - } catch (GenericEntityException e) { - return ServiceUtil.returnError(e.getMessage()); - } catch (GenericServiceException e) { + } catch (GenericEntityException | GenericServiceException e) { return ServiceUtil.returnError(e.getMessage()); } return result; @@ -500,9 +487,7 @@ public class EbayStoreHelper { } } } - } catch (GenericEntityException e) { - return ServiceUtil.returnError(e.getMessage()); - } catch (GenericServiceException e) { + } catch (GenericEntityException | GenericServiceException e) { return ServiceUtil.returnError(e.getMessage()); } return ServiceUtil.returnSuccess(); @@ -709,8 +694,6 @@ public class EbayStoreHelper { } } catch (GenericEntityException gee) { return ServiceUtil.returnError(gee.getMessage()); - } catch (Exception e) { - return ServiceUtil.returnError(e.getMessage()); } return ServiceUtil.returnSuccess(); } diff --git a/ebaystore/src/main/java/org/apache/ofbiz/ebaystore/EbayStoreInventoryServices.java b/ebaystore/src/main/java/org/apache/ofbiz/ebaystore/EbayStoreInventoryServices.java index d8c1984..27183b4 100644 --- a/ebaystore/src/main/java/org/apache/ofbiz/ebaystore/EbayStoreInventoryServices.java +++ b/ebaystore/src/main/java/org/apache/ofbiz/ebaystore/EbayStoreInventoryServices.java @@ -121,11 +121,7 @@ public class EbayStoreInventoryServices { result = ServiceUtil.returnError(UtilProperties.getMessage(RESOURCE, "EbayStoreInventoryFolderIdUpdatedFailed", locale)); } } - }catch (ApiException e) { - result = ServiceUtil.returnFailure(e.getMessage()); - } catch (SdkSoapException e) { - result = ServiceUtil.returnFailure(e.getMessage()); - } catch (SdkException e) { + } catch (ApiException | SdkException | SdkSoapException e) { result = ServiceUtil.returnFailure(e.getMessage()); } catch (GenericEntityException e) { result = ServiceUtil.returnFailure(e.getMessage()); @@ -172,11 +168,7 @@ public class EbayStoreInventoryServices { Debug.logError("Fail to create inventory product ".concat(productId).concat("in productStore ").concat(context.get("productStoreId").toString()).concat(" message from ebay : ").concat(productResp.getMessage()), MODULE); } } - } catch (ApiException e) { - Debug.logError(e.getMessage(), MODULE); - } catch (SdkSoapException e) { - Debug.logError(e.getMessage(), MODULE); - } catch (SdkException e) { + } catch (ApiException | SdkException | SdkSoapException e) { Debug.logError(e.getMessage(), MODULE); } catch (GenericEntityException e) { Debug.logError(e.getMessage(), MODULE); @@ -228,11 +220,7 @@ public class EbayStoreInventoryServices { Debug.logError("Fail to update inventory product ".concat(productId).concat("in productStore ").concat(context.get("productStoreId").toString()).concat(" message from ebay : ").concat(resp.getMessage()), MODULE); } } - } catch (ApiException e) { - Debug.logError(e.getMessage(), MODULE); - } catch (SdkSoapException e) { - Debug.logError(e.getMessage(), MODULE); - } catch (SdkException e) { + } catch (ApiException | SdkException | SdkSoapException e) { Debug.logError(e.getMessage(), MODULE); } catch (GenericEntityException e) { Debug.logError(e.getMessage(), MODULE); @@ -275,11 +263,7 @@ public class EbayStoreInventoryServices { } result = ServiceUtil.returnSuccess(UtilProperties.getMessage(RESOURCE, "EbayStoreInventoryFolderIdLoaded", UtilMisc.toMap("folderId", folderId), locale)); } - } catch (ApiException e) { - result = ServiceUtil.returnFailure(e.getMessage()); - } catch (SdkSoapException e) { - result = ServiceUtil.returnFailure(e.getMessage()); - } catch (SdkException e) { + } catch (ApiException | SdkException | SdkSoapException e) { result = ServiceUtil.returnFailure(e.getMessage()); } if (result.get("responseMessage") != null && "fail".equals(result.get("responseMessage"))) folderId = null; @@ -310,11 +294,7 @@ public class EbayStoreInventoryServices { return folderId; } } - } catch (ApiException e) { - Debug.logError(e.getMessage(), MODULE); - } catch (SdkSoapException e) { - Debug.logError(e.getMessage(), MODULE); - } catch (SdkException e) { + } catch (ApiException | SdkException | SdkSoapException e) { Debug.logError(e.getMessage(), MODULE); } return folderId; @@ -364,11 +344,7 @@ public class EbayStoreInventoryServices { Debug.logError("The problem with get manage inventory detail from ebay site.", MODULE); } } - } catch (ApiException e) { - result = ServiceUtil.returnFailure(e.getMessage()); - } catch (SdkSoapException e) { - result = ServiceUtil.returnFailure(e.getMessage()); - } catch (SdkException e) { + } catch (ApiException | SdkException | SdkSoapException e) { result = ServiceUtil.returnFailure(e.getMessage()); } catch (GenericEntityException e) { result = ServiceUtil.returnFailure(e.getMessage()); @@ -398,9 +374,7 @@ public class EbayStoreInventoryServices { } } } - } catch (GenericEntityException e) { - result = ServiceUtil.returnFailure(e.getMessage()); - } catch (GenericServiceException e) { + } catch (GenericEntityException | GenericServiceException e) { result = ServiceUtil.returnFailure(e.getMessage()); } result = ServiceUtil.returnSuccess(); diff --git a/ebaystore/src/main/java/org/apache/ofbiz/ebaystore/EbayStoreOptions.java b/ebaystore/src/main/java/org/apache/ofbiz/ebaystore/EbayStoreOptions.java index f5fa337..4bc4c75 100644 --- a/ebaystore/src/main/java/org/apache/ofbiz/ebaystore/EbayStoreOptions.java +++ b/ebaystore/src/main/java/org/apache/ofbiz/ebaystore/EbayStoreOptions.java @@ -122,13 +122,7 @@ public class EbayStoreOptions { EbayStoreHelper.createErrorLogMessage(userLogin, dispatcher, paramMap.get("productStoreId").toString(), resp.getAck().toString(), "GetStoreOptionsCall : retrieveThemeColorSchemeByThemeId", resp.getErrors(0).getLongMessage()); } } - } catch (ApiException e) { - e.printStackTrace(); - return "error"; - } catch (SdkSoapException e) { - e.printStackTrace(); - return "error"; - } catch (SdkException e) { + } catch (ApiException | SdkException | SdkSoapException e) { e.printStackTrace(); return "error"; } @@ -191,16 +185,12 @@ public class EbayStoreOptions { } } } - } catch (GenericServiceException e) { - Debug.logError(e.getMessage(), MODULE); } catch (EventHandlerException e) { Debug.logError(e.getMessage(), MODULE); - } catch (ApiException e) { - Debug.logError(e.getMessage(), MODULE); - } catch (SdkException e) { - Debug.logError(e.getMessage(), MODULE); } catch (Exception e) { Debug.logError(e.getMessage(), MODULE); + } catch (ApiException | SdkException e) { + Debug.logError(e.getMessage(), MODULE); } return "success"; } @@ -247,16 +237,12 @@ public class EbayStoreOptions { } } } - } catch (GenericServiceException e) { - Debug.logError(e.getMessage(), MODULE); } catch (EventHandlerException e) { Debug.logError(e.getMessage(), MODULE); - } catch (ApiException e) { - Debug.logError(e.getMessage(), MODULE); - } catch (SdkException e) { - Debug.logError(e.getMessage(), MODULE); } catch (Exception e) { Debug.logError(e.getMessage(), MODULE); + } catch (ApiException | SdkException e) { + Debug.logError(e.getMessage(), MODULE); } return "success"; } diff --git a/ecommerce/src/main/java/org/apache/ofbiz/ecommerce/janrain/JanrainHelper.java b/ecommerce/src/main/java/org/apache/ofbiz/ecommerce/janrain/JanrainHelper.java index 0615b63..877f108 100644 --- a/ecommerce/src/main/java/org/apache/ofbiz/ecommerce/janrain/JanrainHelper.java +++ b/ecommerce/src/main/java/org/apache/ofbiz/ecommerce/janrain/JanrainHelper.java @@ -181,9 +181,7 @@ public class JanrainHelper { throw new RuntimeException("Unexpected URL error", e); } catch (IOException e) { throw new RuntimeException("Unexpected IO error", e); - } catch (ParserConfigurationException e) { - throw new RuntimeException("Unexpected XML error", e); - } catch (SAXException e) { + } catch (ParserConfigurationException | SAXException e) { throw new RuntimeException("Unexpected XML error", e); } } diff --git a/ldap/src/main/java/org/apache/ofbiz/ldap/cas/OFBizCasAuthenticationHandler.java b/ldap/src/main/java/org/apache/ofbiz/ldap/cas/OFBizCasAuthenticationHandler.java index 52162b2..47f43ca 100644 --- a/ldap/src/main/java/org/apache/ofbiz/ldap/cas/OFBizCasAuthenticationHandler.java +++ b/ldap/src/main/java/org/apache/ofbiz/ldap/cas/OFBizCasAuthenticationHandler.java @@ -150,7 +150,6 @@ public final class OFBizCasAuthenticationHandler extends AbstractOFBizAuthentica String logoutUri = UtilXml.childElementValue(rootElement, "CasLogoutUri", "/logout"); try { response.sendRedirect(casUrl + logoutUri); - } catch (UnsupportedEncodingException e) { } catch (IOException e) { } return "success"; diff --git a/lucene/src/main/java/org/apache/ofbiz/content/search/ContentDocument.java b/lucene/src/main/java/org/apache/ofbiz/content/search/ContentDocument.java index fe829e3..64f8c55 100644 --- a/lucene/src/main/java/org/apache/ofbiz/content/search/ContentDocument.java +++ b/lucene/src/main/java/org/apache/ofbiz/content/search/ContentDocument.java @@ -129,12 +129,9 @@ public class ContentDocument implements LuceneDocument { String text; try { text = ContentWorker.renderContentAsText(dispatcher, contentId, null, locale, mimeTypeId, true); - } catch (GeneralException e) { + } catch (GeneralException | IOException e) { Debug.logError(e, MODULE); return false; - } catch (IOException e2) { - Debug.logError(e2, MODULE); - return false; } if (UtilValidate.isNotEmpty(text)) { Field field = new TextField("content", text, Store.NO); diff --git a/lucene/src/main/java/org/apache/ofbiz/content/search/ProductDocument.java b/lucene/src/main/java/org/apache/ofbiz/content/search/ProductDocument.java index 62adbc4..b7547e0 100644 --- a/lucene/src/main/java/org/apache/ofbiz/content/search/ProductDocument.java +++ b/lucene/src/main/java/org/apache/ofbiz/content/search/ProductDocument.java @@ -204,9 +204,7 @@ public class ProductDocument implements LuceneDocument { Map<String, Object> drContext = UtilMisc.<String, Object>toMap("product", product); String contentText = DataResourceWorker.renderDataResourceAsText(null, delegator, productContentAndInfo.getString("dataResourceId"), drContext, null, null, false); addTextField(doc, "content", contentText, false, "fullText", delegator); - } catch (IOException e1) { - Debug.logError(e1, "Error getting content text to index", MODULE); - } catch (GeneralException e1) { + } catch (IOException | GeneralException e1) { Debug.logError(e1, "Error getting content text to index", MODULE); } diff --git a/lucene/src/main/java/org/apache/ofbiz/content/search/SearchServices.java b/lucene/src/main/java/org/apache/ofbiz/content/search/SearchServices.java index 2f87030..4aa98d9 100644 --- a/lucene/src/main/java/org/apache/ofbiz/content/search/SearchServices.java +++ b/lucene/src/main/java/org/apache/ofbiz/content/search/SearchServices.java @@ -126,9 +126,7 @@ public class SearchServices { return ServiceUtil.returnError(ServiceUtil.getErrorMessage(result)); } } - } catch (GenericEntityException e) { - Debug.logError(e, MODULE); - } catch (GenericServiceException e) { + } catch (GenericEntityException | GenericServiceException e) { Debug.logError(e, MODULE); } return ServiceUtil.returnSuccess(); diff --git a/passport/src/main/java/org/apache/ofbiz/passport/event/GitHubEvents.java b/passport/src/main/java/org/apache/ofbiz/passport/event/GitHubEvents.java index 56a4d9f..24d758c 100644 --- a/passport/src/main/java/org/apache/ofbiz/passport/event/GitHubEvents.java +++ b/passport/src/main/java/org/apache/ofbiz/passport/event/GitHubEvents.java @@ -202,20 +202,11 @@ public class GitHubEvents { request.setAttribute("_ERROR_MESSAGE_", errMsg); return "error"; } - } catch (UnsupportedEncodingException e) { + } catch (URISyntaxException | ConversionException | IOException e) { request.setAttribute("_ERROR_MESSAGE_", e.toString()); return "error"; - } catch (IOException e) { - request.setAttribute("_ERROR_MESSAGE_", e.toString()); - return "error"; - } catch (ConversionException e) { - request.setAttribute("_ERROR_MESSAGE_", e.toString()); - return "error"; - } catch (URISyntaxException e) { - request.setAttribute("_ERROR_MESSAGE_", e.toString()); - return "error"; - } - + } + // Get User Profile HttpGet getMethod = new HttpGet(ApiEndpoint + UserApiUri); Map<String, Object> userInfo = null; @@ -291,11 +282,7 @@ public class GitHubEvents { userLogin.store(); request.setAttribute("USERNAME", userLogin.getString("userLoginId")); request.setAttribute("PASSWORD", autoPassword); - } catch (GenericEntityException e) { - Debug.logError(e.getMessage(), MODULE); - request.setAttribute("_ERROR_MESSAGE_", e.toString()); - return "error"; - } catch (AuthenticatorException e) { + } catch (GenericEntityException | AuthenticatorException e) { Debug.logError(e.getMessage(), MODULE); request.setAttribute("_ERROR_MESSAGE_", e.toString()); return "error"; diff --git a/passport/src/main/java/org/apache/ofbiz/passport/event/LinkedInEvents.java b/passport/src/main/java/org/apache/ofbiz/passport/event/LinkedInEvents.java index 2caf5bc..8efaad7 100644 --- a/passport/src/main/java/org/apache/ofbiz/passport/event/LinkedInEvents.java +++ b/passport/src/main/java/org/apache/ofbiz/passport/event/LinkedInEvents.java @@ -200,35 +200,17 @@ public class LinkedInEvents { request.setAttribute("_ERROR_MESSAGE_", errMsg); return "error"; } - } catch (UnsupportedEncodingException e) { + } catch (URISyntaxException | ConversionException | IOException e) { request.setAttribute("_ERROR_MESSAGE_", e.toString()); return "error"; - } catch (IOException e) { - request.setAttribute("_ERROR_MESSAGE_", e.toString()); - return "error"; - } catch (ConversionException e) { - request.setAttribute("_ERROR_MESSAGE_", e.toString()); - return "error"; - } catch (URISyntaxException e) { - request.setAttribute("_ERROR_MESSAGE_", e.toString()); - return "error"; - } - + } + // Get User Profile HttpGet getMethod = new HttpGet(TokenEndpoint + UserApiUri + "?oauth2_access_token=" + accessToken); Document userInfo = null; try { userInfo = LinkedInAuthenticator.getUserInfo(getMethod, UtilHttp.getLocale(request)); - } catch (IOException e) { - request.setAttribute("_ERROR_MESSAGE_", e.toString()); - return "error"; - } catch (AuthenticatorException e) { - request.setAttribute("_ERROR_MESSAGE_", e.toString()); - return "error"; - } catch (SAXException e) { - request.setAttribute("_ERROR_MESSAGE_", e.toString()); - return "error"; - } catch (ParserConfigurationException e) { + } catch (IOException | ParserConfigurationException | SAXException | AuthenticatorException e) { request.setAttribute("_ERROR_MESSAGE_", e.toString()); return "error"; } finally { @@ -298,11 +280,7 @@ public class LinkedInEvents { userLogin.store(); request.setAttribute("USERNAME", userLogin.getString("userLoginId")); request.setAttribute("PASSWORD", autoPassword); - } catch (GenericEntityException e) { - Debug.logError(e.getMessage(), MODULE); - request.setAttribute("_ERROR_MESSAGE_", e.toString()); - return "error"; - } catch (AuthenticatorException e) { + } catch (GenericEntityException | AuthenticatorException e) { Debug.logError(e.getMessage(), MODULE); request.setAttribute("_ERROR_MESSAGE_", e.toString()); return "error"; diff --git a/passport/src/main/java/org/apache/ofbiz/passport/user/GitHubAuthenticator.java b/passport/src/main/java/org/apache/ofbiz/passport/user/GitHubAuthenticator.java index ea1600c..f808c5f 100644 --- a/passport/src/main/java/org/apache/ofbiz/passport/user/GitHubAuthenticator.java +++ b/passport/src/main/java/org/apache/ofbiz/passport/user/GitHubAuthenticator.java @@ -114,9 +114,7 @@ public class GitHubAuthenticator implements Authenticator { user = GitHubAuthenticator.getUserInfo(getMethod, accessToken, tokenType, Locale.getDefault()); } } - } catch (GenericEntityException e) { - throw new AuthenticatorException(e.getMessage(), e); - } catch (AuthenticatorException e) { + } catch (GenericEntityException | AuthenticatorException e) { throw new AuthenticatorException(e.getMessage(), e); } finally { if (getMethod != null) { @@ -222,9 +220,7 @@ public class GitHubAuthenticator implements Authenticator { user = getUserInfo(getMethod, accessToken, tokenType, Locale.getDefault()); } } - } catch (GenericEntityException e) { - throw new AuthenticatorException(e.getMessage(), e); - } catch (AuthenticatorException e) { + } catch (GenericEntityException | AuthenticatorException e) { throw new AuthenticatorException(e.getMessage(), e); } return user; diff --git a/passport/src/main/java/org/apache/ofbiz/passport/user/LinkedInAuthenticator.java b/passport/src/main/java/org/apache/ofbiz/passport/user/LinkedInAuthenticator.java index 0316dd5..f79b37c 100644 --- a/passport/src/main/java/org/apache/ofbiz/passport/user/LinkedInAuthenticator.java +++ b/passport/src/main/java/org/apache/ofbiz/passport/user/LinkedInAuthenticator.java @@ -114,16 +114,10 @@ public class LinkedInAuthenticator implements Authenticator { user = LinkedInAuthenticator.getUserInfo(getMethod, Locale.getDefault()); } } - } catch (GenericEntityException e) { - throw new AuthenticatorException(e.getMessage(), e); - } catch (IOException e) { - throw new AuthenticatorException(e.getMessage(), e); - } catch (AuthenticatorException e) { + } catch (GenericEntityException | ParserConfigurationException | AuthenticatorException | IOException e) { throw new AuthenticatorException(e.getMessage(), e); } catch (SAXException e) { throw new AuthenticatorException(e.getMessage(), e); - } catch (ParserConfigurationException e) { - throw new AuthenticatorException(e.getMessage(), e); } finally { if (getMethod != null) { getMethod.releaseConnection(); @@ -228,16 +222,10 @@ public class LinkedInAuthenticator implements Authenticator { user = getUserInfo(getMethod, Locale.getDefault()); } } - } catch (GenericEntityException e) { - throw new AuthenticatorException(e.getMessage(), e); - } catch (IOException e) { - throw new AuthenticatorException(e.getMessage(), e); - } catch (AuthenticatorException e) { + } catch (GenericEntityException | ParserConfigurationException | AuthenticatorException | IOException e) { throw new AuthenticatorException(e.getMessage(), e); } catch (SAXException e) { throw new AuthenticatorException(e.getMessage(), e); - } catch (ParserConfigurationException e) { - throw new AuthenticatorException(e.getMessage(), e); } finally { if (getMethod != null) { getMethod.releaseConnection(); diff --git a/pricat/src/main/java/org/apache/ofbiz/htmlreport/HtmlReport.java b/pricat/src/main/java/org/apache/ofbiz/htmlreport/HtmlReport.java index 50ffafc..bb9d98a 100644 --- a/pricat/src/main/java/org/apache/ofbiz/htmlreport/HtmlReport.java +++ b/pricat/src/main/java/org/apache/ofbiz/htmlreport/HtmlReport.java @@ -860,9 +860,7 @@ public class HtmlReport extends AbstractReport { Object o = null; try { o = m.invoke(this, new Object[0]); - } catch (InvocationTargetException ite) { - // can usually be ignored - } catch (IllegalAccessException eae) { + } catch (InvocationTargetException | IllegalAccessException ite) { // can usually be ignored } if (o != null) { diff --git a/pricat/src/main/java/org/apache/ofbiz/pricat/AbstractPricatParser.java b/pricat/src/main/java/org/apache/ofbiz/pricat/AbstractPricatParser.java index 7ebe124..647c0d9 100644 --- a/pricat/src/main/java/org/apache/ofbiz/pricat/AbstractPricatParser.java +++ b/pricat/src/main/java/org/apache/ofbiz/pricat/AbstractPricatParser.java @@ -266,9 +266,6 @@ public abstract class AbstractPricatParser implements InterfacePricatParser { fos.flush(); fos.close(); workbook.close(); - } catch (FileNotFoundException e) { - report.println(e); - Debug.logError(e, MODULE); } catch (IOException e) { report.println(e); Debug.logError(e, MODULE); @@ -617,10 +614,7 @@ public abstract class AbstractPricatParser implements InterfacePricatParser { GenericValue historyValue = null; try { historyValue = EntityQuery.use(delegator).from("ExcelImportHistory").where("userLoginId", userLoginId, "sequenceNum", Long.valueOf(sequenceNum)).queryOne(); - } catch (NumberFormatException e) { - Debug.logError(e.getMessage(), MODULE); - return false; - } catch (GenericEntityException e) { + } catch (NumberFormatException | GenericEntityException e) { Debug.logError(e.getMessage(), MODULE); return false; } diff --git a/pricat/src/main/java/org/apache/ofbiz/pricat/PricatEvents.java b/pricat/src/main/java/org/apache/ofbiz/pricat/PricatEvents.java index 3a999fa..e8c4ba2 100644 --- a/pricat/src/main/java/org/apache/ofbiz/pricat/PricatEvents.java +++ b/pricat/src/main/java/org/apache/ofbiz/pricat/PricatEvents.java @@ -74,9 +74,6 @@ public class PricatEvents { Path file = Paths.get(path + fileName); byte[] bytes = Files.readAllBytes(file); UtilHttp.streamContentToBrowser(response, bytes, "application/octet-stream", URLEncoder.encode(fileName, "UTF-8")); - } catch (MalformedURLException e) { - Debug.logError(e.getMessage(), MODULE); - return "error"; } catch (IOException e) { Debug.logError(e.getMessage(), MODULE); return "error"; @@ -116,9 +113,6 @@ public class PricatEvents { byte[] bytes = Files.readAllBytes(path); path = Paths.get(originalPricatFileName); UtilHttp.streamContentToBrowser(response, bytes, "application/octet-stream", URLEncoder.encode(path.getName(path.getNameCount() - 1).toString(), "UTF-8")); - } catch (MalformedURLException e) { - Debug.logError(e.getMessage(), MODULE); - return "error"; } catch (IOException e) { Debug.logError(e.getMessage(), MODULE); return "error"; @@ -150,10 +144,7 @@ public class PricatEvents { GenericValue historyValue = null; try { historyValue = EntityQuery.use(delegator).from("ExcelImportHistory").where("userLoginId", userLoginId, "sequenceNum", Long.valueOf(sequenceNum)).queryOne(); - } catch (NumberFormatException e) { - Debug.logError(e.getMessage(), MODULE); - return "error"; - } catch (GenericEntityException e) { + } catch (NumberFormatException | GenericEntityException e) { Debug.logError(e.getMessage(), MODULE); return "error"; } @@ -172,9 +163,6 @@ public class PricatEvents { byte[] bytes = Files.readAllBytes(path); UtilHttp.streamContentToBrowser(response, bytes, "application/octet-stream", URLEncoder.encode(fileName, "UTF-8")); } - } catch (MalformedURLException e) { - Debug.logError(e.getMessage(), MODULE); - return "error"; } catch (IOException e) { Debug.logError(e.getMessage(), MODULE); return "error"; diff --git a/pricat/src/main/java/org/apache/ofbiz/pricat/sample/SamplePricatEvents.java b/pricat/src/main/java/org/apache/ofbiz/pricat/sample/SamplePricatEvents.java index b61ae59..aecb68f 100644 --- a/pricat/src/main/java/org/apache/ofbiz/pricat/sample/SamplePricatEvents.java +++ b/pricat/src/main/java/org/apache/ofbiz/pricat/sample/SamplePricatEvents.java @@ -69,9 +69,6 @@ public class SamplePricatEvents extends PricatEvents { Path file = Paths.get(path + fileName); byte[] bytes = Files.readAllBytes(file); UtilHttp.streamContentToBrowser(response, bytes, "application/octet-stream", URLEncoder.encode(fileName, "UTF-8")); - } catch (MalformedURLException e) { - Debug.logError(e.getMessage(), MODULE); - return "error"; } catch (IOException e) { Debug.logError(e.getMessage(), MODULE); return "error"; diff --git a/scrum/src/main/java/org/apache/ofbiz/scrum/ScrumServices.java b/scrum/src/main/java/org/apache/ofbiz/scrum/ScrumServices.java index 48373ea..c2f69f3 100644 --- a/scrum/src/main/java/org/apache/ofbiz/scrum/ScrumServices.java +++ b/scrum/src/main/java/org/apache/ofbiz/scrum/ScrumServices.java @@ -239,15 +239,9 @@ public class ScrumServices { } } } - } catch (IOException e) { + } catch (IOException | GenericServiceException | GenericEntityException e) { e.printStackTrace(); return ServiceUtil.returnError(e.getMessage()); - } catch (GenericEntityException entityEx) { - entityEx.printStackTrace(); - return ServiceUtil.returnError(entityEx.getMessage()); - } catch (GenericServiceException serviceEx) { - serviceEx.printStackTrace(); - return ServiceUtil.returnError(serviceEx.getMessage()); } return result; diff --git a/solr/src/main/java/org/apache/ofbiz/solr/ProductUtil.java b/solr/src/main/java/org/apache/ofbiz/solr/ProductUtil.java index ee3251b..f5277e5 100644 --- a/solr/src/main/java/org/apache/ofbiz/solr/ProductUtil.java +++ b/solr/src/main/java/org/apache/ofbiz/solr/ProductUtil.java @@ -230,8 +230,6 @@ public final class ProductUtil { } } } - } catch (GenericEntityException e) { - Debug.logError(e, e.getMessage(), MODULE); } catch (Exception e) { Debug.logError(e, e.getMessage(), MODULE); } diff --git a/solr/src/main/java/org/apache/ofbiz/solr/SolrProductSearch.java b/solr/src/main/java/org/apache/ofbiz/solr/SolrProductSearch.java index d9455c0..46f2fd2 100644 --- a/solr/src/main/java/org/apache/ofbiz/solr/SolrProductSearch.java +++ b/solr/src/main/java/org/apache/ofbiz/solr/SolrProductSearch.java @@ -96,19 +96,10 @@ public abstract class SolrProductSearch { } else { result = ServiceUtil.returnSuccess(); } - } - catch (GenericEntityException gee) { - Debug.logError(gee, gee.getMessage(), MODULE); - result = ServiceUtil.returnError(gee.toString()); - } - catch (GenericServiceException gse) { + } catch (GenericEntityException | GenericServiceException gse) { Debug.logError(gse, gse.getMessage(), MODULE); result = ServiceUtil.returnError(gse.toString()); } - catch (Exception e) { - Debug.logError(e, e.getMessage(), MODULE); - result = ServiceUtil.returnError(e.toString()); - } } else { final String statusMsg = "Solr ECA indexing disabled; skipping indexing for productId '" + productId + "'"; if (Debug.verboseOn()) Debug.logVerbose("Solr: addToSolr: " + statusMsg, MODULE); @@ -707,8 +698,7 @@ public abstract class SolrProductSearch { final String statusMsg = UtilProperties.getMessage(RESOURCE, "SolrClearedSolrIndexAndReindexedDocuments", UtilMisc.toMap("numDocs", numDocs), locale); result = ServiceUtil.returnSuccess(statusMsg); } - } - catch (MalformedURLException e) { + } catch (IOException | GenericServiceException e) { Debug.logError(e, e.getMessage(), MODULE); result = ServiceUtil.returnError(e.toString()); } @@ -726,28 +716,7 @@ public abstract class SolrProductSearch { Debug.logError(e, e.getMessage(), MODULE); result = ServiceUtil.returnError(e.toString()); } - } - catch (IOException e) { - Debug.logError(e, e.getMessage(), MODULE); - result = ServiceUtil.returnError(e.toString()); - } - catch (ServiceAuthException e) { - Debug.logError(e, e.getMessage(), MODULE); - result = ServiceUtil.returnError(e.toString()); - } - catch (ServiceValidationException e) { - Debug.logError(e, e.getMessage(), MODULE); - result = ServiceUtil.returnError(e.toString()); - } - catch (GenericServiceException e) { - Debug.logError(e, e.getMessage(), MODULE); - result = ServiceUtil.returnError(e.toString()); - } - catch (Exception e) { - Debug.logError(e, e.getMessage(), MODULE); - result = ServiceUtil.returnError(e.toString()); - } - finally { + } finally { if (client != null) { try { client.close();