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

In java proxy example, bad usage of java.lang.IllegalAccessException #28

Open
Nimamoh opened this issue Nov 22, 2020 · 0 comments
Open

Comments

@Nimamoh
Copy link

Nimamoh commented Nov 22, 2020

On the java proxy example, when creating the owner dynamic proxy: OwnerInvocationHandler

The logic is to prevent owner to call its setGeekRating, it is done throwing a java.lang.IllegalAccessException, unless I misunderstood, it is a really poor choice:

IllegalAccessException is used when trying to reflectively access something you have no right to in term of the language (i.e: trying to invoke a private method from outside).
It is also a checked exception, which means it will be wrapped in a UndeclaredThrowableException (see InvocationHandler::invoke javadoc)

Since I follow the exemples quite loosely I were dubious about getting an UndeclaredThrowableException in my client code (which is not a problem on the book's examples since all exceptions are catched). I think a specific exception or even a generic RuntimeException would be more appropriate.

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

No branches or pull requests

1 participant