fmgasparino / google-gin

Automatically exported from code.google.com/p/google-gin
Apache License 2.0
0 stars 0 forks source link

Unhelpful error message when attempting to bind to inner class #99

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Add a bind(SomeClass.class).to(SomeInnerClass.class) to 
GinModule.configure()
2. Attempt to build

What is the expected output? What do you see instead?
It would be nice to get a specific message saying that inner classes can't 
be bound.  Instead, I get
java.lang.RuntimeException: Deferred binding failed for 
'my.package.TestingGinModule$MyClassStub' (did you forget to inherit a 
required module?)

What version of the product are you using? On what operating system?
r130, under Google's build system

Please provide any additional information below.

Original issue reported on code.google.com by stephenh...@gmail.com on 21 Apr 2010 at 12:52

GoogleCodeExporter commented 9 years ago
It should be possible to bind to inner classes. Please give me a code sample 
(class
containing inner class, ginjector and ginmodule) and I'll try to find the bug.

Original comment by aragos on 21 Apr 2010 at 3:23

GoogleCodeExporter commented 9 years ago
I've never been able to bind to a (non-static) inner class. Although I never 
had any 
problem binding to a (static) nested class. I've never really needed an inner 
class, 
though, and the error was typically due to me forgetting the "static" keyword 
on my 
nested class. Maybe this is your problem?

Original comment by philippe.beaudoin on 21 Apr 2010 at 3:43

GoogleCodeExporter commented 9 years ago
Yes, that's precisely the problem.  But it took a lot of frustrated debugging 
to 
figure out I'd forgotten add "static", and it seems like a more helpful error 
message 
should have been possible.

It turns out that I was only looking at the text of the exception that was 
thrown, 
since the output to stdout was suppressed by my build tools.  The suppressed 
output 
is slightly more helpful:

[ERROR] Rebind result 'my.package.TestingGinModule.MyClassStub' has no default 
(zero 
argument) constructors.
java.lang.NoSuchMethodException: 
my.package.TestingGinModule$MyClassStub.<init>()

But maybe it could still be better?  I suppose my main take-home message from 
this is 
to make sure to always check stdout whenever I get an error asking if I forgot 
to 
inherit a required module.  But I wonder if there's a way to forward the actual 
error 
text to the exception as well?

Original comment by stephenh...@gmail.com on 22 Apr 2010 at 5:15

GoogleCodeExporter commented 9 years ago

Original comment by aragos on 4 Apr 2011 at 7:14