Created
July 7, 2014 19:11
-
-
Save gissuebot/e778ccd9dd78313a4a3b to your computer and use it in GitHub Desktop.
Migrated attachment for Guice issue 757, comment 0
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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