Skip to content

Instantly share code, notes, and snippets.

@gissuebot
Created July 7, 2014 19:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gissuebot/e778ccd9dd78313a4a3b to your computer and use it in GitHub Desktop.
Save gissuebot/e778ccd9dd78313a4a3b to your computer and use it in GitHub Desktop.
Migrated attachment for Guice issue 757, comment 0
import com.google.inject.AbstractModule;
import com.google.inject.Guice;
import com.google.inject.Injector;
import com.google.inject.Provides;
import java.util.concurrent.Executor;
import java.util.concurrent.Executors;
import java.util.function.Supplier;
public final class Java8LambdaIssue {
public static void main(String[] args) {
Injector injector = Guice.createInjector(new LambdaIssueModule());
Executor executor = injector.getInstance(Executor.class);
}
private static class LambdaIssueModule extends AbstractModule {
@Override
protected void configure() { }
@Provides
public Executor createExecutor() {
if (returnTrue()) {
throw new IllegalStateException("Something went wrong");
}
// NB: the following code will not be executed
Supplier<String> supplier = () -> "The presence of this lambda causes Guice's exception handling to fail";
// commenting out the above lambda allows Guice's error handling to correctly report the IllegalStateException
return Executors.newSingleThreadExecutor();
}
}
/** Avoid dead code elimination by javac. */
private static boolean returnTrue() {
return Boolean.parseBoolean("true");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment