Discussion:
Bug in Assisted Factory when contructing an object
Electro Type
2016-09-13 19:30:23 UTC
Permalink
I currently do not have a test class to provide, I first want to know if
this is a problem with Assisted Factories you are aware of... If it's not,
I'll try to create a test class for you to check! I use Guice 4.1.0.

The pseudo-code triggering the problem is something like this :

- Object A uses the method "create()" of an assisted factory to create
object B, which is of class "Widget".
- There is an @Inject annotated method (called "init()") on class Widget.
- In this "init()" method, B uses the same "create()" method from the same
assisted factory to create a Object C. And this is where the problem
occures : the created "C" is not valid! Note that C is of the same class
than B (Widget), but C doesn't create any new object in its own "init()"
method.

I've tried to debug Guice's code a little bit, and found that this problem
is caused in *com.google.inject.assistedinject.FactoryProvider2#invoke(...)*
when *data.cachedBinding* is not null. I also saw that *data.cachedBinding*
is not null when the "*optimized*" property is true. I searched to see how
I could disable this optimization and saw that injecting the Guice Injector
itself in my objects was a way to do it. I tried it and it did work!! That
produced a valid "C" object...

Of course I do not want to stick with such very slow workaround.

Are you aware of this problem?

Thanks!

Julien
--
You received this message because you are subscribed to the Google Groups "google-guice" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-guice+***@googlegroups.com.
To post to this group, send email to google-***@googlegroups.com.
Visit this group at https://groups.google.com/group/google-guice.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-guice/aec3a4cc-0568-4700-8155-309cbc0249be%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Electro Type
2016-09-13 22:43:09 UTC
Permalink
Here's a test project :
https://github.com/electrotype/guice-assisted-factory-bug

Please run */src/test/java/TestClass.java* with Junit.
--
You received this message because you are subscribed to the Google Groups "google-guice" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-guice+***@googlegroups.com.
To post to this group, send email to google-***@googlegroups.com.
Visit this group at https://groups.google.com/group/google-guice.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-guice/337ac538-fdb2-47c2-beca-c346a231e6b6%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Tavian Barnes
2016-09-14 14:06:28 UTC
Permalink
Seems like a bug. You should report it
here: https://github.com/google/guice/issues
Post by Electro Type
https://github.com/electrotype/guice-assisted-factory-bug
Please run */src/test/java/TestClass.java* with Junit.
--
You received this message because you are subscribed to the Google Groups "google-guice" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-guice+***@googlegroups.com.
To post to this group, send email to google-***@googlegroups.com.
Visit this group at https://groups.google.com/group/google-guice.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-guice/341f860a-c8db-4ab7-a71b-ecc1ee6bc43b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Electro Type
2016-09-14 14:20:27 UTC
Permalink
Done : https://github.com/google/guice/issues/1044

Thanks.
--
You received this message because you are subscribed to the Google Groups "google-guice" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-guice+***@googlegroups.com.
To post to this group, send email to google-***@googlegroups.com.
Visit this group at https://groups.google.com/group/google-guice.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-guice/821431ec-316c-42fd-9a99-be692e7bbd40%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Loading...