Skip to content

Commit

Permalink
Test that crashes Guice inside Guava
Browse files Browse the repository at this point in the history
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
  • Loading branch information
swankjesse committed Sep 1, 2020
1 parent a689de7 commit b0fe032
Showing 1 changed file with 60 additions and 0 deletions.
60 changes: 60 additions & 0 deletions core/test/com/google/inject/RecursiveLoadTest.java
Original file line number Diff line number Diff line change
@@ -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 {
}
}

0 comments on commit b0fe032

Please sign in to comment.