[PATCH] 8188240: Reflection Proxy should skip static methods
mandy chung
mandy.chung at oracle.com
Tue Mar 13 23:31:09 UTC 2018
On 3/13/18 4:06 PM, David Lloyd wrote:
> I worked up a little patch for 8188240. I was able to co-opt an
> existing test which now fails before the patch and passes after. It's
> a tiny patch so I'm including it inline. I've CC'd Mandy because she
> filed the original bug.
>
> Here's the patch (use patch -p1 to apply):
>
> -------- cut ------- 8< ------- cut --------
> diff --git a/src/java.base/share/classes/java/lang/reflect/ProxyGenerator.java
> b/src/java.base/share/classes/java/lang/reflect/ProxyGenerator.java
> index cc8dbbfffab..465a5b938e3 100644
> --- a/src/java.base/share/classes/java/lang/reflect/ProxyGenerator.java
> +++ b/src/java.base/share/classes/java/lang/reflect/ProxyGenerator.java
> @@ -449,7 +449,9 @@ class ProxyGenerator {
> */
> for (Class<?> intf : interfaces) {
> for (Method m : intf.getMethods()) {
> - addProxyMethod(m, intf);
> + if (! Modifier.isStatic(m.getModifiers())) {
> + addProxyMethod(m, intf);
> + }
> }
> }
This looks okay.
>
> diff --git a/test/jdk/java/lang/reflect/Proxy/Basic1.java
> b/test/jdk/java/lang/reflect/Proxy/Basic1.java
> index b2440ccd9f9..4a21470b1be 100644
> --- a/test/jdk/java/lang/reflect/Proxy/Basic1.java
> +++ b/test/jdk/java/lang/reflect/Proxy/Basic1.java
> @@ -36,6 +36,10 @@ import java.util.*;
>
> public class Basic1 {
>
> + public interface ClashWithRunnable {
> + static int run() { return 123; }
> + }
> +
> public static void main(String[] args) {
>
> System.err.println(
> @@ -43,7 +47,7 @@ public class Basic1 {
>
> try {
> Class<?>[] interfaces =
> - new Class<?>[] { Runnable.class, Observer.class };
> + new Class<?>[] { ClashWithRunnable.class,
> Runnable.class, Observer.class };
>
> ClassLoader loader = ClassLoader.getSystemClassLoader();
>
> -------- cut ------- 8< ------- cut --------
I prefer to keep the original test case i.e. create a proxy class from
Runnable and Observer. Instead add a new test case to create a proxy
class with ClashWithRunnable, Runnable and Observer and verify that it
does not include static methods. I would add another static method
ClashWithRunnable::foo (no name clash) and verify
proxyClass::getDeclaredMethods does not contain foo.
Mandy
More information about the core-libs-dev
mailing list