[jbpm-commits] JBoss JBPM SVN: r7046 - in jbpm3/branches/jbpm-3.2-soa/core/src: main/java/org/jbpm/context/exe/converter and 3 other directories.
do-not-reply at jboss.org
do-not-reply at jboss.org
Tue Nov 15 06:17:23 EST 2011
Author: marco.rietveld
Date: 2011-11-15 06:17:22 -0500 (Tue, 15 Nov 2011)
New Revision: 7046
Modified:
jbpm3/branches/jbpm-3.2-soa/core/src/main/java/org/jbpm/bytes/ByteArray.java
jbpm3/branches/jbpm-3.2-soa/core/src/main/java/org/jbpm/bytes/ByteBlockChopper.java
jbpm3/branches/jbpm-3.2-soa/core/src/main/java/org/jbpm/context/exe/converter/SerializableToByteArrayConverter.java
jbpm3/branches/jbpm-3.2-soa/core/src/main/java/org/jbpm/context/exe/variableinstance/ByteArrayInstance.java
jbpm3/branches/jbpm-3.2-soa/core/src/test/java/org/jbpm/bytes/ByteArrayDbTest.java
jbpm3/branches/jbpm-3.2-soa/core/src/test/java/org/jbpm/context/exe/variableinstance/SerializableInstanceDbTest.java
Log:
JBPM3441: Serializable Process Variable de/serialization results in an NPE in a non-trivial case
Modified: jbpm3/branches/jbpm-3.2-soa/core/src/main/java/org/jbpm/bytes/ByteArray.java
===================================================================
--- jbpm3/branches/jbpm-3.2-soa/core/src/main/java/org/jbpm/bytes/ByteArray.java 2011-11-15 09:52:28 UTC (rev 7045)
+++ jbpm3/branches/jbpm-3.2-soa/core/src/main/java/org/jbpm/bytes/ByteArray.java 2011-11-15 11:17:22 UTC (rev 7046)
@@ -67,15 +67,15 @@
}
public void update(ByteArray value) {
- List otherByteBlocks = value.getByteBlocks();
+ List otherByteBlocks = (value != null ? value.getByteBlocks() : null);
// Different than constructor:
- // 1. clear on empty list.
+ // 1. clear to empty list.
this.byteBlocks.clear();
if (otherByteBlocks != null) {
// 2. use addAll in order to work as much as possible with JPA/ORM
this.byteBlocks.addAll(otherByteBlocks);
}
- this.name = value.name;
+ this.name = (value != null ? value.name : null );
}
public byte[] getBytes() {
Modified: jbpm3/branches/jbpm-3.2-soa/core/src/main/java/org/jbpm/bytes/ByteBlockChopper.java
===================================================================
--- jbpm3/branches/jbpm-3.2-soa/core/src/main/java/org/jbpm/bytes/ByteBlockChopper.java 2011-11-15 09:52:28 UTC (rev 7045)
+++ jbpm3/branches/jbpm-3.2-soa/core/src/main/java/org/jbpm/bytes/ByteBlockChopper.java 2011-11-15 11:17:22 UTC (rev 7046)
@@ -59,7 +59,8 @@
}
else if (byteCount > 0) {
if (log.isTraceEnabled()) log.trace("no need to chop " + byteCount + " bytes");
- bytes = Collections.singletonList(byteArray);
+ bytes = new ArrayList(1);
+ bytes.add(byteArray);
}
}
return bytes;
Modified: jbpm3/branches/jbpm-3.2-soa/core/src/main/java/org/jbpm/context/exe/converter/SerializableToByteArrayConverter.java
===================================================================
--- jbpm3/branches/jbpm-3.2-soa/core/src/main/java/org/jbpm/context/exe/converter/SerializableToByteArrayConverter.java 2011-11-15 09:52:28 UTC (rev 7045)
+++ jbpm3/branches/jbpm-3.2-soa/core/src/main/java/org/jbpm/context/exe/converter/SerializableToByteArrayConverter.java 2011-11-15 11:17:22 UTC (rev 7046)
@@ -78,17 +78,22 @@
public Object revert(Object o, final ProcessDefinition processDefinition) {
ByteArray byteArray = (ByteArray) o;
- InputStream memoryStream = new ByteArrayInputStream(byteArray.getBytes());
- try {
- ObjectInputStream objectStream = new CustomLoaderObjectInputStream(memoryStream,
- JbpmConfiguration.getProcessClassLoader(processDefinition));
- return objectStream.readObject();
+ if( byteArray.getBytes().length > 0 ) {
+ InputStream memoryStream = new ByteArrayInputStream(byteArray.getBytes());
+ try {
+ ObjectInputStream objectStream = new CustomLoaderObjectInputStream(memoryStream,
+ JbpmConfiguration.getProcessClassLoader(processDefinition));
+ return objectStream.readObject();
+ }
+ catch (IOException e) {
+ throw new JbpmException("failed to deserialize object", e);
+ }
+ catch (ClassNotFoundException e) {
+ throw new JbpmException("serialized class not found", e);
+ }
}
- catch (IOException e) {
- throw new JbpmException("failed to deserialize object", e);
+ else {
+ return null;
}
- catch (ClassNotFoundException e) {
- throw new JbpmException("serialized class not found", e);
- }
}
}
Modified: jbpm3/branches/jbpm-3.2-soa/core/src/main/java/org/jbpm/context/exe/variableinstance/ByteArrayInstance.java
===================================================================
--- jbpm3/branches/jbpm-3.2-soa/core/src/main/java/org/jbpm/context/exe/variableinstance/ByteArrayInstance.java 2011-11-15 09:52:28 UTC (rev 7045)
+++ jbpm3/branches/jbpm-3.2-soa/core/src/main/java/org/jbpm/context/exe/variableinstance/ByteArrayInstance.java 2011-11-15 11:17:22 UTC (rev 7046)
@@ -53,12 +53,13 @@
Session session = jbpmContext.getSession();
if (session != null) {
valueToUpdate = (ByteArray) session.get(ByteArray.class, new Long(this.value.getId()), LockMode.UPGRADE);
- valueToUpdate.update((ByteArray) value);
+ if( valueToUpdate != null ) {
+ valueToUpdate.update((ByteArray) value);
+ }
}
}
// if for some reason, this.value is NOT in the (hibernate) session, update it anyway.
- // -- but then there's something _VERY_ weird and wrong going on.
if( valueToUpdate == null ) {
this.value.update((ByteArray) value);
}
Modified: jbpm3/branches/jbpm-3.2-soa/core/src/test/java/org/jbpm/bytes/ByteArrayDbTest.java
===================================================================
--- jbpm3/branches/jbpm-3.2-soa/core/src/test/java/org/jbpm/bytes/ByteArrayDbTest.java 2011-11-15 09:52:28 UTC (rev 7045)
+++ jbpm3/branches/jbpm-3.2-soa/core/src/test/java/org/jbpm/bytes/ByteArrayDbTest.java 2011-11-15 11:17:22 UTC (rev 7046)
@@ -49,7 +49,7 @@
newTransaction();
ByteArray retrievedByteArray = (ByteArray) session.load(ByteArray.class, new Long(
byteArray.getId()));
- assertNull(retrievedByteArray.getBytes());
+ assertTrue(retrievedByteArray.getBytes().length == 0);
session.delete(retrievedByteArray);
}
@@ -91,7 +91,7 @@
newTransaction();
ByteArray retrievedByteArray = (ByteArray) session.load(ByteArray.class, new Long(
byteArray.getId()));
- assertNull(retrievedByteArray.getBytes());
+ assertTrue(retrievedByteArray.getBytes().length == 0);
session.delete(retrievedByteArray);
}
Modified: jbpm3/branches/jbpm-3.2-soa/core/src/test/java/org/jbpm/context/exe/variableinstance/SerializableInstanceDbTest.java
===================================================================
--- jbpm3/branches/jbpm-3.2-soa/core/src/test/java/org/jbpm/context/exe/variableinstance/SerializableInstanceDbTest.java 2011-11-15 09:52:28 UTC (rev 7045)
+++ jbpm3/branches/jbpm-3.2-soa/core/src/test/java/org/jbpm/context/exe/variableinstance/SerializableInstanceDbTest.java 2011-11-15 11:17:22 UTC (rev 7046)
@@ -24,6 +24,7 @@
import java.util.List;
import org.hibernate.Session;
+import org.jbpm.JbpmConfiguration;
import org.jbpm.context.def.ContextDefinition;
import org.jbpm.context.exe.ContextInstance;
import org.jbpm.context.exe.MySerializableClass;
@@ -49,6 +50,14 @@
}
+ protected JbpmConfiguration getJbpmConfiguration() {
+ if (jbpmConfiguration == null) {
+ // disable logging service to prevent logs from referencing custom object
+ jbpmConfiguration = JbpmConfiguration.parseResource("org/jbpm/context/exe/jbpm.cfg.xml");
+ }
+ return jbpmConfiguration;
+ }
+
protected void tearDown() throws Exception {
super.tearDown();
}
@@ -71,12 +80,12 @@
contextInstance.setVariable("a", new MySerializableClass(555));
processInstance = saveAndReload(processInstance);
- numByteArrayRows = getLatestDbId("ID_", "JBPM_BYTEARRAY");
- numByteBlockRows = getLatestDbId("PROCESSFILE_", "JBPM_BYTEBLOCK");
+ int newByteArrayRows = getLatestDbId("ID_", "JBPM_BYTEARRAY");
+ int newByteBlockRows = getLatestDbId("PROCESSFILE_", "JBPM_BYTEBLOCK");
// check db ids again
- assertTrue(numByteArrayRows > 0);
- assertTrue(numByteBlockRows > 0);
+ assertTrue(newByteArrayRows > 0);
+ assertTrue(newByteBlockRows > 0);
contextInstance = processInstance.getContextInstance();
assertEquals(new MySerializableClass(555), contextInstance.getVariable("a"));
@@ -84,11 +93,35 @@
// check if db ids are the same
// 1. One ByteArray object for var
// 2. One newValue for 1rst ByteArrayUpdateLog
- // 3. One newValue and one oldValue for 2nd ByteArrayUpdateLog
+ // 3. One newValue
+ // 4. and one oldValue for 2nd ByteArrayUpdateLog
// TOTAL = 4
// If a _NEW_ ByteArray object is made, then there would be 5 ByteArray objects and byte []'s
- assertTrue("Too many ByteArray objects have been made [" + numByteArrayRows + "]", numByteArrayRows == 4 );
- assertTrue("Too many byte [] objects have been persisted [" + numByteBlockRows + "]", numByteBlockRows == 4 );
+ assertTrue("Too many ByteArray objects have been made [" + numByteArrayRows + "!=" + newByteArrayRows + "]", numByteArrayRows == newByteArrayRows );
+ assertTrue("Too many byte [] objects have been persisted [" + numByteBlockRows + "!=" + newByteBlockRows + "]", numByteBlockRows == newByteBlockRows );
+
+ // Check that null's don't cause a problem.
+ contextInstance.setVariable("a", null);
+ processInstance = saveAndReload(processInstance);
+ assertEquals("Null variable not retrieved as null.", null, contextInstance.getVariable("a"));
+
+ newByteArrayRows = getLatestDbId("ID_", "JBPM_BYTEARRAY");
+ newByteBlockRows = getLatestDbId("PROCESSFILE_", "JBPM_BYTEBLOCK");
+
+ // 4. One oldValue for 3rd ByteArrayUpdateLog (newValue is null)
+ assertTrue("Too many ByteArray objects have been made [" + numByteArrayRows + "!=" + newByteArrayRows + "]", numByteArrayRows == newByteArrayRows );
+ assertTrue("Too many byte [] objects have been persisted [" + numByteBlockRows + "! >=" + newByteBlockRows + "]", numByteBlockRows >= newByteBlockRows );
+
+ // Refill var
+ contextInstance.setVariable("a", new MySerializableClass(123));
+ processInstance = saveAndReload(processInstance);
+
+ newByteArrayRows = getLatestDbId("ID_", "JBPM_BYTEARRAY");
+ newByteBlockRows = getLatestDbId("PROCESSFILE_", "JBPM_BYTEBLOCK");
+
+ // Same as before..
+ assertTrue("Too many ByteArray objects have been made [" + numByteArrayRows + "!=" + newByteArrayRows + "]", numByteArrayRows == newByteArrayRows );
+ assertTrue("Too many byte [] objects have been persisted [" + numByteBlockRows + "!=" + newByteBlockRows + "]", numByteBlockRows == newByteBlockRows );
}
protected int getLatestDbId(String idName, String tableName) {
More information about the jbpm-commits
mailing list