Skip to content

Commit

Permalink
Improved: Remove redundant null checks (OFBIZ-10911)
Browse files Browse the repository at this point in the history
Redundant null checks detected by Eclipse has been removed.


git-svn-id: https://svn.apache.org/repos/asf/ofbiz/ofbiz-framework/trunk@1857896 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
mthl committed Apr 21, 2019
1 parent d7127ce commit d5e3c2d
Show file tree
Hide file tree
Showing 30 changed files with 156 additions and 197 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -212,8 +212,7 @@ public static Map<String, Object> createCreditCard(DispatchContext ctx, Map<Stri
// add a PartyContactMechPurpose of BILLING_LOCATION if necessary
String contactMechPurposeTypeId = "BILLING_LOCATION";

GenericValue tempVal = null;

GenericValue tempVal;
try {
List<GenericValue> allPCWPs = EntityQuery.use(delegator).from("PartyContactWithPurpose")
.where("partyId", partyId, "contactMechId", contactMechId, "contactMechPurposeTypeId", contactMechPurposeTypeId).queryList();
Expand Down Expand Up @@ -393,8 +392,7 @@ public static Map<String, Object> updateCreditCard(DispatchContext ctx, Map<Stri
// add a PartyContactMechPurpose of BILLING_LOCATION if necessary
String contactMechPurposeTypeId = "BILLING_LOCATION";

GenericValue tempVal = null;

GenericValue tempVal;
try {
List<GenericValue> allPCWPs = EntityQuery.use(delegator).from("PartyContactWithPurpose")
.where("partyId", partyId, "contactMechId", contactMechId, "contactMechPurposeTypeId", contactMechPurposeTypeId).queryList();
Expand Down Expand Up @@ -740,7 +738,7 @@ public static Map<String, Object> createEftAccount(DispatchContext ctx, Map<Stri
// add a PartyContactMechPurpose of BILLING_LOCATION if necessary
String contactMechPurposeTypeId = "BILLING_LOCATION";

GenericValue tempVal = null;
GenericValue tempVal;
try {
List<GenericValue> allPCWPs = EntityQuery.use(delegator).from("PartyContactWithPurpose")
.where("partyId", partyId, "contactMechId", contactMechId, "contactMechPurposeTypeId", contactMechPurposeTypeId).queryList();
Expand Down Expand Up @@ -871,8 +869,7 @@ public static Map<String, Object> updateEftAccount(DispatchContext ctx, Map<Stri
// add a PartyContactMechPurpose of BILLING_LOCATION if necessary
String contactMechPurposeTypeId = "BILLING_LOCATION";

GenericValue tempVal = null;

GenericValue tempVal;
try {
List<GenericValue> allPCWPs = EntityQuery.use(delegator).from("PartyContactWithPurpose")
.where("partyId", partyId, "contactMechId", contactMechId, "contactMechPurposeTypeId", contactMechPurposeTypeId).queryList();
Expand Down Expand Up @@ -976,7 +973,7 @@ public static Map<String, Object> createCheckAccount(DispatchContext ctx, Map<St
// add a PartyContactMechPurpose of BILLING_LOCATION if necessary
String contactMechPurposeTypeId = "BILLING_LOCATION";

GenericValue tempVal = null;
GenericValue tempVal;
try {
List<GenericValue> allPCWPs = EntityQuery.use(delegator).from("PartyContactWithPurpose")
.where("partyId", partyId, "contactMechId", contactMechId, "contactMechPurposeTypeId", contactMechPurposeTypeId).queryList();
Expand Down Expand Up @@ -1098,8 +1095,7 @@ public static Map<String, Object> updateCheckAccount(DispatchContext ctx, Map<St
// add a PartyContactMechPurpose of BILLING_LOCATION if necessary
String contactMechPurposeTypeId = "BILLING_LOCATION";

GenericValue tempVal = null;

GenericValue tempVal;
try {
List<GenericValue> allPCWPs = EntityQuery.use(delegator).from("PartyContactWithPurpose")
.where("partyId", partyId, "contactMechId", contactMechId, "contactMechPurposeTypeId", contactMechPurposeTypeId).queryList();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,6 @@ public static String updatePublishLinks(HttpServletRequest request, HttpServletR
Timestamp origFromDate = null;
for (Object [] pubArr : origSubList) {
Timestamp fromDate = (Timestamp)pubArr[2];
origSubContentId = null;
if (fromDate != null) {
origSubContentId = (String)pubArr[0];
origFromDate = fromDate;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,10 +163,8 @@ public static Map<String, Object> persistContentAndAssoc(DispatchContext dctx, M
List<String> tmpPurposes = StringUtil.split(contentPurposeString, "|");
contentPurposeList.addAll(tmpPurposes);
}
if (contentPurposeList != null) {
context.put("contentPurposeList", contentPurposeList);
context.put("contentPurposeString", null);
}
context.put("contentPurposeList", contentPurposeList);
context.put("contentPurposeString", null);

if (Debug.infoOn()) {
Debug.logInfo("in persist... contentPurposeList(0):" + contentPurposeList, module);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ public static void renderContentAsText(LocalDispatcher dispatcher, GenericValue
custMethod = EntityQuery.use(delegator).from("CustomMethod").where("customMethodId", content.get("customMethodId")).cache().queryOne();
}
if (custMethod != null) serviceName = custMethod.getString("customMethodName");
if (dispatcher != null && UtilValidate.isNotEmpty(serviceName)) {
if (UtilValidate.isNotEmpty(serviceName)) {
DispatchContext dctx = dispatcher.getDispatchContext();
ModelService service = dctx.getModelService(serviceName);
if (service != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -350,11 +350,9 @@ protected void loadParents(String partBomTypeId, Date inDate, List<GenericValue>
oneChildNode = new BOMNode(oneChild.getString("productId"), delegator, dispatcher, userLogin);
// Configurator
// If the node is null this means that the node has been discarded by the rules.
if (oneChildNode != null) {
oneChildNode.setParentNode(this);
oneChildNode.setTree(tree);
oneChildNode.loadParents(partBomTypeId, inDate, productFeatures);
}
oneChildNode.setParentNode(this);
oneChildNode.setTree(tree);
oneChildNode.loadParents(partBomTypeId, inDate, productFeatures);
childrenNodes.add(oneChildNode);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -319,16 +319,16 @@ public static Map<String, Object> getBOMTree(DispatchContext dctx, Map<String, ?
fromDate = new Date();
}

BOMTree tree = null;
BOMTree tree;
try {
tree = new BOMTree(productId, bomType, fromDate, type, delegator, dispatcher, userLogin);
} catch (GenericEntityException gee) {
return ServiceUtil.returnError(UtilProperties.getMessage(resource, "ManufacturingBomErrorCreatingBillOfMaterialsTree", UtilMisc.toMap("errorString", gee.getMessage()), locale));
}
if (tree != null && quantity != null) {
if (quantity != null) {
tree.setRootQuantity(quantity);
}
if (tree != null && amount != null) {
if (amount != null) {
tree.setRootAmount(amount);
}
result.put("tree", tree);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1253,9 +1253,7 @@ public static void reserveInventory(Delegator delegator, LocalDispatcher dispatc
Map<String, Object> reserveResult = dispatcher.runSync("reserveStoreInventory", reserveInput);
if (ServiceUtil.isError(reserveResult)) {
String invErrMsg = "The product ";
if (product != null) {
invErrMsg += getProductName(product, orderItem);
}
invErrMsg += getProductName(product, orderItem);
invErrMsg += " with ID " + orderItem.getString("productId") + " is no longer in stock. Please try reducing the quantity or removing the product from this order.";
resErrorMessages.add(invErrMsg);
}
Expand Down Expand Up @@ -5984,10 +5982,8 @@ public static Map<String, Object> updateOrderItemShipGroupAssoc(DispatchContext

if (rowNumber == null) {
Long count = EntityQuery.use(delegator).from("OrderItemShipGroupAssoc").where("orderId", orderId, "orderItemSeqId", orderItemSeqId).queryCount();
if (count != null) {
rowNumber = count.intValue();
result.put("rowNumber", rowNumber);
}
rowNumber = count.intValue();
result.put("rowNumber", rowNumber);
}

//find OISG Assoc
Expand Down Expand Up @@ -6099,7 +6095,7 @@ public static Map<String, Object> updateOrderItemShipGroupAssoc(DispatchContext
result.put("totalQuantity", totalQuantity);

//Only for multi service calling and the last row : test if orderItem quantity equals OrderItemShipGroupAssocs quantitys
if (rowCount != null && rowNumber != null ) {
if (rowCount != null) {
int rowCountInt = rowCount;
int rowNumberInt = rowNumber;
if (rowCountInt == rowNumberInt - 1) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -435,18 +435,20 @@ public static String setCheckOutOptions(HttpServletRequest request, HttpServletR
public static String checkoutValidation(HttpServletRequest request, HttpServletResponse response) {
ShoppingCart cart = (ShoppingCart) request.getSession().getAttribute("shoppingCart");
if (cart.isSalesOrder()) {
List<GenericValue> paymentMethodTypes = cart.getPaymentMethodTypes();
if (UtilValidate.isEmpty(paymentMethodTypes)) {
String errMsg = UtilProperties.getMessage(resource_error, "OrderNoPaymentMethodTypeSelected", (cart != null ? cart.getLocale() : UtilHttp.getLocale(request)));
request.setAttribute("_ERROR_MESSAGE_",errMsg);
return "error";
}
String shipmentMethod = cart.getShipmentMethodTypeId();
if (UtilValidate.isEmpty(shipmentMethod)) {
String errMsg = UtilProperties.getMessage(resource_error, "OrderNoShipmentMethodSelected", (cart != null ? cart.getLocale() : UtilHttp.getLocale(request)));
request.setAttribute("_ERROR_MESSAGE_",errMsg);
return "error";
}
List<GenericValue> paymentMethodTypes = cart.getPaymentMethodTypes();
if (UtilValidate.isEmpty(paymentMethodTypes)) {
String errMsg = UtilProperties.getMessage(resource_error, "OrderNoPaymentMethodTypeSelected",
cart.getLocale());
request.setAttribute("_ERROR_MESSAGE_",errMsg);
return "error";
}
String shipmentMethod = cart.getShipmentMethodTypeId();
if (UtilValidate.isEmpty(shipmentMethod)) {
String errMsg = UtilProperties.getMessage(resource_error, "OrderNoShipmentMethodSelected",
cart.getLocale());
request.setAttribute("_ERROR_MESSAGE_",errMsg);
return "error";
}
}
return "success";
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4708,7 +4708,7 @@ public GenericValue getOriginAddress(ShoppingCart cart) {
Delegator delegator = cart.delegator;
//check information from the cart ship info
try {
if (originAddress == null && facilityId != null) {
if (facilityId != null) {
originAddress = ShippingEvents.getShippingOriginContactMechFromFacility(delegator, facilityId);
}
if (originAddress == null && supplierPartyId != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -474,7 +474,7 @@ public static String restoreAutoSaveList(HttpServletRequest request, HttpServlet
Debug.logError(e, module);
}
cart.setAutoSaveListId(autoSaveListId);
} else if (userLogin != null) {
} else {
String existingAutoSaveListId = null;
try {
existingAutoSaveListId = getAutoSaveListId(delegator, dispatcher, null, userLogin, cart.getProductStoreId());
Expand Down Expand Up @@ -522,7 +522,7 @@ public static String restoreAutoSaveList(HttpServletRequest request, HttpServlet
if (okayToLoad) {
String prodCatalogId = CatalogWorker.getCurrentCatalogId(request);
try {
addListToCart(delegator, dispatcher, cart, prodCatalogId, autoSaveListId, false, false, userLogin != null ? true : false);
addListToCart(delegator, dispatcher, cart, prodCatalogId, autoSaveListId, false, false, true);
cart.setLastListRestore(UtilDateTime.nowTimestamp());
} catch (IllegalArgumentException e) {
Debug.logError(e, module);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ public static Map<String, Object> createListReorders(DispatchContext dctx, Map<S

// store the order
Map<String, Object> createResp = helper.createOrder(userLogin);
if (createResp == null || (createResp != null && ServiceUtil.isError(createResp))) {
if (createResp == null || ServiceUtil.isError(createResp)) {
Debug.logError("Cannot create order for shopping list - " + shoppingList, module);
} else {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ public static Map<String, Object> updateContactMech(DispatchContext ctx, Map<Str
}

String contactMechId = (String) context.get("contactMechId");
GenericValue contactMech = null;
GenericValue contactMech;
GenericValue partyContactMech = null;

try {
Expand Down Expand Up @@ -427,7 +427,7 @@ public static Map<String, Object> updatePostalAddress(DispatchContext ctx, Map<S
}

String contactMechId = (String) context.get("contactMechId");
GenericValue contactMech = null;
GenericValue contactMech;
GenericValue partyContactMech = null;

try {
Expand Down Expand Up @@ -469,8 +469,7 @@ public static Map<String, Object> updatePostalAddress(DispatchContext ctx, Map<S
GenericValue relatedEntityToSet = null;

if ("POSTAL_ADDRESS".equals(contactMech.getString("contactMechTypeId"))) {
GenericValue addr = null;

GenericValue addr;
try {
addr = EntityQuery.use(delegator).from("PostalAddress").where("contactMechId", contactMechId).queryOne();
} catch (GenericEntityException e) {
Expand Down Expand Up @@ -669,7 +668,6 @@ public static Map<String, Object> updateTelecomNumber(DispatchContext ctx, Map<S
} catch (GenericEntityException e) {
Debug.logWarning(e.getMessage(), module);
contactMech = null;
partyContactMech = null;
}
if (contactMech == null) {
return ServiceUtil.returnError(UtilProperties.getMessage(resourceError,
Expand All @@ -687,8 +685,7 @@ public static Map<String, Object> updateTelecomNumber(DispatchContext ctx, Map<S
GenericValue relatedEntityToSet = null;

if ("TELECOM_NUMBER".equals(contactMech.getString("contactMechTypeId"))) {
GenericValue telNum = null;

GenericValue telNum;
try {
telNum = EntityQuery.use(delegator).from("TelecomNumber").where("contactMechId", contactMechId).queryOne();
} catch (GenericEntityException e) {
Expand Down Expand Up @@ -834,7 +831,7 @@ public static Map<String, Object> createPartyContactMechPurpose(DispatchContext
String contactMechPurposeTypeId = (String) context.get("contactMechPurposeTypeId");
Timestamp fromDate = (Timestamp) context.get("fromDate");

GenericValue tempVal = null;
GenericValue tempVal;
try {
tempVal = EntityQuery.use(delegator).from("PartyContactWithPurpose")
.where("partyId", partyId, "contactMechId", contactMechId, "contactMechPurposeTypeId", contactMechPurposeTypeId)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ public static Map<String, Object> getProductCategoryAndLimitedMembers(DispatchCo
Debug.logError(e.getMessage(), module);
}

GenericValue productCategory = null;
GenericValue productCategory;
try {
productCategory = EntityQuery.use(delegator).from("ProductCategory").where("productCategoryId", productCategoryId).cache().queryOne();
} catch (GenericEntityException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
*******************************************************************************/
package org.apache.ofbiz.product.category;

import java.io.FileInputStream;
import java.io.IOException;
import java.net.URL;
import java.util.HashMap;
Expand Down Expand Up @@ -101,7 +100,6 @@ private SeoConfigUtil() {}
* Initialize url regular express configuration.
*/
public static void init() {
FileInputStream configFileIS = null;
String result = "success";
seoPatterns = new HashMap<String, Pattern>();
seoReplacements = new HashMap<String, String>();
Expand Down Expand Up @@ -322,15 +320,6 @@ public static void init() {
} catch (IOException e) {
result = "error";
Debug.logError(e, module);
} finally {
if (configFileIS != null) {
try {
configFileIS.close();
} catch (IOException e) {
result = "error";
Debug.logError(e, module);
}
}
}
if (seoReplacements.keySet().isEmpty()) {
useUrlRegexp = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,9 @@ public static ProductConfigWrapper getProductConfigWrapper(String productId, Str
} else {
configWrapper = new ProductConfigWrapper(configWrapper);
}
} catch (ProductConfigWrapperException we) {
configWrapper = null;
} catch (Exception e) {
Debug.logWarning(e.getMessage(), module);
configWrapper = null;
}
return configWrapper;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,6 @@ public static String updateProductAssoc(HttpServletRequest request, HttpServletR
productAssoc = EntityQuery.use(delegator).from(tempProductAssoc.getEntityName()).where(tempProductAssoc.getPrimaryKey()).queryOne();
} catch (GenericEntityException e) {
Debug.logWarning(e.getMessage(), module);
productAssoc = null;
}
if (productAssoc == null) {
errMsg = UtilProperties.getMessage(resource,"productevents.could_not_remove_product_association_exist", UtilHttp.getLocale(request));
Expand Down Expand Up @@ -348,8 +347,7 @@ public static String updateProductAssoc(HttpServletRequest request, HttpServletR
request.setAttribute("ProductAssocCreateFromDate", fromDate);
}

GenericValue productAssoc = null;

GenericValue productAssoc;
try {
productAssoc = EntityQuery.use(delegator).from(tempProductAssoc.getEntityName()).where(tempProductAssoc.getPrimaryKey()).queryOne();
} catch (GenericEntityException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -517,7 +517,7 @@ public static Map<String, Object> upsShipmentConfirm(DispatchContext dctx, Map<S
UtilXml.addChildElementValue(dimensionsElement, "Length", UtilValidate.isNotEmpty(boxLength) ? ""+boxLength.intValue() : "", shipmentConfirmRequestDoc);
UtilXml.addChildElementValue(dimensionsElement, "Width", UtilValidate.isNotEmpty(boxWidth) ? ""+boxWidth.intValue() : "", shipmentConfirmRequestDoc);
UtilXml.addChildElementValue(dimensionsElement, "Height", UtilValidate.isNotEmpty(boxHeight) ? ""+boxHeight.intValue() : "", shipmentConfirmRequestDoc);
} else if (shipmentPackage != null && UtilValidate.isNotEmpty(shipmentPackage.getBigDecimal("boxLength"))
} else if (UtilValidate.isNotEmpty(shipmentPackage.getBigDecimal("boxLength"))
&& UtilValidate.isNotEmpty(shipmentPackage.getBigDecimal("boxWidth"))
&& UtilValidate.isNotEmpty(shipmentPackage.getBigDecimal("boxHeight"))) {
Element dimensionsElement = UtilXml.addChildElement(packageElement, "Dimensions", shipmentConfirmRequestDoc);
Expand Down
Loading

0 comments on commit d5e3c2d

Please sign in to comment.