exclude non-public interfaces when autodetecting proxy interfaces

git-svn-id: https://src.springframework.org/svn/spring-framework/trunk@1097 50f2f4bb-b051-0410-bef5-90022cba6387
This commit is contained in:
Juergen Hoeller 2009-05-05 12:37:18 +00:00
parent a5eb3d592d
commit cdcacec6a0
2 changed files with 42 additions and 37 deletions

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2008 the original author or authors. * Copyright 2002-2009 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -16,12 +16,14 @@
package org.springframework.aop.framework; package org.springframework.aop.framework;
import static org.hamcrest.CoreMatchers.instanceOf; import static org.hamcrest.CoreMatchers.instanceOf;
import static org.junit.Assert.*; import static org.junit.Assert.*;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import javax.swing.*;
import javax.accessibility.Accessible;
import org.aopalliance.intercept.MethodInterceptor; import org.aopalliance.intercept.MethodInterceptor;
import org.aopalliance.intercept.MethodInvocation; import org.aopalliance.intercept.MethodInvocation;
import org.junit.Test; import org.junit.Test;
@ -310,6 +312,15 @@ public final class ProxyFactoryTests {
assertTrue(proxy instanceof TestBean); assertTrue(proxy instanceof TestBean);
} }
@Test
public void testExclusionOfNonPublicInterfaces() {
JFrame frame = new JFrame();
ProxyFactory proxyFactory = new ProxyFactory(frame);
Object proxy = proxyFactory.getProxy();
assertTrue(proxy instanceof RootPaneContainer);
assertTrue(proxy instanceof Accessible);
}
public static class Concrete { public static class Concrete {
@ -317,26 +328,18 @@ public final class ProxyFactoryTests {
} }
} }
}
/**
* Simple before advice example that we can use for counting checks.
*
* @author Rod Johnson
*/
@SuppressWarnings("serial") @SuppressWarnings("serial")
class CountingBeforeAdvice extends MethodCounter implements MethodBeforeAdvice { private static class CountingBeforeAdvice extends MethodCounter implements MethodBeforeAdvice {
public void before(Method m, Object[] args, Object target) throws Throwable { public void before(Method m, Object[] args, Object target) throws Throwable {
count(m); count(m);
} }
} }
@SuppressWarnings("serial") @SuppressWarnings("serial")
class TimestampIntroductionInterceptor extends DelegatingIntroductionInterceptor private static class TimestampIntroductionInterceptor extends DelegatingIntroductionInterceptor
implements TimeStamped { implements TimeStamped {
private long ts; private long ts;
@ -355,5 +358,6 @@ class TimestampIntroductionInterceptor extends DelegatingIntroductionInterceptor
public long getTimeStamp() { public long getTimeStamp() {
return ts; return ts;
} }
}
} }

View File

@ -948,7 +948,8 @@ public abstract class ClassUtils {
while (clazz != null) { while (clazz != null) {
Class[] ifcs = clazz.getInterfaces(); Class[] ifcs = clazz.getInterfaces();
for (Class ifc : ifcs) { for (Class ifc : ifcs) {
if (!interfaces.contains(ifc) && (classLoader == null || isVisible(ifc, classLoader))) { if (!interfaces.contains(ifc) && Modifier.isPublic(ifc.getModifiers()) &&
(classLoader == null || isVisible(ifc, classLoader))) {
interfaces.add(ifc); interfaces.add(ifc);
} }
} }