This is an automated email from the ASF dual-hosted git repository. ggregory pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/commons-compress.git
commit 610a7ee73be270809ab51bbaa0c0a40ac3471341 Author: Gary Gregory <garydgreg...@gmail.com> AuthorDate: Mon Feb 12 12:44:03 2024 -0500 Preserve exception causation in ExtraFieldUtils.register(Class) Simplify internal exception handling --- src/changes/changes.xml | 1 + .../compress/archivers/zip/ExtraFieldUtils.java | 19 +++---------------- 2 files changed, 4 insertions(+), 16 deletions(-) diff --git a/src/changes/changes.xml b/src/changes/changes.xml index f1549c52a..8f2600f15 100644 --- a/src/changes/changes.xml +++ b/src/changes/changes.xml @@ -78,6 +78,7 @@ The <action> type attribute can be add,update,fix,remove. <action type="fix" dev="ggregory" due-to="Zbynek Vyskovsky, Gary Gregory">Support preamble garbage in ZipArchiveInputStream #471.</action> <action type="fix" issue="COMPRESS-658" dev="ggregory" due-to="Arnout Engelen">Fix formatting the lowest expressable DOS time #472.</action> <action type="fix" dev="ggregory" due-to="Romain Manni-Bucau, Gary Gregory">Drop reflection from ExtraFieldUtils static initialization #480.</action> + <action type="fix" dev="ggregory" due-to="Gary Gregory">Preserve exception causation in ExtraFieldUtils.register(Class).</action> <!-- ADD --> <action type="add" dev="ggregory" due-to="Gary Gregory">Add and use ZipFile.builder(), ZipFile.Builder, and deprecate constructors.</action> <action type="add" dev="ggregory" due-to="Gary Gregory">Add and use SevenZFile.builder(), SevenZFile.Builder, and deprecate constructors.</action> diff --git a/src/main/java/org/apache/commons/compress/archivers/zip/ExtraFieldUtils.java b/src/main/java/org/apache/commons/compress/archivers/zip/ExtraFieldUtils.java index 7278d2a4d..a51237439 100644 --- a/src/main/java/org/apache/commons/compress/archivers/zip/ExtraFieldUtils.java +++ b/src/main/java/org/apache/commons/compress/archivers/zip/ExtraFieldUtils.java @@ -17,7 +17,6 @@ package org.apache.commons.compress.archivers.zip; import java.lang.reflect.Constructor; -import java.lang.reflect.InvocationTargetException; import java.util.ArrayList; import java.util.List; import java.util.Objects; @@ -385,24 +384,12 @@ public class ExtraFieldUtils { IMPLEMENTATIONS.put(zef.getHeaderId(), () -> { try { return constructor.newInstance(); - } catch (final InstantiationException | IllegalAccessException e) { - throw new IllegalStateException(e); - } catch (final InvocationTargetException e) { - final Throwable cause = e.getTargetException(); - if (cause instanceof RuntimeException) { - throw (RuntimeException) cause; - } - throw new IllegalStateException(cause); + } catch (final ReflectiveOperationException e) { + throw new IllegalStateException(clazz.toString(), e); } }); - } catch (final ClassCastException cc) { // NOSONAR - throw new IllegalArgumentException(clazz + " doesn't implement ZipExtraField"); // NOSONAR - } catch (final InstantiationException ie) { // NOSONAR - throw new IllegalArgumentException(clazz + " is not a concrete class"); // NOSONAR - } catch (final IllegalAccessException ie) { // NOSONAR - throw new IllegalArgumentException(clazz + "'s no-arg constructor is not public"); // NOSONAR } catch (final ReflectiveOperationException e) { - throw new IllegalArgumentException(clazz + ": " + e); // NOSONAR + throw new IllegalArgumentException(clazz.toString(), e); } } }