We have an issue here:
When we run our tests locally on a linux machine we get the following error ( not on windows or a remote linux server) see log below.
I checked the failing class and one of our team members described the problem like this:
"org.powermock.core.classloader.MockClassLoader.loadUnmockedClass(MockClassLoader.java:192) is incorrectly throwing a
javassist.NotFoundException that is wrapped in a RuntimeException instead of throwing the correct
java.lang.ClassNotFoundException."
public CtClass get(String classname) throws NotFoundException {
CtClass clazz;
if (classname == null)
clazz = null;
else
clazz = get0(classname, true);
if (clazz == null)
throw new NotFoundException(classname);
else {
clazz.incGetCounter();
return clazz;
}
}
So to me it seems that get is throwing the wrong exception it throws a javassist.NotFoundException when it should have thrown java.lang.ClassNotFoundException.
We could solve it by adding the following in the below method:
} catch (Exception e) {
if(e instanceof javassist.NotFoundException){
throw new ClassNotFoundException();
}else{
throw new RuntimeException(e);
}
Not even sure you need the last else.
What is you opinion?
Br,
//mikael
private Class<?> loadUnmockedClass(String name) throws ClassFormatError, ClassNotFoundException {
byte bytes[] = null;
try {
/*
* TODO This if-statement is a VERY ugly hack to avoid the
* java.lang.ExceptionInInitializerError caused by
* "javassist.NotFoundException:
* net.sf.cglib.proxy.Enhancer$EnhancerKey$$KeyFactoryByCGLIB$$7fb24d72
* ". This happens after the
*
* se.jayway.examples.tests.privatefield.
* SimplePrivateFieldServiceClassTest#testUseService(..) tests has
* been run and all other tests will fail if this class is tried to
* be loaded. Atm I have found no solution other than this ugly hack
* to make it work. We really need to investigate the real cause of
* this behavior.
*/
if (!name.startsWith(CGLIB_ENHANCER) && !name.startsWith(CGLIB_METHOD_WRAPPER)) {
final CtClass ctClass = classPool.get(name);
if (ctClass.isFrozen()) {
ctClass.defrost();
}
bytes = ctClass.toBytecode();
}
} catch (Exception e) {
throw new RuntimeException(e);
}
return bytes == null ? null : defineClass(name, bytes, 0, bytes.length);
}
java.lang.RuntimeException: javassist.NotFoundException: company.helpers.alarm.AlarmConfigurationDataExtendedByProxy
at org.powermock.core.classloader.MockClassLoader.loadUnmockedClass(MockClassLoader.java:192)
at org.powermock.core.classloader.MockClassLoader.loadModifiedClass(MockClassLoader.java:144)
at org.powermock.core.classloader.DeferSupportingClassLoader.loadClass(DeferSupportingClassLoader.java:67)
at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:190)
at com.company.proxy.InterceptableProxyFactory.addAdditionalSetMethodsToClass(InterceptableProxyFactory.java:76)
at com.company.proxy.InterceptableProxyFactory.createANewInterfaceJavaBeanProxy(InterceptableProxyFactory.java:197)
at com.company.proxy.Proxy.javaBean(Proxy.java:114)
at com.company.beanadapter.CustomDefaultListableBeanFactory.createBean(CustomDefaultListableBeanFactory.java:83)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:294)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:225)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:291)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:585)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:913)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:464)
at com.company.beanadapter.CustomFileSystemXmlApplicationContext.<init>(CustomFileSystemXmlApplicationContext.java:29)
at com.company.beanadapter.BeanAdapter.<init>(BeanAdapter.java:52)
at com.company.beanadapter.BeanAdapterProvider.initializeAndGetAdapter(BeanAdapterProvider.java:84)
at com.company.cf.AggregationAdapter$1.call(AggregationAdapter.java:97)
at com.company.cf.AggregationAdapter$1.call(AggregationAdapter.java:93)
at java.util.concurrent.FutureTask.run(FutureTask.java:262)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:744)
Caused by: javassist.NotFoundException: company.helpers.alarm.AlarmConfigurationDataExtendedByProxy
at javassist.ClassPool.get(ClassPool.java:450)
at org.powermock.core.classloader.MockClassLoader.loadUnmockedClass(MockClassLoader.java:185)
... 25 more
java.lang.RuntimeException: javassist.NotFoundException: company.helpers.alarm.AlarmConfigurationDataExtendedByProxy
at org.powermock.core.classloader.MockClassLoader.loadUnmockedClass(MockClassLoader.java:192)
at org.powermock.core.classloader.MockClassLoader.loadModifiedClass(MockClassLoader.java:144)
at org.powermock.core.classloader.DeferSupportingClassLoader.loadClass(DeferSupportingClassLoader.java:67)
at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:190)
at com.company.proxy.InterceptableProxyFactory.addAdditionalSetMethodsToClass(InterceptableProxyFactory.java:76)
at com.company.proxy.InterceptableProxyFactory.createANewInterfaceJavaBeanProxy(InterceptableProxyFactory.java:197)
at com.company.proxy.Proxy.javaBean(Proxy.java:114)
at com.company.beanadapter.CustomDefaultListableBeanFactory.createBean(CustomDefaultListableBeanFactory.java:83)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:294)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:225)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:291)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:585)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:913)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:464)
at com.company.beanadapter.CustomFileSystemXmlApplicationContext.<init>(CustomFileSystemXmlApplicationContext.java:29)
at com.company.beanadapter.BeanAdapter.<init>(BeanAdapter.java:52)
at com.company.beanadapter.BeanAdapterProvider.initializeAndGetAdapter(BeanAdapterProvider.java:84)
at com.company.cf.AggregationAdapter$1.call(AggregationAdapter.java:97)
at com.company.cf.AggregationAdapter$1.call(AggregationAdapter.java:93)
at java.util.concurrent.FutureTask.run(FutureTask.java:262)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:744)
Caused by: javassist.NotFoundException: company.helpers.alarm.AlarmConfigurationDataExtendedByProxy
at javassist.ClassPool.get(ClassPool.java:450)
at org.powermock.core.classloader.MockClassLoader.loadUnmockedClass(MockClassLoader.java:185)
... 25 more
--
You received this message because you are subscribed to the Google Groups "PowerMock" group.
To unsubscribe from this group and stop receiving emails from it, send an email to powermock+...@googlegroups.com.
To post to this group, send email to powe...@googlegroups.com.
Visit this group at http://groups.google.com/group/powermock.
For more options, visit https://groups.google.com/d/optout.