aspakh / google-gin

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

Ambiguous error when injecting with UIBinder and constructor parameters #115

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1. Create new UIBinder (creates class and .xml file) - e.g. MainPanel
2. Annotate MainPanel with @Singleton and it's constructor with @Inject and 
otherwise prepare it to be injected.
3. Remove all ui elements and references to ui elements in the xml file and in 
the MainPanel class. But leave the parameters in the MainPanel constructor 
(e.g. "String firstName").
4. In entry point class, instantiate the injector and get MainPanel from the 
injector.
5. run.

What is the expected output? What do you see instead?
I expect an intelligent error.

Instead, I get the following:
[ERROR] [helloworlds] Binding requested for constant key 
Key[type=java.lang.String, annotation=[none]] but no explicit binding was found.

What version of the product are you using? On what operating system?
gin 1.0, jan 2010 on Ubuntu 10.04 32 bit

Please provide any additional information below.

And now in my MainPanel class:
@Singleton
public class MainPanel extends Composite {
    ...
    @Inject
    public MainPanel(String firstName) { // this is the offender!
    ...

And this the xml file for UIBinder:

<g:DockLayoutPanel unit="PX">
<g:center>
<g:HTML>center</g:HTML>
</g:center>
</g:DockLayoutPanel>

And in my EntryPoint class I do:
public final MyWidgetGinjector injector = GWT.create(MyWidgetGinjector.class);

And:
MainPanel mcp = injector.getMainPanel();

Clearly I'm wrong for leaving the parameter in a constructor of a class that is 
being injected and not dealing with it, but the error received gave only an 
ambiguous indication as to what the problem was. Something more helpful, like 
"You have a non-zero argument constructor in the injected class: MainPanel. Get 
rid of that argument!"

This would be especially helpful for people trying gin out for the first time 
and altering the generated code from Eclipse and forgetting to delete a 
constructor argument. (Especially since a quick search on Google yields only 
links to the code.)

Original issue reported on code.google.com by rscottf...@gmail.com on 16 Aug 2010 at 2:58

GoogleCodeExporter commented 8 years ago
There is actually someone working in improving the error messages in Gin, 
hopefully that patch will soon be ready. There are some difficulties with 
resolving this particular use case but as far as I know, a solution is in the 
works.

Original comment by aragos on 22 Aug 2010 at 1:08