Skip to content

Commit 8bcd1ba

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). google#785
1 parent 4a66eb4 commit 8bcd1ba

File tree

1 file changed

+92
-0
lines changed

1 file changed

+92
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
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.Ignore;
19+
import org.junit.Test;
20+
import org.junit.runner.RunWith;
21+
import org.junit.runners.JUnit4;
22+
23+
@RunWith(JUnit4.class)
24+
public final class RecursiveLoadTest {
25+
/**
26+
* This test uses failed optional bindings to trigger a recursive load crash.
27+
* https://github.com/google/guice/issues/785
28+
*/
29+
@Ignore
30+
@Test public void recursiveLoadWithOptionals() {
31+
Guice.createInjector(new AbstractModule() {
32+
@Override protected void configure() {
33+
bind(A.class);
34+
}
35+
});
36+
}
37+
38+
static class A {
39+
@Inject B b;
40+
}
41+
42+
static class B {
43+
@Inject C c;
44+
}
45+
46+
static class C {
47+
@Inject(optional = true) D d;
48+
@Inject E e;
49+
}
50+
51+
static class D {
52+
@Inject B b;
53+
@Inject Unresolved unresolved;
54+
}
55+
56+
static class E {
57+
@Inject B b;
58+
}
59+
60+
@Ignore
61+
@Test public void recursiveLoadWithoutOptionals() {
62+
Guice.createInjector(new AbstractModule() {
63+
@Provides public V provideV(Z z) {
64+
return null;
65+
}
66+
});
67+
}
68+
69+
static class V {
70+
}
71+
72+
static class X {
73+
@Inject Z z;
74+
}
75+
76+
static class Z {
77+
@Inject W w;
78+
@Inject X x;
79+
}
80+
81+
static class W {
82+
@Inject Y y;
83+
@Inject Z z;
84+
}
85+
86+
static class Y {
87+
@Inject Unresolved unresolved;
88+
}
89+
90+
interface Unresolved {
91+
}
92+
}

0 commit comments

Comments
 (0)