-
Notifications
You must be signed in to change notification settings - Fork 36
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
return the toString of invocation handler when calling toString on the proxy #16
Conversation
@@ -51,6 +53,11 @@ | |||
@Override | |||
public Object invoke(final Object proxy, final Method method, final Object[] args) throws Throwable | |||
{ | |||
if (TO_STRING_METHOD_NAME.equals(method.getName())) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To be completely accurate, I think this check should also check the number of parameters to the call is zero. An overload of Foo.toString(long l) may need to be proxied.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point. I'll add that.
@@ -53,7 +53,7 @@ | |||
@Override | |||
public Object invoke(final Object proxy, final Method method, final Object[] args) throws Throwable | |||
{ | |||
if (TO_STRING_METHOD_NAME.equals(method.getName())) | |||
if (TO_STRING_METHOD_NAME.equals(method.getName()) && args == null) | |||
{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that you need to check args.length == 0. Could you include a unit test to verify?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is definitely null when there are no arguments, I've tested it and the JavaDoc states:
args - an array of objects containing the values of the arguments passed in the method invocation on the proxy instance, or null if interface method takes no arguments.
I'll work out a way of putting in a meaningful unit test to verify.
…ing toString on the proxy
@epickrram reviewed and is happy for me to merge. |
see #15