Skip to content

Commit 39d7382

Browse files
committed
Merge branch '2.0.x'
2 parents 079b67c + 972d952 commit 39d7382

File tree

2 files changed

+74
-0
lines changed

2 files changed

+74
-0
lines changed

spring-boot-project/spring-boot/src/main/java/org/springframework/boot/SpringBootExceptionHandler.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,9 @@ private boolean isPassedToParent(Throwable ex) {
8686
* @return {@code true} if the exception contains a log configuration message
8787
*/
8888
private boolean isLogConfigurationMessage(Throwable ex) {
89+
if (ex instanceof InvocationTargetException) {
90+
return isLogConfigurationMessage(ex.getCause());
91+
}
8992
String message = ex.getMessage();
9093
if (message != null) {
9194
for (String candidate : LOG_CONFIGURATION_MESSAGES) {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
/*
2+
* Copyright 2012-2018 the original author or authors.
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+
17+
package org.springframework.boot;
18+
19+
import java.lang.Thread.UncaughtExceptionHandler;
20+
import java.lang.reflect.InvocationTargetException;
21+
22+
import org.junit.Test;
23+
24+
import static org.mockito.Matchers.same;
25+
import static org.mockito.Mockito.mock;
26+
import static org.mockito.Mockito.verify;
27+
import static org.mockito.Mockito.verifyZeroInteractions;
28+
29+
/**
30+
* Tests for {@link SpringBootExceptionHandler}.
31+
*
32+
* @author Henri Tremblay
33+
* @author Andy Wilkinson
34+
*/
35+
public class SpringBootExceptionHandlerTests {
36+
37+
private final UncaughtExceptionHandler parent = mock(UncaughtExceptionHandler.class);
38+
39+
private final SpringBootExceptionHandler handler = new SpringBootExceptionHandler(
40+
this.parent);
41+
42+
@Test
43+
public void uncaughtExceptionDoesNotForwardLoggedErrorToParent() {
44+
Thread thread = Thread.currentThread();
45+
Exception ex = new Exception();
46+
this.handler.registerLoggedException(ex);
47+
this.handler.uncaughtException(thread, ex);
48+
verifyZeroInteractions(this.parent);
49+
}
50+
51+
@Test
52+
public void uncaughtExceptionForwardsLogConfigurationErrorToParent() {
53+
Thread thread = Thread.currentThread();
54+
Exception ex = new Exception(
55+
"[stuff] Logback configuration error detected [stuff]");
56+
this.handler.registerLoggedException(ex);
57+
this.handler.uncaughtException(thread, ex);
58+
verify(this.parent).uncaughtException(same(thread), same(ex));
59+
}
60+
61+
@Test
62+
public void uncaughtExceptionForwardsWrappedLogConfigurationErrorToParent() {
63+
Thread thread = Thread.currentThread();
64+
Exception ex = new InvocationTargetException(new Exception(
65+
"[stuff] Logback configuration error detected [stuff]", new Exception()));
66+
this.handler.registerLoggedException(ex);
67+
this.handler.uncaughtException(thread, ex);
68+
verify(this.parent).uncaughtException(same(thread), same(ex));
69+
}
70+
71+
}

0 commit comments

Comments
 (0)