Status: New
Owner: ----

New issue 544 by mathieu.carbou: Guice servlet module crashed when used with Elements.getElements()
http://code.google.com/p/google-guice/issues/detail?id=544

To reproduice:

1. Create a web.xml with a Guice servlet config containing at least one filter mapping.

2. Before creating the injector use Elements.elements() to insepect all the modules. I.e.

In my case i need to search if a binding has been defined for a specific type:

for (Element element : Elements.getElements(stage, modules)) {
Boolean res = element.acceptVisitor(new DefaultElementVisitor<Boolean>() {
        @Override
        public <T> Boolean visit(Binding<T> binding) {
            return key.equals(binding.getKey());
        }
    });
    if (res != null && res)
        return true;
}

3. Then create the injector with the modules you have introspected.


ServletsModuleBuilder crashed there:

Set<String> servletUris = Sets.newHashSet();
for (ServletDefinition servletDefinition : servletDefinitions) {
  if (servletUris.contains(servletDefinition.getPattern())) {
    addError("More than one servlet was mapped to the same URI pattern: "
        + servletDefinition.getPattern());
  }
  else {
bind(Key.get(ServletDefinition.class, UniqueAnnotations.create())).toProvider(servletDefinition);
    servletUris.add(servletDefinition.getPattern());
  }
}

When introspecting, servletDefinitions have been added to the module's instance variable. So when the injector goes through the module again, it launches an error saying that the servletDefinitions already exist.

This is quite critical for use... Would it be possible to fix or is there at this time a workaround for this ?

NB: we don't have the possibllity to instanciate the modules again.


--
You received this message because you are subscribed to the Google Groups 
"google-guice-dev" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/google-guice-dev?hl=en.

Reply via email to