为什么 NativeMethodAccessorImpl 声明 InvocationTargetException
Why NativeMethodAccessorImpl declare InvocationTargetException
NativeMethodAccessorImpl invoke method 声明它可以抛出 IllegalArgumentException
或 InvocationTargetException
public Object invoke(Object obj, Object[] args)
throws IllegalArgumentException, InvocationTargetException
{
// We can't inflate methods belonging to vm-anonymous classes because
// that kind of class can't be referred to by name, hence can't be
// found from the generated bytecode.
if (++numInvocations > ReflectionFactory.inflationThreshold()
&& !ReflectUtil.isVMAnonymousClass(method.getDeclaringClass())) {
MethodAccessorImpl acc = (MethodAccessorImpl)
new MethodAccessorGenerator().
generateMethod(method.getDeclaringClass(),
method.getName(),
method.getParameterTypes(),
method.getReturnType(),
method.getExceptionTypes(),
method.getModifiers());
parent.setDelegate(acc);
}
return invoke0(method, obj, args);
}
private static native Object invoke0(Method m, Object obj, Object[] args);
本机方法 在某些情况下,例如
Exception in thread "main" java.lang.IllegalArgumentException: argument type mismatch
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
但是我没有看到任何抛出 InvocationTargetException
checked exception
的选项
InvocationTargetException
可以被本机方法 invoke0
抛出(不声明异常)吗?
或者 InvocationTargetException
是否因为方法签名 backward/future 兼容性而保留?
invoke0 可以抛出 InvocationTargetException
:
Exception in Application start method
java.lang.reflect.InvocationTargetException
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
例如当找不到 FXML 资源文件时。
NativeMethodAccessorImpl invoke method 声明它可以抛出 IllegalArgumentException
或 InvocationTargetException
public Object invoke(Object obj, Object[] args) throws IllegalArgumentException, InvocationTargetException { // We can't inflate methods belonging to vm-anonymous classes because // that kind of class can't be referred to by name, hence can't be // found from the generated bytecode. if (++numInvocations > ReflectionFactory.inflationThreshold() && !ReflectUtil.isVMAnonymousClass(method.getDeclaringClass())) { MethodAccessorImpl acc = (MethodAccessorImpl) new MethodAccessorGenerator(). generateMethod(method.getDeclaringClass(), method.getName(), method.getParameterTypes(), method.getReturnType(), method.getExceptionTypes(), method.getModifiers()); parent.setDelegate(acc); } return invoke0(method, obj, args); } private static native Object invoke0(Method m, Object obj, Object[] args);
本机方法
Exception in thread "main" java.lang.IllegalArgumentException: argument type mismatch at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
但是我没有看到任何抛出 InvocationTargetException
checked exception
InvocationTargetException
可以被本机方法 invoke0
抛出(不声明异常)吗?
或者 InvocationTargetException
是否因为方法签名 backward/future 兼容性而保留?
invoke0 可以抛出 InvocationTargetException
:
Exception in Application start method
java.lang.reflect.InvocationTargetException
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
例如当找不到 FXML 资源文件时。