google/guice — pull request #857 by HiJon89 (2014-10-03 11:24:07+00:00)
Title: Move the references to javax.servlet classes into the anonymous class

This fixes an issue I encountered when trying to upgrade to Guice 4. These static references were added to `ServletScopes` that reference `HttpServletRequest` and `HttpServletResponse`. This causes a `NoClassDefFoundError` if you reference `ServletScopes` without javax.servlet:servlet-api on the classpath (the guice-servlet dependency on this JAR has provided scope).

Our use-case is that we have a custom scope annotation that is bound to request-scoped in our API's, and no scope in our background jobs. We have a module that determines what environment we're running in and binds the scope annotation automatically. It looks something like this:

```java
@Override
protected void configure() {
bindScope(CustomScope.class, isApi() ? ServletScopes.REQUEST : Scopes.NO_SCOPE);
}
```

This worked fine in Guice 3. The problem is that in Guice 4, simply referencing `ServletScopes.REQUEST` (even if you don't end up using it) throws a `NoClassDefFoundError` unless you have javax.servlet:servlet-api on the classpath (which we don't in our background jobs).

Let me know if I'm missing an obvious workaround, we don't want to have to add javax.servlet:servlet-api to the classpath for our background jobs (for philosophical and practical reasons).