Skip to content
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

Merged
merged 3 commits into from
Mar 30, 2017

Conversation

juddgaddie
Copy link
Contributor

see #15

@@ -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()))
Copy link
Contributor

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.

Copy link
Contributor Author

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)
{
Copy link
Contributor

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?

Copy link
Contributor Author

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.

@juddgaddie juddgaddie merged commit 8a0c2b9 into LMAX-Exchange:master Mar 30, 2017
@juddgaddie
Copy link
Contributor Author

@epickrram reviewed and is happy for me to merge.

@juddgaddie juddgaddie changed the title return the toString of invocation handler when calling toString on thee proxy return the toString of invocation handler when calling toString on the proxy Oct 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants