Author: jleroux
Date: Tue May 17 17:25:52 2011
New Revision: 1104423
URL:
http://svn.apache.org/viewvc?rev=1104423&view=revLog:
A patch from Martin Kreidenweis "NullPointerException in GenericDelegator during testMode rollback"
https://issues.apache.org/jira/browse/OFBIZ-4284Test mode rollback doesn't work right in GenericDelegator for calls to removeByPrimary() key and removeByValue() when the row to be deleted didn't exist in the first place. It creates a TestOperation with a null value and subsequently fails to create that during rollback.
First, the TestOperation shouldn't be created at all. Second, if null is passed to GenericDelegator.create() it tries to handle this, but fails with a NullPointerException.
Modified:
ofbiz/trunk/framework/entity/src/org/ofbiz/entity/GenericDelegator.java
Modified: ofbiz/trunk/framework/entity/src/org/ofbiz/entity/GenericDelegator.java
URL:
http://svn.apache.org/viewvc/ofbiz/trunk/framework/entity/src/org/ofbiz/entity/GenericDelegator.java?rev=1104423&r1=1104422&r2=1104423&view=diff==============================================================================
--- ofbiz/trunk/framework/entity/src/org/ofbiz/entity/GenericDelegator.java (original)
+++ ofbiz/trunk/framework/entity/src/org/ofbiz/entity/GenericDelegator.java Tue May 17 17:25:52 2011
@@ -861,7 +861,7 @@ public class GenericDelegator implements
return value;
} catch (GenericEntityException e) {
- String errMsg = "Failure in create operation for entity [" + value.getEntityName() + "]: " + e.toString() + ". Rolling back transaction.";
+ String errMsg = "Failure in create operation for entity [" + (value != null ? value.getEntityName() : "null") + "]: " + e.toString() + ". Rolling back transaction.";
Debug.logError(errMsg, module);
try {
// only rollback the transaction if we started one...
@@ -995,7 +995,9 @@ public class GenericDelegator implements
this.saveEntitySyncRemoveInfo(primaryKey);
if (testMode) {
- storeForTestRollback(new TestOperation(OperationType.DELETE, removedEntity));
+ if (removedEntity != null) {
+ storeForTestRollback(new TestOperation(OperationType.DELETE, removedEntity));
+ }
}
ecaRunner.evalRules(EntityEcaHandler.EV_RETURN, EntityEcaHandler.OP_REMOVE, primaryKey, false);
@@ -1061,7 +1063,9 @@ public class GenericDelegator implements
int num = helper.removeByPrimaryKey(value.getPrimaryKey());
if (testMode) {
- storeForTestRollback(new TestOperation(OperationType.DELETE, removedValue));
+ if (removedValue != null) {
+ storeForTestRollback(new TestOperation(OperationType.DELETE, removedValue));
+ }
}
this.saveEntitySyncRemoveInfo(value.getPrimaryKey());