Child pages
  • Multiple Business Interface Hazzards
Skip to end of metadata
Go to start of metadata

UndeclaredThrowableException

When two java interfaces are implemented by a proxy and those two interfaces declare the same method but with different throws clauses some very nasty side effects happen, namely you loose the ability to throw any checked exceptions that are not in the throws clause of both methods.

IllegalArgumentException

This one is less of a runtime problem as doing this will cause things to fail up front. When two java interfaces are implemented by a proxy and those two interfaces declare the same method but with different return types the VM proxy code will refuse to create a proxy at all. Take this code example:

Running this code will result in the following exception:

java.lang.IllegalArgumentException: methods with same signature run(java.lang.Object) but incompatible return types: [class ReturnTest$ThingOne, class ReturnTest$ThingTwo]
	at sun.misc.ProxyGenerator.checkReturnTypes(ProxyGenerator.java:669)
	at sun.misc.ProxyGenerator.generateClassFile(ProxyGenerator.java:420)
	at sun.misc.ProxyGenerator.generateProxyClass(ProxyGenerator.java:306)
	at java.lang.reflect.Proxy.getProxyClass(Proxy.java:501)
	at java.lang.reflect.Proxy.newProxyInstance(Proxy.java:581)
	at ReturnTest.test(ReturnTest.java:36)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
	at com.intellij.rt.execution.junit2.JUnitStarter.main(JUnitStarter.java:32)

  • No labels