-
Bug
-
Resolution: Duplicate
-
P4
-
17, 21, 22, 23
-
b01
-
generic
-
generic
A DESCRIPTION OF THE PROBLEM :
run my code, I excepted StackOverflowError,but it print error : java.lang.NoClassDefFoundError: Could not initialize class java.lang.reflect.UndeclaredThrowableException why? this is bug?
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
I expected StackOverflowError
ACTUAL -
java.lang.NoClassDefFoundError: Could not initialize class java.lang.reflect.UndeclaredThrowableException
---------- BEGIN SOURCE ----------
import java.lang.reflect.Proxy;
import java.lang.reflect.UndeclaredThrowableException;
public class JdkDynamicProxy {
public static void main(String[] args) {
// new UndeclaredThrowableException(new RuntimeException());
ClassLoader classLoader = JdkDynamicProxy.class.getClassLoader();
MaiPiao proxyMaiPiao = (MaiPiao) Proxy.newProxyInstance(classLoader, new Class[]{MaiPiao.class}, (proxy, method, args1) -> {
if(method.getName().equals("maiPiao")){
System.out.println("卖票");
return null;
}else if(method.getName().equals("getName")){
return "name1";
}
return method.invoke(proxy);
});
proxyMaiPiao.maiPiao();
String name = proxyMaiPiao.getName();
System.out.println(name);
proxyMaiPiao.doSomething();
}
public interface MaiPiao{
void maiPiao();
String getName();
void doSomething();
}
}
---------- END SOURCE ----------
run my code, I excepted StackOverflowError,but it print error : java.lang.NoClassDefFoundError: Could not initialize class java.lang.reflect.UndeclaredThrowableException why? this is bug?
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
I expected StackOverflowError
ACTUAL -
java.lang.NoClassDefFoundError: Could not initialize class java.lang.reflect.UndeclaredThrowableException
---------- BEGIN SOURCE ----------
import java.lang.reflect.Proxy;
import java.lang.reflect.UndeclaredThrowableException;
public class JdkDynamicProxy {
public static void main(String[] args) {
// new UndeclaredThrowableException(new RuntimeException());
ClassLoader classLoader = JdkDynamicProxy.class.getClassLoader();
MaiPiao proxyMaiPiao = (MaiPiao) Proxy.newProxyInstance(classLoader, new Class[]{MaiPiao.class}, (proxy, method, args1) -> {
if(method.getName().equals("maiPiao")){
System.out.println("卖票");
return null;
}else if(method.getName().equals("getName")){
return "name1";
}
return method.invoke(proxy);
});
proxyMaiPiao.maiPiao();
String name = proxyMaiPiao.getName();
System.out.println(name);
proxyMaiPiao.doSomething();
}
public interface MaiPiao{
void maiPiao();
String getName();
void doSomething();
}
}
---------- END SOURCE ----------
- duplicates
-
JDK-8335478 Add notes for Error handling in Method.invoke and Constructor.newInstance
- Open