Uploaded image for project: 'jBPM'
  1. jBPM
  2. JBPM-2929

ClassCastException after reading serialized variable

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Done
    • Icon: Major Major
    • jBPM 4.5
    • jBPM 4.4
    • Runtime Engine
    • None

      Related to JBPM-2703.

      I have a process definition with two custom nodes, refering to ActivityBehaviour classes Custom1 and Custom2. Class Custom1 sets a process variable named "bean" of class Bean, and Custom2 reads and uses this variable:

      public class Bean implements Serializable {
      	private int value;
      	public int getValue() { return value; }
      	public void setValue(int value) { this.value = value; }
      }
      
      public class Custom1 implements ActivityBehaviour {
      	public void execute(ActivityExecution execution) throws Exception {
      		Bean bean = new Bean();
      		bean.setValue(42);
      		execution.setVariable("bean", bean);
      	}
      }
      
      public class Custom2 implements ActivityBehaviour {
      	public void execute(ActivityExecution execution) throws Exception {
      		Bean bean = (Bean)execution.getVariable("bean");
      		if (bean.getValue() != 42) {
      			throw new Exception("Value must be 42!");
      		}
      	}
      }
      

      All these classes were added to the deployment using addResourcesFromZipInputStream/addResourceFromInputStream. So far this works fine.

      However, when I put a task node between custom1 and custom2 (apparently causing the variable to be serialized?), things go awry:

      java.lang.ClassCastException: [...].Bean cannot be cast to [...].Bean
      	at [...].Custom2.execute(Custom2.java:6)
      	at org.jbpm.pvm.internal.wire.usercode.UserCodeActivityBehaviour.execute(UserCodeActivityBehaviour.java:42)
      	at org.jbpm.pvm.internal.model.op.ExecuteActivity.perform(ExecuteActivity.java:60)
      	at ...etc...
      

      So it seems that there are two Bean-classes, loaded by different classloaders. I've traced this problem to the DeploymentObjectInputStream, which creates a new DeploymentClassLoader each time it enters the catch-clause. Since the second Bean-class is loaded by a different classloader, it is incompatible with the first.

        1. JBPM-2929-fix.patch
          2 kB
          Marcus Klimstra
        2. JBPM-2929-test.patch
          8 kB
          Marcus Klimstra

              rebody HuiSheng Xu (Inactive)
              marcusk_jira Marcus Klimstra (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

                Created:
                Updated:
                Resolved: