1 Reply Latest reply on Oct 16, 2017 6:19 AM by vkp_123

    java.lang.IllegalStateException and javassist.CannotCompileException during application deployment

    vkp_123

      I am getting the javassist  exception while deployment the .EAR file . I am using Java 1.8 SDK  , IBM JDK 1.8 . In my pom.xml file , i am using 3.19.0-GA javassit dependency and spring version 4.2.5.RELEASE . The error is getting

       

      error

       

      Caused by: java.lang.IllegalStateException: javassist.CannotCompileException: by java.lang.LinkageError: org.springframework.aop.framework.ProxyCreatorSupport

              at org.springframework.aop.framework.JavassistApplicationContext.<clinit>(JavassistApplicationContext.java:36)

              ... 112 more

      Caused by: javassist.CannotCompileException: by java.lang.LinkageError: org.springframework.aop.framework.ProxyCreatorSupport

              at javassist.ClassPool.toClass(ClassPool.java:1085)

              at javassist.ClassPool.toClass(ClassPool.java:1028)

              at javassist.ClassPool.toClass(ClassPool.java:986)

              at javassist.CtClass.toClass(CtClass.java:1079)

              at org.springframework.aop.framework.JavassistApplicationContext.<clinit>(JavassistApplicationContext.java:34)

              ... 112 more

      Caused by: java.lang.LinkageError: org.springframework.aop.framework.ProxyCreatorSupport

              at java.lang.ClassLoader.defineClassImpl(Native Method)

              at java.lang.ClassLoader.defineClass(ClassLoader.java:346)

              at java.lang.ClassLoader.defineClass(ClassLoader.java:283)

              at sun.reflect.GeneratedMethodAccessor17.invoke(Unknown Source)

              at

       

      After analyzing the class file of javassit , i can see InvocationTargetException  causing error

       

      javassit jar file class code :

       

      public Class toClass(CtClass ct, ClassLoader loader, ProtectionDomain domain)

      /*      */     throws CannotCompileException

      /*      */   {

      /*      */     try

      /*      */     {

      /* 1065 */       byte[] b = ct.toBytecode();

      /*      */       Object[] args;

      /*      */       Method method;

      /* 1068 */       Object[] args; if (domain == null) {

      /* 1069 */         Method method = defineClass1;

      /* 1070 */         args = new Object[] { ct.getName(), b, new Integer(0), new Integer(b.length) };

      /*      */       }

      /*      */       else

      /*      */       {

      /* 1074 */         method = defineClass2;

      /* 1075 */         args = new Object[] { ct.getName(), b, new Integer(0), new Integer(b.length), domain };

      /*      */       }

      /*      */      

      /*      */

      /* 1079 */       return toClass2(method, loader, args);

      /*      */     }

      /*      */     catch (RuntimeException e) {

      /* 1082 */       throw e;

      /*      */     }

      /*      */     catch (InvocationTargetException e) {

      /* 1085 */       throw new CannotCompileException(e.getTargetException());

      /*      */     }

      /*      */     catch (Exception e) {

      /* 1088 */       throw new CannotCompileException(e);

      /*      */     }

      /*      */   }

       

      code :

      public class JavassistApplicationContext extends XmlWebApplicationContext {

          static {

              ClassPool classPool = ClassPool.getDefault();

              try {

                  ClassLoader classLoader = Thread.currentThread().getContextClassLoader();

                  classPool.appendClassPath(new LoaderClassPath(classLoader));

                  CtClass cc = classPool.get("org.springframework.aop.framework.ProxyCreatorSupport");

                  CtConstructor c = cc.getConstructors()[0];

                  c.insertAfter("$0.aopProxyFactory = new org.springframework.aop.framework.JavassistAopProxyFactory();");

                  cc.toClass();

              } catch (Exception e) {

                  throw new IllegalStateException(e);

              }

          }

      }

       

      This code was working fine with JDK 1.6 and javassit 3.12 . Any suggestion ?