mirror of
https://github.com/AuthMe/AuthMeReloaded.git
synced 2024-11-18 08:15:12 +01:00
Avoid setting field with reflection on a JDK class - fails on newer JDK versions
This commit is contained in:
parent
2e3448ab58
commit
db04fd2a5b
@ -40,10 +40,10 @@ public class ExceptionUtilsTest {
|
||||
@Test
|
||||
public void shouldHandleCircularCausesGracefully() {
|
||||
// given
|
||||
IllegalStateException ise = new IllegalStateException();
|
||||
UnsupportedOperationException uoe = new UnsupportedOperationException(ise);
|
||||
ExceptionWithSettableCause exceptionWithSettableCause = new ExceptionWithSettableCause();
|
||||
UnsupportedOperationException uoe = new UnsupportedOperationException(exceptionWithSettableCause);
|
||||
ReflectiveOperationException roe = new ReflectiveOperationException(uoe);
|
||||
ReflectionTestUtils.setField(Throwable.class, ise, "cause", roe);
|
||||
exceptionWithSettableCause.cause = roe;
|
||||
|
||||
// when
|
||||
NullPointerException resultNpe = ExceptionUtils.findThrowableInCause(NullPointerException.class, uoe);
|
||||
@ -65,4 +65,14 @@ public class ExceptionUtilsTest {
|
||||
// then
|
||||
assertThat(result, equalTo("[MalformedURLException]: Unrecognized URL format"));
|
||||
}
|
||||
|
||||
private static final class ExceptionWithSettableCause extends Exception {
|
||||
|
||||
Exception cause;
|
||||
|
||||
@Override
|
||||
public synchronized Throwable getCause() {
|
||||
return cause;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user