Author: lektran
Date: Sun Oct 18 00:34:29 2009
New Revision: 826322
URL: http://svn.apache.org/viewvc?rev=826322&view=rev
Log:
Catch ClassCastExceptions in <store-value/> operations, these will occur if you
have a null GenericValue (perhaps from a lookup that returned no results), set
some fields on it and then try to store it. What you actually have at that
point is a FastMap created when you set the fields.
Also added use of the utility MethodContext.setErrorReturn(String,
SimpleMethod) rather than manually adding errors to the environment context.
Modified:
ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/entityops/StoreValue.java
Modified:
ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/entityops/StoreValue.java
URL:
http://svn.apache.org/viewvc/ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/entityops/StoreValue.java?rev=826322&r1=826321&r2=826322&view=diff
==============================================================================
---
ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/entityops/StoreValue.java
(original)
+++
ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/entityops/StoreValue.java
Sun Oct 18 00:34:29 2009
@@ -56,18 +56,19 @@
public boolean exec(MethodContext methodContext) {
boolean doCacheClear =
!"false".equals(methodContext.expandString(doCacheClearStr));
- GenericValue value = valueAcsr.get(methodContext);
+ GenericValue value = null;
+ try {
+ value = valueAcsr.get(methodContext);
+ } catch (ClassCastException e) {
+ String errMsg = "In store-value the value specified by valueAcsr
[" + valueAcsr + "] was not an instance of GenericValue, not storing";
+ Debug.logError(errMsg, module);
+ methodContext.setErrorReturn(errMsg, simpleMethod);
+ return false;
+ }
if (value == null) {
String errMsg = "In store-value a value was not found with the
specified valueAcsr: " + valueAcsr + ", not storing";
-
Debug.logWarning(errMsg, module);
- if (methodContext.getMethodType() == MethodContext.EVENT) {
- methodContext.putEnv(simpleMethod.getEventErrorMessageName(),
errMsg);
- methodContext.putEnv(simpleMethod.getEventResponseCodeName(),
simpleMethod.getDefaultErrorCode());
- } else if (methodContext.getMethodType() == MethodContext.SERVICE)
{
-
methodContext.putEnv(simpleMethod.getServiceErrorMessageName(), errMsg);
-
methodContext.putEnv(simpleMethod.getServiceResponseMessageName(),
simpleMethod.getDefaultErrorCode());
- }
+ methodContext.setErrorReturn(errMsg, simpleMethod);
return false;
}
@@ -76,14 +77,7 @@
} catch (GenericEntityException e) {
Debug.logError(e, module);
String errMsg = "ERROR: Could not complete the " +
simpleMethod.getShortDescription() + " process [problem storing the " +
valueAcsr + " value: " + e.getMessage() + "]";
-
- if (methodContext.getMethodType() == MethodContext.EVENT) {
- methodContext.putEnv(simpleMethod.getEventErrorMessageName(),
errMsg);
- methodContext.putEnv(simpleMethod.getEventResponseCodeName(),
simpleMethod.getDefaultErrorCode());
- } else if (methodContext.getMethodType() == MethodContext.SERVICE)
{
-
methodContext.putEnv(simpleMethod.getServiceErrorMessageName(), errMsg);
-
methodContext.putEnv(simpleMethod.getServiceResponseMessageName(),
simpleMethod.getDefaultErrorCode());
- }
+ methodContext.setErrorReturn(errMsg, simpleMethod);
return false;
}
return true;