cancel
Showing results for 
Search instead for 
Did you mean: 

Error running 5.12 unit tests with Java 7

brianshowers
Champ in-the-making
Champ in-the-making
Due to the issue with saving TaskEntry objects (originally mentioned here), we are currently using a forked and patched version of Activiti v5.11.  I wanted to upgrade to v5.12, so I was going to reapply my patch on top of the 5.12 tag and rebuild.  However, I've started getting an error running the Activiti unit tests in 5.12 under a Java 7 JVM.

Specifically, what I see is org.activiti.examples.bpmn.scripttask.ScriptTaskTest::testAutoStoreVariables() fails with the following exception:

Environment: Windows 7, Java 1.7.0_17

——————————————————————————-
Test set: org.activiti.examples.bpmn.scripttask.ScriptTaskTest
——————————————————————————-
Tests run: 4, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 0.193 sec <<< FAILURE!
testAutoStoreVariables(org.activiti.examples.bpmn.scripttask.ScriptTaskTest)  Time elapsed: 0.075 sec  <<< ERROR!
org.activiti.engine.ActivitiException: couldn't find a variable type that is able to serialize sun.org.mozilla.javascript.internal.Undefined@30baae4a
   at org.activiti.engine.impl.variable.DefaultVariableTypes.findVariableType(DefaultVariableTypes.java:62)
   at org.activiti.engine.impl.persistence.entity.VariableScopeImpl.createVariableInstance(VariableScopeImpl.java:359)
   at org.activiti.engine.impl.persistence.entity.VariableScopeImpl.createVariableLocal(VariableScopeImpl.java:292)
   at org.activiti.engine.impl.persistence.entity.VariableScopeImpl.createVariableLocal(VariableScopeImpl.java:279)

   at org.activiti.engine.impl.TaskServiceImpl.complete(TaskServiceImpl.java:161)
   at org.activiti.examples.bpmn.scripttask.ScriptTaskTest.testAutoStoreVariables(ScriptTaskTest.java:76)
   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
   at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
   at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
   at java.lang.reflect.Method.invoke(Method.java:601)
   at junit.framework.TestCase.runTest(TestCase.java:176)
   at org.activiti.engine.impl.test.PvmTestCase.runTest(PvmTestCase.java:65)
   at junit.framework.TestCase.runBare(TestCase.java:141)
   at org.activiti.engine.impl.test.AbstractActivitiTestCase.runBare(AbstractActivitiTestCase.java:86)
   at junit.framework.TestResult$1.protect(TestResult.java:122)
   at junit.framework.TestResult.runProtected(TestResult.java:142)
   at junit.framework.TestResult.run(TestResult.java:125)
   at junit.framework.TestCase.run(TestCase.java:129)
   at junit.framework.TestSuite.runTest(TestSuite.java:255)
   at junit.framework.TestSuite.run(TestSuite.java:250)
   at org.junit.internal.runners.JUnit38ClassRunner.run(JUnit38ClassRunner.java:84)
   at org.apache.maven.surefire.junit4.JUnit4TestSet.execute(JUnit4TestSet.java:35)
   at org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:146)
   at org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:97)
   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
   at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
   at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
   at java.lang.reflect.Method.invoke(Method.java:601)
   at org.apache.maven.surefire.booter.ProviderFactory$ClassLoaderProxy.invoke(ProviderFactory.java:103)
   at com.sun.proxy.$Proxy0.invoke(Unknown Source)
   at org.apache.maven.surefire.booter.SurefireStarter.invokeProvider(SurefireStarter.java:145)
   at org.apache.maven.surefire.booter.SurefireStarter.runSuitesInProcess(SurefireStarter.java:87)
   at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:69)

However, if I run the same test using a Java 1.6.0_25 JVM, it passes!

I spent some time stepping through the test in the debugger, and it seems to come down to a change in the sun.org.mozilla.javascript.internal.Undefined implementation.  In the Java 6 implemenation, that class implements Serializable.  So, org.activiti.engine.impl.variable.DefaultVariableTypes::findVariableType() is able to map Undefined to Serializable.

However, in Java 1.7, it appears that sun.org.mozilla.javascript.internal.Undefined does not implement Serializeable.  So, no valid type can be found and an exception is thrown.

I haven't been able to track down any source code for the Undefined class, so it's a bit hard for me to tell for certain, but this test fails for me in Java 7 and passes in Java 6:


  public void testUndefinedType() {
      boolean serializable = (Undefined.instance instanceof Serializable);
      assertTrue(serializable);
  }

While it's not that big of deal if I can't run the Activiti tests in the Java 1.7 VM, I think the issue might be bigger than that.  I think that Activiti won't be able to save script variables of an undefined type in a Java 7 JVM.
16 REPLIES 16

jbarrez
Star Contributor
Star Contributor
All of our QA runs on JDK 7, and we have only one JDK 6 build to verify: http://jenkins.alfresco.com:8080/jenkins/

Also, when I run it locally with JDK 7 all tests are passing (obviously, or we wouldnt have released) … are you using sun jdk? What platform?

brianshowers
Champ in-the-making
Champ in-the-making
Based on other posts that I had read, that's what I had thought about your test environment.  Part of what makes this so confusing.

That said, it certainly appears that in at least some of the 1.7 implementations, Undefined doesn't implement Serializable.

I'm not using anything unusual for the JDK, just Oracle 1.7.0_17 JDK for x64 Windows.  I'm running on Windows 7.

brianshowers
Champ in-the-making
Champ in-the-making
Here's another interesting finding.  When I execute the test using the 1.7.0_17 i586 (32-bit) JDK, the test passes.  So, it appears to me that the Activity build isn't compatible with the 64-bit Java 7 JDK (at least for Windows, I'm not sure about other OS builds).

That said, I have no idea why the implementation of the Undefined class would be different across JDK builds.

jbarrez
Star Contributor
Star Contributor
Wow, that's a pretty bizar find. I believe our QA is running Red Hat 64 bit. And our systems (OS X) are definitely 64 bit.

I've got no clue why the windows one would be different … let's hope it is a bug and it is fixed in a next release?

That said, I have no idea why the implementation of the Undefined class would be different across JDK builds.

Indeed … that makes no sense….

Altough they are working on getting the new JS engine (Nashorn) into the JDK …

brianshowers
Champ in-the-making
Champ in-the-making
What build number are you using?  I just tried with Oracle 1.7.0_17 (64-bit) build for OS X and I ran into the same issue.  Undefined doesn't implement Serializable, so the same test fails.  There is no 32-bit build for OS X, so I couldn't repeat that part of the scenario.

udoderk
Champ in-the-making
Champ in-the-making
What build number are you using?  I just tried with Oracle 1.7.0_17 (64-bit) build for OS X and I ran into the same issue.  Undefined doesn't implement Serializable, so the same test fails.  There is no 32-bit build for OS X, so I couldn't repeat that part of the scenario.
Hi brianshowers,

Why ever appears sun.org.mozilla.javascript.internal.Undefined ??

P. S Just my two cents: the described problem is not an activiti-problem but Oracle Bug Smiley Wink

brianshowers
Champ in-the-making
Champ in-the-making
Hi udoderk,

Thanks for the note!  The reason I bring this up here is because it comes into play if you use script blocks in your BPMN diagram such as:


<scriptTask id="script2" scriptFormat="JavaScript" activiti:autoStoreVariables="true">
  <script><![CDATA[
       
    var sum = a + b;          
           
    ]]></script>
</scriptTask>

If you use that functionality, Activiti tries to save the variable "sum" which is of type sun.org.mozilla.javascript.internal.Undefined.  The Activiti implementation counts on that class implementing Serializable.  If it does not, Activiti cannot save the variable and will throw a runtime exception.

This could very well be a bug in the JDK, but since getting Oracle to fix a bug is not a trivial (or quick) matter, I suspect that the Activiti implementation may need to be changed to work around that bug.  On the other hand, it's also possible that in the latest build of the JDK, the Serializable interface was removed on purpose, and it might never come back.  Either way, if Activiti is not compatible with particular builds of the JDK, that's something everyone should be aware of.

jbarrez
Star Contributor
Star Contributor
@Brian:  I completely agree with you. I've written down a blog post so people are aware: http://www.jorambarrez.be/blog/2013/03/25/bug-on-jdk-1-7-0_17-when-using-scripttask-in-activiti/

I'll try to find out how to post a JDK bug. However, removing the 'implements Serializable' is something that I can't think that can be done by mistake.

udoderk
Champ in-the-making
Champ in-the-making
Hi,

thank you for this example!

But i assume, that this problem will be occured with last version of JDK6 for 32bit and 64bit machine jdk-6u43
I have downloaded this jdk, then installed it, and then look at jt.jar, located under  <jdk1.6.0_43 path>\jre\lib.
This version has no serialization too!
package sun.org.mozilla.javascript.internal;

public class Undefined
{
  public static final Object instance = new Undefined();

  public Object readResolve()
  {
    return instance;
  }
}
i have used jd-gui-0.3.3.windows to display this jar file.
The jdk1.6.0_37 (32bit) has the Serializable Version of Undefined