
fest - issue #310
fest-reflect is catching my RuntimeException while it should not!
What steps will reproduce the problem? package fest;
import org.fest.reflect.core.Reflection;
class MyRuntimeException extends RuntimeException { private static final long serialVersionUID = 1L; public MyRuntimeException(String text) { super(text); } }
public class Main { public void set() { throw new MyRuntimeException("set"); }
public static void main(String[] args) {
Main main = new Main();
try {
Reflection.method("set").in(main).invoke();
} catch(RuntimeException e) {
System.out.println(e.getMessage());
}
}
}
What is the expected output? set
What do you see instead? Exception in thread "main" org.fest.reflect.exception.ReflectionError: Unable to invoke method 'set' with arguments [] at org.fest.reflect.method.Invoker.invoke(Invoker.java:101) at fest.Main.main(Main.java:20) Caused by: java.lang.reflect.InvocationTargetException at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:585) at org.fest.reflect.method.Invoker.invoke(Invoker.java:99) ... 1 more Caused by: fest.MyRuntimeException: set at fest.Main.set(Main.java:14) ... 6 more
What version of the product are you using? On what operating system? fest-reflect-1.1.jar
Please provide any additional information below. When replacing throw MyRuntimeException by throw RuntimeException, one get the error message Unable to invoke method 'set' with arguments []
while it should be also set
Comment #1
Posted on Feb 11, 2009 by Quick WombatComment deleted
Comment #2
Posted on Feb 16, 2009 by Quick WombatComment deleted
Comment #3
Posted on Mar 5, 2009 by Quick WombatIssue migrated to http://jira.codehaus.org/browse/FEST-68
Comment #4
Posted on Mar 19, 2009 by Quick WombatI have a fix in place, this bug also affects constructor invocation. I'll have a SNAPSHOT release shortly.
Thanks! :) -Alex
Comment #5
Posted on Mar 19, 2009 by Quick WombatMethod invocation and constructor invocation now throw the original exception thrown by this invocations, instead of wrapping them with a ReflectionError.
Status: Fixed
Labels:
Module-fest-reflect
Milestone-Release1.2
Type-Defect
Priority-Critical
OpSys-All