jjnair / fest

Automatically exported from code.google.com/p/fest
0 stars 0 forks source link

fest-reflect is catching my RuntimeException while it should not! #310

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
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

Original issue reported on code.google.com by Francis....@gmail.com on 11 Feb 2009 at 8:52

GoogleCodeExporter commented 8 years ago
[deleted comment]
GoogleCodeExporter commented 8 years ago
[deleted comment]
GoogleCodeExporter commented 8 years ago
Issue migrated to http://jira.codehaus.org/browse/FEST-68

Original comment by Alex.Rui...@gmail.com on 5 Mar 2009 at 10:51

GoogleCodeExporter commented 8 years ago
I have a fix in place, this bug also affects constructor invocation. I'll have a
SNAPSHOT release shortly.

Thanks! :)
-Alex

Original comment by Alex.Rui...@gmail.com on 19 Mar 2009 at 6:46

GoogleCodeExporter commented 8 years ago
Method invocation and constructor invocation now throw the original exception 
thrown
by this invocations, instead of wrapping them with a ReflectionError.

Original comment by Alex.Rui...@gmail.com on 19 Mar 2009 at 8:25