Issue 722 in google-guice: PrivateModule prevents interceptors to be applied

26 views
Skip to first unread message

google...@googlecode.com

unread,
Aug 2, 2012, 8:44:29 AM8/2/12
to google-g...@googlegroups.com
Status: New
Owner: ----

New issue 722 by wix...@gmail.com: PrivateModule prevents interceptors to
be applied
http://code.google.com/p/google-guice/issues/detail?id=722

Description of the issue:
When an interceptor is bound inside a private module the original class
will not be enhanced if its bound and exposed via an interface. If the
class is bound and exposed directly or if the interface is bound in a non
private module the interceptors are applied correctly. This seems incorrect
and an inconsistent behavior.

Steps to reproduce:
1. run all 3 unit tests in attached InterceptorTest class
2. testPrivateModule fails, but the other 2 run fine

Attachments:
InterceptorTest.java 2.7 KB

google...@googlecode.com

unread,
Aug 2, 2012, 8:45:29 AM8/2/12
to google-g...@googlegroups.com

Comment #1 on issue 722 by wix...@gmail.com: PrivateModule prevents
Probably related to issue702

google...@googlecode.com

unread,
Aug 2, 2012, 9:04:16 AM8/2/12
to google-g...@googlegroups.com

Comment #2 on issue 722 by wix...@gmail.com: PrivateModule prevents
upload new test without the @Ignore annotation

Attachments:
InterceptorTest.java 2.6 KB

google...@googlecode.com

unread,
Aug 2, 2012, 9:27:42 AM8/2/12
to google-g...@googlegroups.com
Updates:
Status: WorkingAsIntended

Comment #3 on issue 722 by sberlin: PrivateModule prevents interceptors to
be applied
http://code.google.com/p/google-guice/issues/detail?id=722

Somewhat unfortunately, this is working-as-designed.

Because of the way just-in-time-bindings work, in the HelloModulePrivate,
Guice does not know that the statement:
bind(HelloWord.class).to(HelloWorldImpl.class)
also means that 'HelloWorldImpl' is 'private'. The statement is only
saying, "Link HelloWorld to HelloWordImpl". Because of that, HelloWordImpl
is actually being bound in the parent module, and the interceptor in the
private module can't see it.

This is why HelloModulePrivateNoInterface works -- you have a separate
bind(HelloWorldImpl.class) line, telling Guice that HelloWorldImpl wants to
be private.

If you add that bind statement (doesn't need to be a singleton as it is in
HelloModulePrivateNoInterface) in the HelloModulePrivate, then things will
start working.

Another fix would be to add 'binder().requireExplicitBindings()' to the
parent Module, and that will tell Guice that you don't want just-in-time
bindings at all, and everything should exist in the Module is was declared
in.

google...@googlecode.com

unread,
Aug 2, 2012, 10:02:16 AM8/2/12
to google-g...@googlegroups.com

Comment #4 on issue 722 by wix...@gmail.com: PrivateModule prevents
A bit surprising, but both your solutions work fine for me.
Many thanks for the prompt and useful reply!

Reply all
Reply to author
Forward
0 new messages