From 44c3a631600b23773ca58345bde0bc586def3ccc Mon Sep 17 00:00:00 2001 From: Sakthi Date: Mon, 3 Jun 2019 22:47:27 -0700 Subject: [PATCH] HBASE-22536 TestForeignExceptionSerialization fails when run on JDK11 Signed-off-by: Sean Busbey (cherry picked from commit 2280c8f4a88350278447515deb0811c42d0bb476) --- .../TestForeignExceptionSerialization.java | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/errorhandling/TestForeignExceptionSerialization.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/errorhandling/TestForeignExceptionSerialization.java index 127e72f88dd..6b6ef0c430d 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/errorhandling/TestForeignExceptionSerialization.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/errorhandling/TestForeignExceptionSerialization.java @@ -17,12 +17,13 @@ */ package org.apache.hadoop.hbase.errorhandling; -import static org.junit.Assert.assertArrayEquals; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; import java.io.IOException; +import java.util.Objects; + import org.apache.hadoop.hbase.HBaseClassTestRule; import org.apache.hadoop.hbase.testclassification.MasterTests; import org.apache.hadoop.hbase.testclassification.SmallTests; @@ -75,7 +76,15 @@ public class TestForeignExceptionSerialization { assertTrue(generic.getMessage().contains(errorMsg)); ForeignException e = ForeignException.deserialize(ForeignException.serialize(srcName, generic)); - assertArrayEquals("Local stack trace got corrupted", generic.getStackTrace(), e.getCause().getStackTrace()); + + // Workaround for java 11 - replaced assertArrayEquals with individual elements comparison + // using custom comparison helper method + assertEquals("Stacktrace lengths don't match", generic.getStackTrace().length, + e.getCause().getStackTrace().length); + for (int i = 0; i < generic.getStackTrace().length; i++) { + assertTrue("Local stack trace got corrupted at " + i + "th index", + compareStackTraceElement(generic.getStackTrace()[i], e.getCause().getStackTrace()[i])); + } e.printStackTrace(); // should have ForeignException and source node in it. assertTrue(e.getCause().getCause() == null); @@ -84,4 +93,10 @@ public class TestForeignExceptionSerialization { assertTrue(e.getCause().getMessage().contains(errorMsg)); } + // Helper method to compare two stackTraceElements + private boolean compareStackTraceElement(StackTraceElement obj1, StackTraceElement obj2) { + return obj1.getClassName().equals(obj2.getClassName()) && obj1.getLineNumber() == obj2 + .getLineNumber() && Objects.equals(obj1.getMethodName(), obj2.getMethodName()) && Objects + .equals(obj1.getFileName(), obj2.getFileName()); + } }