Confirm bug in java.lang.reflect.Proxy wrt static methods in interfaces

Eric McCorkle eric at
Mon Oct 2 18:44:26 UTC 2017

Hello everyone,

A colleague of mine discovered what seems to be a bug in
java.lang.reflect.Proxy#newProxyInstance.  I'd like to confirm that this
is indeed incorrect behavior before I go and fix it.

Consider the following two interfaces:

interface I1 {
  static I1 foo() {
    return null;

interface I2 {
  static I2 foo() {
    return null;

JLS 9.4.1 states that static methods are not inherited in interfaces,
thus it should be perfectly legal to define some class which inherits I1
and I2.

The following proxy creation fails:

public class ProxyBug {
  public static void main(String... args) {
    I2 i2 =(I2)Proxy.newProxyInstance(
                 new Class[] {I1.class, I2.class},
                 new InvocationHandler() {
                   public Object invoke(Object proxy,
                                        Method method,
                                        Object[] args)
                     throws Throwable {
                     return null;

The exception generated is as follows:

Exception in thread "main" java.lang.IllegalArgumentException: methods
with same signature foo() but incompatible return types: [interface I1,
interface I2]
	at sun.misc.ProxyGenerator.checkReturnTypes(
	at sun.misc.ProxyGenerator.generateClassFile(
	at sun.misc.ProxyGenerator.generateProxyClass(
	at java.lang.reflect.Proxy$ProxyClassFactory.apply(
	at java.lang.reflect.Proxy$ProxyClassFactory.apply(
	at java.lang.reflect.WeakCache$Factory.get(
	at java.lang.reflect.WeakCache.get(
	at java.lang.reflect.Proxy.getProxyClass0(
	at java.lang.reflect.Proxy.newProxyInstance(
	at ProxyBug.main(

So it would seem that newProxyInstance is incorrectly including static
methods in its check for incompatible return types.

Can I get someone from core-libs to confirm that this is not intended
before I file a bug and start on the fix?

More information about the core-libs-dev mailing list