MethodHandles.Lookup.defineClass for CGLIB class definition purposes
Spring's CGLIB fork is patched with local copies of affected files here, introducing the notion of a "contextClass" (e.g. the proxy superclass) which gets passed through to ReflectUtils.defineClass for delegating to MethodHandles.Lookup.defineClass eventually, against a privateLookupIn(contextClass) lookup context on JDK 9/10/11. Issue: SPR-15859
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2016 the original author or authors.
|
||||
* Copyright 2002-2018 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.
|
||||
@@ -212,7 +212,7 @@ public abstract class AbstractAopProxyTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSerializationSerializableTargetAndAdvice() throws Throwable {
|
||||
public void testSerializableTargetAndAdvice() throws Throwable {
|
||||
SerializablePerson personTarget = new SerializablePerson();
|
||||
personTarget.setName("jim");
|
||||
personTarget.setAge(26);
|
||||
@@ -435,7 +435,7 @@ public abstract class AbstractAopProxyTests {
|
||||
TestBean raw = new OwnSpouse();
|
||||
|
||||
ProxyCreatorSupport pc = new ProxyCreatorSupport();
|
||||
pc.setInterfaces(new Class<?>[] {ITestBean.class});
|
||||
pc.setInterfaces(ITestBean.class);
|
||||
pc.setTarget(raw);
|
||||
|
||||
ITestBean tb = (ITestBean) createProxy(pc);
|
||||
@@ -457,7 +457,7 @@ public abstract class AbstractAopProxyTests {
|
||||
pc.addAdvice(mi);
|
||||
|
||||
// We don't care about the object
|
||||
mockTargetSource.setTarget(new Object());
|
||||
mockTargetSource.setTarget(new TestBean());
|
||||
pc.setTargetSource(mockTargetSource);
|
||||
AopProxy aop = createAopProxy(pc);
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
* Copyright 2002-2018 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.
|
||||
@@ -122,27 +122,7 @@ public class CglibProxyTests extends AbstractAopProxyTests implements Serializab
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPackageMethodInvocationWithDifferentClassLoader() {
|
||||
ClassLoader child = new ClassLoader(getClass().getClassLoader()) {
|
||||
};
|
||||
|
||||
PackageMethodTestBean bean = new PackageMethodTestBean();
|
||||
bean.value = "foo";
|
||||
mockTargetSource.setTarget(bean);
|
||||
|
||||
AdvisedSupport as = new AdvisedSupport();
|
||||
as.setTargetSource(mockTargetSource);
|
||||
as.addAdvice(new NopInterceptor());
|
||||
AopProxy aop = new CglibAopProxy(as);
|
||||
|
||||
PackageMethodTestBean proxy = (PackageMethodTestBean) aop.getProxy(child);
|
||||
assertTrue(AopUtils.isCglibProxy(proxy));
|
||||
assertNotEquals(proxy.getClass().getClassLoader(), bean.getClass().getClassLoader());
|
||||
assertNull(proxy.getString()); // we're stuck in the proxy instance
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testProxyCanBeClassNotInterface() throws Exception {
|
||||
public void testProxyCanBeClassNotInterface() {
|
||||
TestBean raw = new TestBean();
|
||||
raw.setAge(32);
|
||||
mockTargetSource.setTarget(raw);
|
||||
@@ -174,7 +154,7 @@ public class CglibProxyTests extends AbstractAopProxyTests implements Serializab
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUnadvisedProxyCreationWithCallDuringConstructor() throws Exception {
|
||||
public void testUnadvisedProxyCreationWithCallDuringConstructor() {
|
||||
CglibTestBean target = new CglibTestBean();
|
||||
target.setName("Rob Harrop");
|
||||
|
||||
@@ -370,7 +350,7 @@ public class CglibProxyTests extends AbstractAopProxyTests implements Serializab
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testProxyProtectedMethod() throws Exception {
|
||||
public void testProxyProtectedMethod() {
|
||||
CountingBeforeAdvice advice = new CountingBeforeAdvice();
|
||||
ProxyFactory proxyFactory = new ProxyFactory(new MyBean());
|
||||
proxyFactory.addAdvice(advice);
|
||||
@@ -382,14 +362,14 @@ public class CglibProxyTests extends AbstractAopProxyTests implements Serializab
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testProxyTargetClassInCaseOfNoInterfaces() throws Exception {
|
||||
public void testProxyTargetClassInCaseOfNoInterfaces() {
|
||||
ProxyFactory proxyFactory = new ProxyFactory(new MyBean());
|
||||
MyBean proxy = (MyBean) proxyFactory.getProxy();
|
||||
assertEquals(4, proxy.add(1, 3));
|
||||
}
|
||||
|
||||
@Test // SPR-13328
|
||||
public void testVarargsWithEnumArray() throws Exception {
|
||||
public void testVarargsWithEnumArray() {
|
||||
ProxyFactory proxyFactory = new ProxyFactory(new MyBean());
|
||||
MyBean proxy = (MyBean) proxyFactory.getProxy();
|
||||
assertTrue(proxy.doWithVarargs(MyEnum.A, MyOtherEnum.C));
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2013 the original author or authors.
|
||||
* Copyright 2002-2018 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.
|
||||
@@ -35,13 +35,13 @@ import static org.junit.Assert.*;
|
||||
public class BeanNameAutoProxyCreatorInitTests {
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void testIgnoreAdvisorThatIsCurrentlyCreation() {
|
||||
public void testIgnoreAdvisorThatIsCurrentlyInCreation() {
|
||||
ClassPathXmlApplicationContext ctx =
|
||||
new ClassPathXmlApplicationContext(getClass().getSimpleName() + "-context.xml", getClass());
|
||||
new ClassPathXmlApplicationContext(getClass().getSimpleName() + "-context.xml", getClass());
|
||||
TestBean bean = (TestBean) ctx.getBean("bean");
|
||||
bean.setName("foo");
|
||||
assertEquals("foo", bean.getName());
|
||||
bean.setName(null); // should throw
|
||||
bean.setName(null); // should throw
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user