From b0fe03240b9f98137e11100c22537089ecc7cf51 Mon Sep 17 00:00:00 2001 From: Jesse Wilson Date: Tue, 1 Sep 2020 00:13:05 -0400 Subject: [PATCH] Test that crashes Guice inside Guava This test causes Guice to violate the requirements of Guava's LoadingCache by triggering a recursive load. The recursive load crashes either with an UncheckedExecutionException (bad) or causes a deadlock (terrible). https://github.com/google/guice/issues/785 --- .../com/google/inject/RecursiveLoadTest.java | 60 +++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 core/test/com/google/inject/RecursiveLoadTest.java diff --git a/core/test/com/google/inject/RecursiveLoadTest.java b/core/test/com/google/inject/RecursiveLoadTest.java new file mode 100644 index 0000000000..403d73616a --- /dev/null +++ b/core/test/com/google/inject/RecursiveLoadTest.java @@ -0,0 +1,60 @@ +/* + * Copyright (C) 2020 Google Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.google.inject; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.JUnit4; + +@RunWith(JUnit4.class) +public final class RecursiveLoadTest { + /** + * This test uses failed optional bindings to trigger a recursive load crash. + * https://github.com/google/guice/issues/785 + */ + @Test public void recursiveLoad() { + Guice.createInjector(new AbstractModule() { + @Override protected void configure() { + bind(A.class); + } + }); + } + + static class A { + @Inject B b; + } + + static class B { + @Inject C c; + } + + static class C { + @Inject(optional = true) D d; + @Inject E e; + } + + static class D { + @Inject B b; + @Inject Unresolved unresolved; + } + + static class E { + @Inject B b; + } + + interface Unresolved { + } +}