Skip to content

Commit b0fe032

Browse files
committed
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). #785
1 parent a689de7 commit b0fe032

File tree

1 file changed

+60
-0
lines changed

1 file changed

+60
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
/*
2+
* Copyright (C) 2020 Google Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package com.google.inject;
17+
18+
import org.junit.Test;
19+
import org.junit.runner.RunWith;
20+
import org.junit.runners.JUnit4;
21+
22+
@RunWith(JUnit4.class)
23+
public final class RecursiveLoadTest {
24+
/**
25+
* This test uses failed optional bindings to trigger a recursive load crash.
26+
* https://github.com/google/guice/issues/785
27+
*/
28+
@Test public void recursiveLoad() {
29+
Guice.createInjector(new AbstractModule() {
30+
@Override protected void configure() {
31+
bind(A.class);
32+
}
33+
});
34+
}
35+
36+
static class A {
37+
@Inject B b;
38+
}
39+
40+
static class B {
41+
@Inject C c;
42+
}
43+
44+
static class C {
45+
@Inject(optional = true) D d;
46+
@Inject E e;
47+
}
48+
49+
static class D {
50+
@Inject B b;
51+
@Inject Unresolved unresolved;
52+
}
53+
54+
static class E {
55+
@Inject B b;
56+
}
57+
58+
interface Unresolved {
59+
}
60+
}

0 commit comments

Comments
 (0)