Skip to content

Commit

Permalink
Improve exception handling during method guessing
Browse files Browse the repository at this point in the history
In some configurations, stream corruptions can occur during method
guessing with multiple threads. This behavior seems to be non
deterministically and was not fully understood yet. However, even on
affected configurations, the miss rate is roughly at 1/3000 methods that
fail. For this reason, we catch the resulting exceptions for now and
only display warnings if running in verbose mode.
  • Loading branch information
qtc-de committed Dec 14, 2023
1 parent f24fb73 commit 779e4b0
Showing 1 changed file with 63 additions and 6 deletions.
69 changes: 63 additions & 6 deletions src/eu/tneitzel/rmg/operations/MethodGuesser.java
Original file line number Diff line number Diff line change
Expand Up @@ -440,6 +440,25 @@ public void run()
}
}

catch (java.rmi.UnmarshalException e)
{
/*
* When running with multiple threads, from time to time, stream corruption can be observed.
* This seems to be non deterministically and only appears in certain setups. In my current
* setup, it seems always to break on the "String selectSurname(String email)" method. In
* future, this should be debugged. However, as in a run of 3000 methods this only occurs one
* or two times, it is probably not that important.
*/
if (RMGOption.GLOBAL_VERBOSE.getBool())
{
String info = "Caught unexpected " + e.getClass().getName() + " while guessing the " + candidate.getSignature() + "method.\n"
+"[-]" + Logger.getIndent() + "This occurs sometimes when guessing with multiple threads.\n"
+"[-]" + Logger.getIndent() + "You can retry with --threads 1 or just ignore the exception.";
Logger.eprintlnBlue(info);
ExceptionHandler.showStackTrace(e);
}
}

catch(Exception e)
{
/*
Expand All @@ -449,11 +468,11 @@ public void run()
e.printStackTrace(new PrintWriter(writer));

String info = "Caught unexpected " + e.getClass().getName() + " during method guessing.\n"
+"Please report this to improve rmg :)\n"
+"Stack-Trace:\n"
+"[-]" + Logger.getIndent() + "Please report this to improve rmg :)\n"
+"[-]" + Logger.getIndent() + "Stack-Trace:\n"
+writer.toString();

Logger.println(info);
Logger.eprintlnBlue(info);
}

finally
Expand Down Expand Up @@ -557,6 +576,25 @@ public void run()
*/
}

else if (cause instanceof java.rmi.UnmarshalException)
{
/*
* When running with multiple threads, from time to time, stream corruption can be observed.
* This seems to be non deterministically and only appears in certain setups. In my current
* setup, it seems always to break on the "String selectSurname(String email)" method. In
* future, this should be debugged. However, as in a run of 3000 methods this only occurs one
* or two times, it is probably not that important.
*/
if (RMGOption.GLOBAL_VERBOSE.getBool())
{
String info = "Caught unexpected " + e.getClass().getName() + " while guessing the " + SpringRemotingWrapper.getSignature(invocationHolder.getCandidate()) + " method.\n"
+"[-]" + Logger.getIndent() + "This occurs sometimes when guessing with multiple threads.\n"
+"[-]" + Logger.getIndent() + "You can retry with --threads 1 or just ignore the exception.";
Logger.eprintlnBlue(info);
ExceptionHandler.showStackTrace(e);
}
}

else
{
/*
Expand All @@ -566,6 +604,25 @@ public void run()
}
}

catch (java.rmi.UnmarshalException e)
{
/*
* When running with multiple threads, from time to time, stream corruption can be observed.
* This seems to be non deterministically and only appears in certain setups. In my current
* setup, it seems always to break on the "String selectSurname(String email)" method. In
* future, this should be debugged. However, as in a run of 3000 methods this only occurs one
* or two times, it is probably not that important.
*/
if (RMGOption.GLOBAL_VERBOSE.getBool())
{
String info = "Caught unexpected " + e.getClass().getName() + " while guessing the " + SpringRemotingWrapper.getSignature(invocationHolder.getCandidate()) + " method.\n"
+"[-]" + Logger.getIndent() + "This occurs sometimes when guessing with multiple threads.\n"
+"[-]" + Logger.getIndent() + "You can retry with --threads 1 or just ignore the exception.";
Logger.eprintlnBlue(info);
ExceptionHandler.showStackTrace(e);
}
}

catch(Exception e)
{
/*
Expand Down Expand Up @@ -600,8 +657,8 @@ private void unexpectedError(RemoteInvocationHolder invoHolder, Exception e)
e.printStackTrace(new PrintWriter(writer));

info = "Caught unexpected " + e.getClass().getName() + " during method guessing.\n"
+"Please report this to improve rmg :)\n"
+"Stack-Trace:\n"
+"[-]" + Logger.getIndent() + "Please report this to improve rmg :)\n"
+"[-]" + Logger.getIndent() + "Stack-Trace:\n"
+writer.toString();
}

Expand All @@ -610,7 +667,7 @@ private void unexpectedError(RemoteInvocationHolder invoHolder, Exception e)
info = "Spring Remoting call did not cause an exception. This is not expected.";
}

Logger.println(info);
Logger.eprintlnBlue(info);
}
}
}

0 comments on commit 779e4b0

Please sign in to comment.