Upgrade to CGLIB 3 and inline into spring-core
CGLIB 3 has been released in order to depend on ASM 4, which Spring now depends on internally (see previous commit). This commit eliminates spring-beans' optional dependency on cglib-nodep v2.2 and instead repackages net.sf.cglib => org.springframework.cglib much in the same way we have historically done with ASM. This change is beneficial to users in several ways: - Eliminates the need to manually add CGLIB to the application classpath; especially important for the growing number of @Configuration class users. Java-based configuration functionality, along with proxy-target-class and method injection features now work 'out of the box' in Spring 3.2. - Eliminates the possibility of conflicts with other libraries that may dependend on differing versions of CGLIB, e.g. Hibernate 3.3.1.ga and its dependency on CGLIB 2.1.3 would easily cause a conflict if the application were depending on CGLIB 3 for Spring-related purposes. - Picks up CGLIB 3's changes to support ASM 4, meaning that CGLIB is that much less likely to work well in a Java 7 environment due to ASM 4's support for transforming classes with invokedynamic bytecode instructions. On CGLIB and ASM: CGLIB's own dependency on ASM is also transformed along the way to depend on Spring's repackaged org.springframework.asm, primarily to eliminate unnecessary duplication of ASM classfiles in spring-core and in the process save around 100K in the final spring-core JAR file size. It is coincidental that spring-core and CGLIB currently depend on the exact same version of ASM (4.0), but it is also unlikely to change any time soon. If this change does occur and versions of ASM drift, then the size optimization mentioned above will have to be abandoned. This would have no compatibility impact, however, so this is a reasonable solution now and for the forseeable future. On a mysterious NoClassDefFoundError: During the upgrade to CGLIB 3.0, Spring test cases began failing due to NoClassDefFoundErrors being thrown from CGLIB's DebuggingClassWriter regarding its use of asm-util's TraceClassVisitor type. previous versions of cglib-nodep, particularly 2.2, did not cause this behavior, even though cglib-nodep has never actually repackaged and bundled asm-util classes. The reason for these NoClassDefFoundErrors occurring now is still not fully understood, but appears to be due to subtle JVM bytecode preverification rules. The hypothesis is that due to minor changes in DebuggingClassWriter such as additional casts, access to instance variables declared in the superclass, and indeed a change in the superclass hierarchy, preverification may be kicking in on the toByteArray method body, at which point the reference to the missing TraceClassVisitor type is noticed and the NCDFE is thrown. For this reason, a dummy implementation of TraceClassVisitor has been added to spring-core in the org.springframework.asm.util package. This class simply ensures that Spring's own tests never result in the NCDFE described above, and more importantly that Spring's users never encounter the same. Other changes include: - rename package-private Cglib2AopProxy => CglibAopProxy - eliminate all 'cglibAvailable' checks, warnings and errors - eliminate all 'CGLIB2' language in favor of 'CGLIB' - eliminate all mention in reference and java docs of needing to add cglib(-nodep) to one's application classpath Issue: SPR-9669
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2007 the original author or authors.
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -486,7 +486,7 @@ public abstract class AbstractAopProxyTests {
|
||||
/**
|
||||
* An interceptor throws a checked exception not on the method signature.
|
||||
* For efficiency, we don't bother unifying java.lang.reflect and
|
||||
* net.sf.cglib UndeclaredThrowableException
|
||||
* org.springframework.cglib UndeclaredThrowableException
|
||||
*/
|
||||
@Test
|
||||
public void testUndeclaredCheckedException() throws Throwable {
|
||||
@@ -514,9 +514,6 @@ public abstract class AbstractAopProxyTests {
|
||||
catch (UndeclaredThrowableException thrown) {
|
||||
assertEquals("exception matches", unexpectedException, thrown.getUndeclaredThrowable());
|
||||
}
|
||||
//catch (net.sf.cglib.proxy.UndeclaredThrowableException thrown) {
|
||||
// assertEquals("exception matches", unexpectedException, thrown.getUndeclaredThrowable());
|
||||
//}
|
||||
catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
fail("Didn't expect exception: " + ex);
|
||||
@@ -549,9 +546,6 @@ public abstract class AbstractAopProxyTests {
|
||||
catch (RuntimeException thrown) {
|
||||
assertEquals("exception matches", unexpectedException, thrown);
|
||||
}
|
||||
//catch (net.sf.cglib.proxy.UndeclaredThrowableException thrown) {
|
||||
// assertEquals("exception matches", unexpectedException, thrown.getUndeclaredThrowable());
|
||||
//}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2007 the original author or authors.
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -21,11 +21,13 @@ import static org.junit.Assert.*;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
import net.sf.cglib.core.CodeGenerationException;
|
||||
import org.aopalliance.intercept.MethodInterceptor;
|
||||
import org.aopalliance.intercept.MethodInvocation;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.cglib.core.CodeGenerationException;
|
||||
|
||||
import org.springframework.aop.ClassFilter;
|
||||
import org.springframework.aop.MethodMatcher;
|
||||
import org.springframework.aop.Pointcut;
|
||||
@@ -65,7 +67,7 @@ public final class CglibProxyTests extends AbstractAopProxyTests implements Seri
|
||||
|
||||
protected AopProxy createAopProxy(AdvisedSupport as) {
|
||||
as.setProxyTargetClass(true);
|
||||
return new Cglib2AopProxy(as);
|
||||
return new CglibAopProxy(as);
|
||||
}
|
||||
|
||||
protected boolean requiresTarget() {
|
||||
@@ -75,7 +77,7 @@ public final class CglibProxyTests extends AbstractAopProxyTests implements Seri
|
||||
@Test
|
||||
public void testNullConfig() {
|
||||
try {
|
||||
new Cglib2AopProxy(null);
|
||||
new CglibAopProxy(null);
|
||||
fail("Shouldn't allow null interceptors");
|
||||
}
|
||||
catch (IllegalArgumentException ex) {
|
||||
@@ -105,7 +107,7 @@ public final class CglibProxyTests extends AbstractAopProxyTests implements Seri
|
||||
AdvisedSupport as = new AdvisedSupport(new Class[]{});
|
||||
as.setTargetSource(mockTargetSource);
|
||||
as.addAdvice(new NopInterceptor());
|
||||
AopProxy aop = new Cglib2AopProxy(as);
|
||||
AopProxy aop = new CglibAopProxy(as);
|
||||
|
||||
Object proxy = aop.getProxy();
|
||||
assertTrue(AopUtils.isCglibProxy(proxy));
|
||||
@@ -118,7 +120,7 @@ public final class CglibProxyTests extends AbstractAopProxyTests implements Seri
|
||||
mockTargetSource.setTarget(raw);
|
||||
AdvisedSupport pc = new AdvisedSupport();
|
||||
pc.setTargetSource(mockTargetSource);
|
||||
AopProxy aop = new Cglib2AopProxy(pc);
|
||||
AopProxy aop = new CglibAopProxy(pc);
|
||||
|
||||
Object proxy = aop.getProxy();
|
||||
assertTrue(AopUtils.isCglibProxy(proxy));
|
||||
@@ -159,7 +161,7 @@ public final class CglibProxyTests extends AbstractAopProxyTests implements Seri
|
||||
AdvisedSupport as = new AdvisedSupport(new Class[]{});
|
||||
as.setTarget(bean);
|
||||
as.addAdvice(new NopInterceptor());
|
||||
AopProxy aop = new Cglib2AopProxy(as);
|
||||
AopProxy aop = new CglibAopProxy(as);
|
||||
|
||||
CglibTestBean proxy = (CglibTestBean) aop.getProxy();
|
||||
|
||||
@@ -176,7 +178,7 @@ public final class CglibProxyTests extends AbstractAopProxyTests implements Seri
|
||||
pc.setFrozen(true);
|
||||
pc.setTarget(target);
|
||||
|
||||
Cglib2AopProxy aop = new Cglib2AopProxy(pc);
|
||||
CglibAopProxy aop = new CglibAopProxy(pc);
|
||||
|
||||
CglibTestBean proxy = (CglibTestBean) aop.getProxy();
|
||||
|
||||
@@ -258,7 +260,7 @@ public final class CglibProxyTests extends AbstractAopProxyTests implements Seri
|
||||
mockTargetSource.setTarget(target);
|
||||
AdvisedSupport pc = new AdvisedSupport(new Class[]{});
|
||||
pc.setTargetSource(mockTargetSource);
|
||||
Cglib2AopProxy aop = new Cglib2AopProxy(pc);
|
||||
CglibAopProxy aop = new CglibAopProxy(pc);
|
||||
aop.setConstructorArguments(new Object[] {"Rob Harrop", new Integer(22)},
|
||||
new Class[] {String.class, int.class});
|
||||
|
||||
@@ -276,7 +278,7 @@ public final class CglibProxyTests extends AbstractAopProxyTests implements Seri
|
||||
AdvisedSupport as = new AdvisedSupport(new Class[]{});
|
||||
as.setTargetSource(mockTargetSource);
|
||||
as.addAdvice(new NopInterceptor());
|
||||
Cglib2AopProxy cglib = new Cglib2AopProxy(as);
|
||||
CglibAopProxy cglib = new CglibAopProxy(as);
|
||||
|
||||
ITestBean proxy1 = (ITestBean) cglib.getProxy();
|
||||
|
||||
@@ -284,7 +286,7 @@ public final class CglibProxyTests extends AbstractAopProxyTests implements Seri
|
||||
as = new AdvisedSupport(new Class[]{});
|
||||
as.setTargetSource(mockTargetSource);
|
||||
as.addAdvice(new NopInterceptor());
|
||||
cglib = new Cglib2AopProxy(as);
|
||||
cglib = new CglibAopProxy(as);
|
||||
|
||||
assertThat(cglib.getProxy(), instanceOf(ITestBean.class));
|
||||
}
|
||||
@@ -298,7 +300,7 @@ public final class CglibProxyTests extends AbstractAopProxyTests implements Seri
|
||||
as.setTargetSource(mockTargetSource);
|
||||
as.addAdvice(new NopInterceptor());
|
||||
as.addInterface(Serializable.class);
|
||||
Cglib2AopProxy cglib = new Cglib2AopProxy(as);
|
||||
CglibAopProxy cglib = new CglibAopProxy(as);
|
||||
|
||||
ITestBean proxy1 = (ITestBean) cglib.getProxy();
|
||||
|
||||
@@ -306,7 +308,7 @@ public final class CglibProxyTests extends AbstractAopProxyTests implements Seri
|
||||
as = new AdvisedSupport(new Class[]{});
|
||||
as.setTargetSource(mockTargetSource);
|
||||
as.addAdvice(new NopInterceptor());
|
||||
cglib = new Cglib2AopProxy(as);
|
||||
cglib = new CglibAopProxy(as);
|
||||
|
||||
ITestBean proxy2 = (ITestBean) cglib.getProxy();
|
||||
assertTrue(proxy2 instanceof Serializable);
|
||||
@@ -320,7 +322,7 @@ public final class CglibProxyTests extends AbstractAopProxyTests implements Seri
|
||||
AdvisedSupport as = new AdvisedSupport(new Class[]{});
|
||||
as.setTargetSource(mockTargetSource);
|
||||
as.addAdvice(new NopInterceptor());
|
||||
AopProxy aop = new Cglib2AopProxy(as);
|
||||
AopProxy aop = new CglibAopProxy(as);
|
||||
|
||||
ExceptionThrower proxy = (ExceptionThrower) aop.getProxy();
|
||||
|
||||
@@ -494,4 +496,4 @@ class UnsupportedInterceptor implements MethodInterceptor {
|
||||
throw new UnsupportedOperationException(mi.getMethod().getName());
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user