[jbpm-commits] JBoss JBPM SVN: r5202 - in jbpm3/branches/jbpm-3.2-soa/modules/core/src: test/java/org/jbpm/graph/def and 1 other directory.
do-not-reply at jboss.org
do-not-reply at jboss.org
Thu Jul 2 20:08:25 EDT 2009
Author: alex.guizar at jboss.com
Date: 2009-07-02 20:08:25 -0400 (Thu, 02 Jul 2009)
New Revision: 5202
Modified:
jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/instantiation/Delegation.java
jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/instantiation/FieldInstantiator.java
jbpm3/branches/jbpm-3.2-soa/modules/core/src/test/java/org/jbpm/graph/def/ExceptionHandlerTest.java
Log:
Prevent NPE wrapped in DelegationException thrown when delegation class cannot be located; throw ClassNotFoundException wrapped in DelegationException instead
Modified: jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/instantiation/Delegation.java
===================================================================
--- jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/instantiation/Delegation.java 2009-07-02 23:37:21 UTC (rev 5201)
+++ jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/instantiation/Delegation.java 2009-07-03 00:08:25 UTC (rev 5202)
@@ -37,6 +37,7 @@
import org.dom4j.io.XMLWriter;
import org.jbpm.JbpmException;
+import org.jbpm.graph.def.DelegationException;
import org.jbpm.graph.def.ProcessDefinition;
import org.jbpm.jpdl.xml.JpdlXmlReader;
import org.jbpm.jpdl.xml.Parsable;
@@ -156,17 +157,15 @@
}
}
- // load the class that needs to be instantiated
- Class delegationClass = null;
try {
- delegationClass = Class.forName(className, false, classLoader);
+ // load the class that needs to be instantiated
+ Class delegationClass = Class.forName(className, false, classLoader);
+ // instantiate the object
+ return instantiator.instantiate(delegationClass, configuration);
}
catch (ClassNotFoundException e) {
- log.error("couldn't load delegation class '" + className + "'", e);
+ throw new DelegationException("could not load delegation class '" + className + "'", e);
}
-
- // instantiate the object
- return instantiator.instantiate(delegationClass, configuration);
}
// equals ///////////////////////////////////////////////////////////////////
Modified: jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/instantiation/FieldInstantiator.java
===================================================================
--- jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/instantiation/FieldInstantiator.java 2009-07-02 23:37:21 UTC (rev 5201)
+++ jbpm3/branches/jbpm-3.2-soa/modules/core/src/main/java/org/jbpm/instantiation/FieldInstantiator.java 2009-07-03 00:08:25 UTC (rev 5202)
@@ -49,7 +49,6 @@
public class FieldInstantiator implements Instantiator {
public Object instantiate(Class clazz, String configuration) {
-
// create a new instance with the default constructor
Object newInstance = newInstance(clazz);
@@ -114,15 +113,15 @@
}
protected Object newInstance(Class clazz) {
- Object newInstance = null;
try {
- newInstance = clazz.newInstance();
+ return clazz.newInstance();
}
- catch (Exception e) {
- log.error("couldn't instantiate type '" + clazz.getName() + "' with the default constructor");
- throw new JbpmException(e);
+ catch (InstantiationException e) {
+ throw new JbpmException("could not instantiate " + clazz, e);
}
- return newInstance;
+ catch (IllegalAccessException e) {
+ throw new JbpmException("could not access " + clazz, e);
+ }
}
public static Object getValue(Class type, Element propertyElement) {
Modified: jbpm3/branches/jbpm-3.2-soa/modules/core/src/test/java/org/jbpm/graph/def/ExceptionHandlerTest.java
===================================================================
--- jbpm3/branches/jbpm-3.2-soa/modules/core/src/test/java/org/jbpm/graph/def/ExceptionHandlerTest.java 2009-07-02 23:37:21 UTC (rev 5201)
+++ jbpm3/branches/jbpm-3.2-soa/modules/core/src/test/java/org/jbpm/graph/def/ExceptionHandlerTest.java 2009-07-03 00:08:25 UTC (rev 5202)
@@ -26,122 +26,114 @@
import org.jbpm.graph.exe.ProcessInstance;
/**
- *
* @author bernd.ruecker at camunda.com
*/
public class ExceptionHandlerTest extends AbstractJbpmTestCase {
- public static class NoExceptionAction implements ActionHandler
- {
- public void execute(ExecutionContext executionContext) throws Exception
- {
+ public static class NoExceptionAction implements ActionHandler {
+ private static final long serialVersionUID = 1L;
+
+ public void execute(ExecutionContext executionContext) throws Exception {
}
}
- public static class ThrowExceptionAction implements ActionHandler
- {
- public void execute(ExecutionContext executionContext) throws Exception
- {
+ public static class ThrowExceptionAction implements ActionHandler {
+ private static final long serialVersionUID = 1L;
+
+ public void execute(ExecutionContext executionContext) throws Exception {
throw new Exception("exception in action handler");
}
}
- public static class ThrowInnerExceptionAction implements ActionHandler
- {
- public void execute(ExecutionContext executionContext) throws Exception
- {
+ public static class ThrowInnerExceptionAction implements ActionHandler {
+ private static final long serialVersionUID = 1L;
+
+ public void execute(ExecutionContext executionContext) throws Exception {
throw new Exception("exception inside of exception handler");
}
}
-
- public void testExceptionHandlerThrowingExcption()
- {
-
- String xml =
- "<?xml version='1.0' encoding='UTF-8'?>"
- +"<process-definition name='TestException'>"
- +" <start-state name='start'>"
- +" <transition name='to_state' to='first'>"
- +" <action class='org.jbpm.graph.def.ExceptionHandlerTest$ThrowExceptionAction' />"
- +" </transition>"
- +" </start-state> "
- +" <state name='first'>"
- +" <transition to='end' />"
- +" </state> "
- +" <end-state name='end' />"
- +" <exception-handler>"
- +" <action class='org.jbpm.graph.def.ExceptionHandlerTest$ThrowInnerExceptionAction' />"
- +" </exception-handler>"
- +"</process-definition>";
-
+
+ public void testExceptionHandlerThrowingException() {
+ String xml = "<?xml version='1.0' encoding='UTF-8'?>" +
+ "<process-definition name='TestException'>" +
+ " <start-state name='start'>" +
+ " <transition to='end'>" +
+ " <action class='" +
+ ThrowExceptionAction.class.getName() +
+ "' />" +
+ " </transition>" +
+ " </start-state> " +
+ " <end-state name='end' />" +
+ " <exception-handler>" +
+ " <action class='" +
+ ThrowInnerExceptionAction.class.getName() +
+ "' />" +
+ " </exception-handler>" +
+ "</process-definition>";
+
ProcessDefinition def = ProcessDefinition.parseXmlString(xml);
ProcessInstance pi = def.createProcessInstance();
- try
- {
- pi.getRootToken().signal();
+ try {
+ pi.signal();
}
- catch (DelegationException ex)
- {
+ catch (DelegationException ex) {
// check that exception is thrown to the client nested in a DelegationException
assertEquals("exception inside of exception handler", ex.getCause().getMessage());
}
}
-
+
public void testMissingExceptionHandlerClass() {
- String xml =
- "<?xml version='1.0' encoding='UTF-8'?>"
- +"<process-definition name='TestException'>"
- +" <start-state name='start'>"
- +" <transition name='to_state' to='first'>"
- +" <action class='org.jbpm.graph.def.ExceptionHandlerTest$ThrowExceptionAction' />"
- +" </transition>"
- +" </start-state> "
- +" <state name='first'>"
- +" <transition to='end' />"
- +" </state> "
- +" <end-state name='end' />"
- +" <exception-handler>"
- +" <action class='org.jbpm.graph.def.ExceptionHandlerTest$DOESNTEXIST' />"
- +" </exception-handler>"
- +"</process-definition>";
-
- ProcessDefinition def = ProcessDefinition.parseXmlString(xml);
+ String xml = "<?xml version='1.0' encoding='UTF-8'?>" +
+ "<process-definition name='TestException'>" +
+ " <start-state name='start'>" +
+ " <transition to='end'>" +
+ " <action class='" +
+ ThrowExceptionAction.class.getName() +
+ "' />" +
+ " </transition>" +
+ " </start-state> " +
+ " <end-state name='end' />" +
+ " <exception-handler>" +
+ " <action class='org.jbpm.graph.def.ExceptionHandlerTest$DOESNOTEXIST' />" +
+ " </exception-handler>" +
+ "</process-definition>";
+
+ ProcessDefinition def = ProcessDefinition.parseXmlString(xml);
ProcessInstance pi = def.createProcessInstance();
-
- try
- {
+
+ try {
pi.getRootToken().signal();
}
- catch (DelegationException ex)
- {
+ catch (DelegationException ex) {
// check that exception is thrown to the client nested in a DelegationException
- assertEquals(NullPointerException.class, ex.getCause().getClass());
+ assertSame(ClassNotFoundException.class, ex.getCause().getClass());
}
}
public void testNoException() {
- String xml =
- "<?xml version='1.0' encoding='UTF-8'?>"
- +"<process-definition name='TestException'>"
- +" <start-state name='start'>"
- +" <transition name='to_state' to='first'>"
- +" <action class='org.jbpm.graph.def.ExceptionHandlerTest$ThrowExceptionAction' />"
- +" </transition>"
- +" </start-state> "
- +" <state name='first'>"
- +" <transition to='end' />"
- +" </state> "
- +" <end-state name='end' />"
- +" <exception-handler>"
- +" <action class='org.jbpm.graph.def.ExceptionHandlerTest$NoExceptionAction' />"
- +" </exception-handler>"
- +"</process-definition>";
+ String xml = "<?xml version='1.0' encoding='UTF-8'?>" +
+ "<process-definition name='TestException'>" +
+ " <start-state name='start'>" +
+ " <transition to='end'>" +
+ " <action class='" +
+ ThrowExceptionAction.class.getName() +
+ "' />" +
+ " </transition>" +
+ " </start-state> " +
+ " <end-state name='end' />" +
+ " <exception-handler>" +
+ " <action class='" +
+ NoExceptionAction.class.getName() +
+ "' />" +
+ " </exception-handler>" +
+ "</process-definition>";
ProcessDefinition def = ProcessDefinition.parseXmlString(xml);
ProcessInstance pi = def.createProcessInstance();
- pi.getRootToken().signal();
-
- // exception is handled correctly
- }
+ pi.signal();
+
+ // exception is handled correctly
+ assertTrue("expected " + pi + " to have ended", pi.hasEnded());
+ }
}
More information about the jbpm-commits
mailing list