Apache Solr open-source search software
LUCENE-4747: Remove reflection from IOUtils for supressing caughth Exceptions
Uwe Schindlerb2404a4c550a
diff --git a/lucene/core/src/java/org/apache/lucene/util/IOUtils.java b/lucene/core/src/java/org/apache/lucene/util/IOUtils.javaindex 83522dcb87e..61b1277fc31 100644--- a/lucene/core/src/java/org/apache/lucene/util/IOUtils.java+++ b/lucene/core/src/java/org/apache/lucene/util/IOUtils.java@@ -222,29 +222,13 @@ public final class IOUtils {}}- /** This reflected {@link Method} is {@code null} before Java 7 */- private static final Method SUPPRESS_METHOD;- static {- Method m;- try {- m = Throwable.class.getMethod("addSuppressed", Throwable.class);- } catch (Exception e) {- m = null;- }- SUPPRESS_METHOD = m;- }-- /** adds a Throwable to the list of suppressed Exceptions of the first Throwable (if Java 7 is detected)+ /** adds a Throwable to the list of suppressed Exceptions of the first Throwable* @param exception this exception should get the suppressed one added* @param suppressed the suppressed exception*/private static final void addSuppressed(Throwable exception, Throwable suppressed) {- if (SUPPRESS_METHOD != null && exception != null && suppressed != null) {- try {- SUPPRESS_METHOD.invoke(exception, suppressed);- } catch (Exception e) {- // ignore any exceptions caused by invoking (e.g. security constraints)- }+ if (exception != null && suppressed != null) {+ exception.addSuppressed(suppressed);}}diff --git a/lucene/core/src/test/org/apache/lucene/util/TestIOUtils.java b/lucene/core/src/test/org/apache/lucene/util/TestIOUtils.javaindex d825f4fd531..16114b6ded9 100644--- a/lucene/core/src/test/org/apache/lucene/util/TestIOUtils.java+++ b/lucene/core/src/test/org/apache/lucene/util/TestIOUtils.java@@ -44,10 +44,6 @@ public class TestIOUtils extends LuceneTestCase {}public void testSuppressedExceptions() {- if (!Constants.JRE_IS_MINIMUM_JAVA7) {- System.err.println("WARNING: TestIOUtils.testSuppressedExceptions: Full test coverage only with Java 7, as suppressed exception recording is not supported before.");- }-// test with prior exceptiontry {final TestException t = new TestException();