daluu / jrobotremoteserver-1.x

The original discontinued jrobotremoteserver now hosted here due to Google Code's demise
http://code.google.com/p/jrobotremoteserver
0 stars 0 forks source link

Wrong exception when exception thrown for ExampleRemoteLibrary #2

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Run Robot Framework Example test for remote library against the remote 
server's example remote library.

What is the expected output? What do you see instead?

Get generic exception with text of "Given strings are not equal".

But instead get this on the command line for the remote server. Robot Framework 
test result reports similar output:

2: __default__.run_keyword[strings_should_be_equal, [hello, world]]
Comparing 'hello' to 'worldjava.lang.reflect.InvocationTargetException
'Somehow we get null pointer exception here instead of what's below.
2: {output=null, return=, status=FAIL, error=null, 
traceback=[Ljava.lang.StackTraceElement;@b02efa[Ljava.lang.StackTraceElement;@b0
2efa[Ljava.lang.StackTraceElement;@b02efa[Ljava.lang.StackTraceElement;@b02efa[L
java.lang.StackTraceElement;@b02efa[Ljava.lang.StackTraceElement;@b02efa[Ljava.l
ang.StackTraceElement;@b02efa[Ljava.lang.StackTraceElement;@b02efa[Ljava.lang.St
ackTraceElement;@b02efa[Ljava.lang.StackTraceElement;@b02efa[Ljava.lang.StackTra
ceElement;@b02efa[Ljava.lang.StackTraceElement;@b02efa[Ljava.lang.StackTraceElem
ent;@b02efa[Ljava.lang.StackTraceElement;@b02efa[Ljava.lang.StackTraceElement;@b
02efa[Ljava.lang.StackTraceElement;@b02efa[Ljava.lang.StackTraceElement;@b02efa[
Ljava.lang.StackTraceElement;@b02efa[Ljava.lang.StackTraceElement;@b02efa}
2: null
Mar 20, 2011 2:36:07 AM redstone.xmlrpc.XmlRpcDispatcher writeError
WARNING: java.lang.NullPointerException: null

Original issue reported on code.google.com by manga...@gmail.com on 25 Mar 2011 at 6:24

GoogleCodeExporter commented 9 years ago
Something I'll have to investigate further when I have time. Issue with Java 
reflection call, but I'm not intimately familiar with Java reflection.

Original comment by manga...@gmail.com on 25 Mar 2011 at 6:25

GoogleCodeExporter commented 9 years ago
Just a thought, maybe this has to do with Java exceptions. Perhaps when 
throwing exceptions it is considered another argument/parameter, so reflection 
call needs to pass some additional expected parameter? Need to research...

If true, code will have to figure out from reflection call whether the method 
actually throws an exception on a given code path, and handle that accordingly.

Original comment by manga...@gmail.com on 25 Mar 2011 at 6:40

GoogleCodeExporter commented 9 years ago
From researching related issue for .NET implementation, this is the reason for 
the issue and the likely solution:

http://download.oracle.com/javase/1.4.2/docs/api/java/lang/reflect/InvocationTar
getException.html#getTargetException()

Original comment by manga...@gmail.com on 14 Sep 2011 at 5:35

GoogleCodeExporter commented 9 years ago
To be fixed with next patch release.

Original comment by manga...@gmail.com on 18 Sep 2011 at 1:17

GoogleCodeExporter commented 9 years ago
From developer feedback as well:

Hi David

I think the issue may be in the catch block of the run_keyword method of the 
RemoteServerMethods class. InvocationTargetException may be swallowing your 
error messages. A possible workaround is to check if the exception you catch is 
an InvocationTargetException and handle its cause instead.

Also, you are getting an ugly stack trace because you are not handling it 
properly. The idiomatic way to do it is:

e.printStackTrace(new PrintWriter(stringWriter));
String stktrc = stringWriter.toString();

Ugly, and hard to guess or remember (I have to google for it every time I need 
it), but you wanted to use Java :P

This is what the catch block should look like:

catch (Throwable e) {
    if(e instanceof InvocationTargetException){
        e = e.getCause();
    }
    e.printStackTrace();
    kr.put("status", "FAIL");
    kr.put("return", "");
    kr.put("error",e.getMessage());
    kr.put("output",e.getMessage());
    StringWriter stringWriter = new StringWriter();
    e.printStackTrace(new PrintWriter(stringWriter));
    String stktrc = stringWriter.toString();
    kr.put("traceback", stktrc);
    return kr;

}

Hope that helps

Original comment by manga...@gmail.com on 18 Sep 2011 at 1:25

GoogleCodeExporter commented 9 years ago
This should be fixed with the new release at 
https://github.com/ombre42/jrobotremoteserver

Original comment by manga...@gmail.com on 21 Jul 2012 at 5:52