Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in / Register
Toggle navigation
S
spring-boot
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
DEMO
spring-boot
Commits
678e1257
Commit
678e1257
authored
May 11, 2018
by
Andy Wilkinson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Polish "Unwrap InvocationTargetException in isLogConfigurationMessage"
Closes gh-12958
parent
2953ed1d
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
17 additions
and
28 deletions
+17
-28
SpringBootExceptionHandler.java
.../org/springframework/boot/SpringBootExceptionHandler.java
+1
-2
SpringBootExceptionHandlerTests.java
...springframework/boot/SpringBootExceptionHandlerTests.java
+16
-26
No files found.
spring-boot/src/main/java/org/springframework/boot/SpringBootExceptionHandler.java
View file @
678e1257
/*
/*
* Copyright 2012-201
6
the original author or authors.
* Copyright 2012-201
8
the original author or authors.
*
*
* Licensed under the Apache License, Version 2.0 (the "License");
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* you may not use this file except in compliance with the License.
...
@@ -89,7 +89,6 @@ class SpringBootExceptionHandler implements UncaughtExceptionHandler {
...
@@ -89,7 +89,6 @@ class SpringBootExceptionHandler implements UncaughtExceptionHandler {
if
(
ex
instanceof
InvocationTargetException
)
{
if
(
ex
instanceof
InvocationTargetException
)
{
return
isLogConfigurationMessage
(
ex
.
getCause
());
return
isLogConfigurationMessage
(
ex
.
getCause
());
}
}
String
message
=
ex
.
getMessage
();
String
message
=
ex
.
getMessage
();
if
(
message
!=
null
)
{
if
(
message
!=
null
)
{
for
(
String
candidate
:
LOG_CONFIGURATION_MESSAGES
)
{
for
(
String
candidate
:
LOG_CONFIGURATION_MESSAGES
)
{
...
...
spring-boot/src/test/java/org/springframework/boot/SpringBootExceptionHandlerTest.java
→
spring-boot/src/test/java/org/springframework/boot/SpringBootExceptionHandlerTest
s
.java
View file @
678e1257
...
@@ -16,17 +16,13 @@
...
@@ -16,17 +16,13 @@
package
org
.
springframework
.
boot
;
package
org
.
springframework
.
boot
;
import
java.lang.Thread.UncaughtExceptionHandler
;
import
java.lang.reflect.InvocationTargetException
;
import
java.lang.reflect.InvocationTargetException
;
import
org.junit.Rule
;
import
org.junit.Test
;
import
org.junit.Test
;
import
org.mockito.InjectMocks
;
import
org.mockito.Mock
;
import
org.mockito.junit.MockitoJUnit
;
import
org.mockito.junit.MockitoRule
;
import
static
org
.
mockito
.
Matchers
.
same
;
import
static
org
.
mockito
.
ArgumentMatchers
.
same
;
import
static
org
.
mockito
.
Mockito
.
mock
;
import
static
org
.
mockito
.
Mockito
.
verify
;
import
static
org
.
mockito
.
Mockito
.
verify
;
import
static
org
.
mockito
.
Mockito
.
verifyZeroInteractions
;
import
static
org
.
mockito
.
Mockito
.
verifyZeroInteractions
;
...
@@ -34,48 +30,42 @@ import static org.mockito.Mockito.verifyZeroInteractions;
...
@@ -34,48 +30,42 @@ import static org.mockito.Mockito.verifyZeroInteractions;
* Tests for {@link SpringBootExceptionHandler}.
* Tests for {@link SpringBootExceptionHandler}.
*
*
* @author Henri Tremblay
* @author Henri Tremblay
* @author Andy Wilkinson
*/
*/
public
class
SpringBootExceptionHandlerTest
{
public
class
SpringBootExceptionHandlerTests
{
@Rule
public
MockitoRule
rule
=
MockitoJUnit
.
rule
();
@Mock
private
final
UncaughtExceptionHandler
parent
=
mock
(
UncaughtExceptionHandler
.
class
);
private
Thread
.
UncaughtExceptionHandler
parent
;
@InjectMocks
private
final
SpringBootExceptionHandler
handler
=
new
SpringBootExceptionHandler
(
private
SpringBootExceptionHandler
handler
;
this
.
parent
)
;
@Test
@Test
public
void
uncaughtException
_should
NotForwardLoggedErrorToParent
()
{
public
void
uncaughtException
Does
NotForwardLoggedErrorToParent
()
{
Thread
thread
=
Thread
.
currentThread
();
Thread
thread
=
Thread
.
currentThread
();
Exception
ex
=
new
Exception
();
Exception
ex
=
new
Exception
();
this
.
handler
.
registerLoggedException
(
ex
);
this
.
handler
.
registerLoggedException
(
ex
);
this
.
handler
.
uncaughtException
(
thread
,
ex
);
this
.
handler
.
uncaughtException
(
thread
,
ex
);
verifyZeroInteractions
(
this
.
parent
);
verifyZeroInteractions
(
this
.
parent
);
}
}
@Test
@Test
public
void
uncaughtException
_shouldForward
LogConfigurationErrorToParent
()
{
public
void
uncaughtException
Forwards
LogConfigurationErrorToParent
()
{
Thread
thread
=
Thread
.
currentThread
();
Thread
thread
=
Thread
.
currentThread
();
Exception
ex
=
new
Exception
(
"[stuff] Logback configuration error detected [stuff]"
);
Exception
ex
=
new
Exception
(
"[stuff] Logback configuration error detected [stuff]"
);
this
.
handler
.
registerLoggedException
(
ex
);
this
.
handler
.
registerLoggedException
(
ex
);
this
.
handler
.
uncaughtException
(
thread
,
ex
);
this
.
handler
.
uncaughtException
(
thread
,
ex
);
verify
(
this
.
parent
).
uncaughtException
(
same
(
thread
),
same
(
ex
));
verify
(
this
.
parent
).
uncaughtException
(
same
(
thread
),
same
(
ex
));
}
}
@Test
@Test
public
void
uncaughtException
_shouldForwardLogConfigurationErrorToParentEvenWhenWrapped
()
{
public
void
uncaughtException
ForwardsWrappedLogConfigurationErrorToParent
()
{
Thread
thread
=
Thread
.
currentThread
();
Thread
thread
=
Thread
.
currentThread
();
Exception
ex
=
new
InvocationTargetException
(
new
Exception
(
"[stuff] Logback configuration error detected [stuff]"
,
new
Exception
()));
Exception
ex
=
new
InvocationTargetException
(
new
Exception
(
"[stuff] Logback configuration error detected [stuff]"
,
new
Exception
()));
this
.
handler
.
registerLoggedException
(
ex
);
this
.
handler
.
registerLoggedException
(
ex
);
this
.
handler
.
uncaughtException
(
thread
,
ex
);
this
.
handler
.
uncaughtException
(
thread
,
ex
);
verify
(
this
.
parent
).
uncaughtException
(
same
(
thread
),
same
(
ex
));
verify
(
this
.
parent
).
uncaughtException
(
same
(
thread
),
same
(
ex
));
}
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment