This commit is contained in:
Phillip Webb
2017-07-27 16:00:08 -07:00
parent eac4c7e882
commit a869d25dbb
17 changed files with 566 additions and 573 deletions

View File

@@ -292,20 +292,13 @@ abstract class AbstractApplicationContextRunner<SELF extends AbstractApplication
consumer.accept(context);
}
catch (Throwable ex) {
AnyThrow.throwUnchecked(ex);
rethrow(ex);
}
}
private static class AnyThrow {
static void throwUnchecked(Throwable e) {
AnyThrow.throwAny(e);
}
@SuppressWarnings("unchecked")
private static <E extends Throwable> void throwAny(Throwable e) throws E {
throw (E) e;
}
@SuppressWarnings("unchecked")
private <E extends Throwable> void rethrow(Throwable e) throws E {
throw (E) e;
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2016 the original author or authors.
* Copyright 2012-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.

View File

@@ -130,11 +130,16 @@ public final class TestPropertyValues {
return call.call();
}
catch (Exception ex) {
AnyThrow.throwUnchecked(ex);
return null; // never reached
rethrow(ex);
throw new IllegalStateException("Original cause not rethrown", ex);
}
}
@SuppressWarnings("unchecked")
private <E extends Throwable> void rethrow(Throwable e) throws E {
throw (E) e;
}
@SuppressWarnings("unchecked")
private void addToSources(MutablePropertySources sources, Type type, String name) {
if (sources.contains(name)) {
@@ -310,16 +315,4 @@ public final class TestPropertyValues {
}
private static class AnyThrow {
static void throwUnchecked(Throwable e) {
AnyThrow.throwAny(e);
}
@SuppressWarnings("unchecked")
private static <E extends Throwable> void throwAny(Throwable e) throws E {
throw (E) e;
}
}
}

View File

@@ -153,7 +153,8 @@ public abstract class AbstractApplicationContextRunnerTests<T extends AbstractAp
new HidePackagesClassLoader(Gson.class.getPackage().getName()))
.run((context) -> {
try {
ClassUtils.forName(Gson.class.getName(), context.getClassLoader());
ClassUtils.forName(Gson.class.getName(),
context.getClassLoader());
fail("Should have thrown a ClassNotFoundException");
}
catch (ClassNotFoundException e) {