Activiti: ReflectUtil.loadClass(String) throws `java.lang.ClassNotFoundException: int` on primitive types

We are using activiti version 5.18.0 and it was working fine as a spring mvc application. But since the application is converted to Spring boot 2, the executions fails with a weird ClassNotFoundException for primitive types.

Here is a sample exception.

Caused by: org.activiti.engine.ActivitiException: Couldn’t deserialize object in variable ‘executionObject’ at org.activiti.engine.impl.variable.SerializableType.deserialize(SerializableType.java:112) at org.activiti.engine.impl.variable.DeserializedObject.flush(DeserializedObject.java:43) at org.activiti.engine.impl.db.DbSqlSession.flushDeserializedObjects(DbSqlSession.java:700) at org.activiti.engine.impl.db.DbSqlSession.flush(DbSqlSession.java:576) at org.activiti.engine.impl.interceptor.CommandContext.flushSessions(CommandContext.java:211) at org.activiti.engine.impl.interceptor.CommandContext.close(CommandContext.java:137) at org.activiti.engine.impl.interceptor.CommandContextInterceptor.execute(CommandContextInterceptor.java:66) at org.activiti.spring.SpringTransactionInterceptor$1.doInTransaction(SpringTransactionInterceptor.java:47) at org.springframework.transaction.support.TransactionTemplate.execute(TransactionTemplate.java:140) at org.activiti.spring.SpringTransactionInterceptor.execute(SpringTransactionInterceptor.java:45) at org.activiti.engine.impl.interceptor.LogInterceptor.execute(LogInterceptor.java:37) at org.activiti.engine.impl.cfg.CommandExecutorImpl.execute(CommandExecutorImpl.java:40) at org.activiti.engine.impl.cfg.CommandExecutorImpl.execute(CommandExecutorImpl.java:35) at org.activiti.engine.impl.RuntimeServiceImpl.startProcessInstanceByKey(RuntimeServiceImpl.java:77) at com.tcl.gvg.itsm.activiti.ActivitiServiceImpl.executeActivity(ActivitiServiceImpl.java:518) … 199 more Caused by: org.activiti.engine.ActivitiClassLoadingException: Class not found: int at org.activiti.engine.impl.util.ReflectUtil.loadClass(ReflectUtil.java:87) at org.activiti.engine.impl.variable.SerializableType$1.resolveClass(SerializableType.java:126) at java.io.ObjectInputStream.readNonProxyDesc(ObjectInputStream.java:1859) at java.io.ObjectInputStream.readClassDesc(ObjectInputStream.java:1745) at java.io.ObjectInputStream.readClass(ObjectInputStream.java:1710) at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1550) at java.io.ObjectInputStream.readArray(ObjectInputStream.java:1966) at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1561) at java.io.ObjectInputStream.defaultReadFields(ObjectInputStream.java:2278) at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:2202) at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:2060) at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1567) at java.io.ObjectInputStream.defaultReadFields(ObjectInputStream.java:2278) at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:2202) at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:2060) at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1567) at java.io.ObjectInputStream.defaultReadFields(ObjectInputStream.java:2278) at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:2202) at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:2060) at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1567) at java.io.ObjectInputStream.defaultReadFields(ObjectInputStream.java:2278) at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:2202) at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:2060) at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1567) at java.io.ObjectInputStream.defaultReadFields(ObjectInputStream.java:2278) at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:2202) at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:2060) at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1567) at java.io.ObjectInputStream.readObject(ObjectInputStream.java:427) at org.activiti.engine.impl.variable.SerializableType.deserialize(SerializableType.java:108) … 213 more Caused by: java.lang.ClassNotFoundException: int at org.springframework.boot.web.embedded.tomcat.TomcatEmbeddedWebappClassLoader.loadClass(TomcatEmbeddedWebappClassLoader.java:70) at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1136) at org.activiti.engine.impl.util.ReflectUtil.loadClass(ReflectUtil.java:291) at org.activiti.engine.impl.util.ReflectUtil.loadClass(ReflectUtil.java:68) … 242 more

Here is a possible workaround.

    protected static final String[] PRIMITIVE_NAMES = new String[] { "boolean",
            "byte", "char", "double", "float", "int", "long", "short", "void" };

    protected static final Class<?>[] PRIMITIVES = new Class[] { boolean.class,
            byte.class, char.class, double.class, float.class, int.class,
            long.class, short.class, Void.TYPE };

    protected static Class<?> forNamePrimitive(String name) {
        if (name.length() <= 8) {
            int p = Arrays.binarySearch(PRIMITIVE_NAMES, name);
            if (p >= 0) {
                return PRIMITIVES[p];
            }
        }
        return null;
    }

and then the loadClass can have a check if the class name is falling under primitive type to resolve a class or else follow the existing implementation.

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Comments: 15 (6 by maintainers)

Most upvoted comments

@raja-anbazhagan no problem, these things happens all the time, and that’s the main reason why we cannot apply a random patch without making sure that we can reproduce the issue in a consistent way first. Thanks a lot for closing the issue 😃