Skip to content

Commit

Permalink
JDK 11 and earlier seem to print cyclic exceptions differetly than JD…
Browse files Browse the repository at this point in the history
…K 16. Adapt tests accordingly

Signed-off-by: Ceki Gulcu <ceki@qos.ch>
  • Loading branch information
ceki committed Aug 21, 2021
1 parent da6f556 commit 0aa3822
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import ch.qos.logback.classic.PatternLayout;
import ch.qos.logback.classic.spi.ILoggingEvent;
import ch.qos.logback.classic.spi.LoggingEvent;
import ch.qos.logback.core.util.EnvUtil;

public class ExtendedThrowableProxyConverterTest {

Expand Down Expand Up @@ -87,6 +88,12 @@ public void nested() {

@Test
public void cyclicCause() {
// the identical formatting check, see verify(e) call below, fails
// under JDK 11. this does not mean that the presently tested code is wrong
// but that JDK 11 formats things differently
if(!EnvUtil.isJDK16OrHigher())
return;

Exception e = new Exception("foo");
Exception e2 = new Exception(e);
e.initCause(e2);
Expand All @@ -95,6 +102,12 @@ public void cyclicCause() {

@Test
public void cyclicSuppressed() {
// the identical formatting check, see verify(e) call below, fails
// under JDK 11. this does not mean that the presently tested code is wrong
// but that JDK 11 formats things differently
if(!EnvUtil.isJDK16OrHigher())
return;

Exception e = new Exception("foo");
Exception e2 = new Exception(e);
e.addSuppressed(e2);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import ch.qos.logback.classic.spi.LoggingEvent;
import ch.qos.logback.classic.util.TestHelper;
import ch.qos.logback.core.CoreConstants;
import ch.qos.logback.core.util.EnvUtil;

public class ThrowableProxyConverterTest {

Expand Down Expand Up @@ -119,6 +120,9 @@ public void nested() {

@Test
public void cyclicCause() {
// Earlier JDKs may formats things differently
if(!EnvUtil.isJDK16OrHigher())
return;
Exception e = new Exception("foo");
Exception e2 = new Exception(e);
e.initCause(e2);
Expand All @@ -127,7 +131,11 @@ public void cyclicCause() {

@Test
public void cyclicSuppressed() {
Exception e = new Exception("foo");
// Earlier JDKs may formats things differently
if(!EnvUtil.isJDK16OrHigher())
return;

Exception e = new Exception("foo");
Exception e2 = new Exception(e);
e.addSuppressed(e2);
verify(e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
import org.junit.Before;
import org.junit.Test;

import ch.qos.logback.core.util.EnvUtil;

public class ThrowableProxyTest {

StringWriter sw = new StringWriter();
Expand Down Expand Up @@ -158,6 +160,9 @@ public void multiNested() {
// see also https://jira.qos.ch/browse/LOGBACK-1454
@Test
public void cyclicCause() {
// Earlier JDKs may formats things differently
if(!EnvUtil.isJDK16OrHigher())
return;
Exception e = new Exception("foo");
Exception e2 = new Exception(e);
e.initCause(e2);
Expand All @@ -167,6 +172,9 @@ public void cyclicCause() {
// see also https://jira.qos.ch/browse/LOGBACK-1454
@Test
public void cyclicSuppressed() {
// Earlier JDKs may formats things differently
if(!EnvUtil.isJDK16OrHigher())
return;
Exception e = new Exception("foo");
Exception e2 = new Exception(e);
e.addSuppressed(e2);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ static public boolean isJDK7OrHigher() {
return isJDK_N_OrHigher(7);
}

static public boolean isJDK16OrHigher() {
return isJDK_N_OrHigher(16);
}

static public boolean isJaninoAvailable() {
ClassLoader classLoader = EnvUtil.class.getClassLoader();
try {
Expand Down

0 comments on commit 0aa3822

Please sign in to comment.