From 8deead6052dc1be81a2e99a24ca3b1a51412df8a Mon Sep 17 00:00:00 2001 From: Nicolas Malin Date: Fri, 11 Aug 2017 17:02:34 +0000 Subject: [PATCH] Fixed: Related to the issue OFBIZ-6401Connect OFBiz to a read only database Escape null pointer exception stack trace when the helper return no value git-svn-id: https://svn.apache.org/repos/asf/ofbiz/ofbiz-framework/trunk@1804824 13f79535-47bb-0310-9956-ffa450edef68 --- .../org/apache/ofbiz/entity/GenericDelegator.java | 11 ++++++----- .../org/apache/ofbiz/webapp/stats/VisitHandler.java | 5 ++++- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/framework/entity/src/main/java/org/apache/ofbiz/entity/GenericDelegator.java b/framework/entity/src/main/java/org/apache/ofbiz/entity/GenericDelegator.java index 0116fe870d..00db9105ed 100644 --- a/framework/entity/src/main/java/org/apache/ofbiz/entity/GenericDelegator.java +++ b/framework/entity/src/main/java/org/apache/ofbiz/entity/GenericDelegator.java @@ -838,13 +838,14 @@ public class GenericDelegator implements Delegator { ecaRunner.evalRules(EntityEcaHandler.EV_CACHE_CLEAR, EntityEcaHandler.OP_CREATE, value, false); this.clearCacheLine(value); } + ecaRunner.evalRules(EntityEcaHandler.EV_RETURN, EntityEcaHandler.OP_CREATE, value, false); } - ecaRunner.evalRules(EntityEcaHandler.EV_RETURN, EntityEcaHandler.OP_CREATE, value, false); TransactionUtil.commit(beganTransaction); return value; } catch (Exception e) { - String errMsg = "Failure in createSetNextSeqId operation for entity [" + value.getEntityName() + "]: " + e.toString() + ". Rolling back transaction."; + String entityName = value != null ? value.getEntityName() : "invalid Generic Value"; + String errMsg = "Failure in createSetNextSeqId operation for entity [" + entityName + "]: " + e.toString() + ". Rolling back transaction."; Debug.logError(e, errMsg, module); TransactionUtil.rollback(beganTransaction, errMsg, e); throw new GenericEntityException(e); @@ -894,13 +895,13 @@ public class GenericDelegator implements Delegator { ecaRunner.evalRules(EntityEcaHandler.EV_CACHE_CLEAR, EntityEcaHandler.OP_CREATE, value, false); this.clearCacheLine(value); } + ecaRunner.evalRules(EntityEcaHandler.EV_RETURN, EntityEcaHandler.OP_CREATE, value, false); } - ecaRunner.evalRules(EntityEcaHandler.EV_RETURN, EntityEcaHandler.OP_CREATE, value, false); TransactionUtil.commit(beganTransaction); return value; } catch (Exception e) { - String errMsg = "Failure in create operation for entity [" + (value != null ? value.getEntityName() : "null") + "]: " + e.toString() + ". Rolling back transaction."; + String errMsg = "Failure in create operation for entity [" + (value != null ? value.getEntityName() : "value is null") + "]: " + e.toString() + ". Rolling back transaction."; Debug.logError(errMsg, module); TransactionUtil.rollback(beganTransaction, errMsg, e); throw new GenericEntityException(e); @@ -930,7 +931,7 @@ public class GenericDelegator implements Delegator { TransactionUtil.commit(beganTransaction); return value; } catch (Exception e) { - String errMsg = "Failure in createOrStore operation for entity [" + value.getEntityName() + "]: " + e.toString() + ". Rolling back transaction."; + String errMsg = "Failure in createOrStore operation for entity [" + (value != null ? value.getEntityName() : "value is null") + "]: " + e.toString() + ". Rolling back transaction."; Debug.logError(e, errMsg, module); TransactionUtil.rollback(beganTransaction, errMsg, e); throw new GenericEntityException(e); diff --git a/framework/webapp/src/main/java/org/apache/ofbiz/webapp/stats/VisitHandler.java b/framework/webapp/src/main/java/org/apache/ofbiz/webapp/stats/VisitHandler.java index 03411e90b2..93f4b5be43 100644 --- a/framework/webapp/src/main/java/org/apache/ofbiz/webapp/stats/VisitHandler.java +++ b/framework/webapp/src/main/java/org/apache/ofbiz/webapp/stats/VisitHandler.java @@ -254,7 +254,10 @@ public class VisitHandler { // looks like we have an ID that doesn't exist in our database, so we'll create a new one visitor = delegator.makeValue("Visitor"); visitor = delegator.createSetNextSeqId(visitor); - if (Debug.infoOn()) Debug.logInfo("The visitorId [" + cookieVisitorId + "] found in cookie was invalid, creating new Visitor with ID [" + visitor.getString("visitorId") + "]", module); + if (Debug.infoOn()) { + String visitorId = visitor != null ? visitor.getString("visitorId") : "empty visitor"; + Debug.logInfo("The visitorId [" + cookieVisitorId + "] found in cookie was invalid, creating new Visitor with ID [" + visitorId + "]", module); + } } } catch (GenericEntityException e) { Debug.logError(e, "Error finding visitor with ID from cookie: " + cookieVisitorId, module);