You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tika.apache.org by ta...@apache.org on 2021/04/15 15:57:07 UTC

[tika] branch main updated: Fix up exception handling for invalid config (#426)

This is an automated email from the ASF dual-hosted git repository.

tallison pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/tika.git


The following commit(s) were added to refs/heads/main by this push:
     new d2340c7  Fix up exception handling for invalid config (#426)
d2340c7 is described below

commit d2340c751d2bfc32e5b73f5a26ca49b3f247f042
Author: Peter Kronenberg <pa...@gmail.com>
AuthorDate: Thu Apr 15 11:56:58 2021 -0400

    Fix up exception handling for invalid config (#426)
    
    Co-authored-by: Peter Kronenberg <pe...@torch.ai>
---
 .../src/main/java/org/apache/tika/utils/AnnotationUtils.java   | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/tika-core/src/main/java/org/apache/tika/utils/AnnotationUtils.java b/tika-core/src/main/java/org/apache/tika/utils/AnnotationUtils.java
index c544772..dfdaef2 100644
--- a/tika-core/src/main/java/org/apache/tika/utils/AnnotationUtils.java
+++ b/tika-core/src/main/java/org/apache/tika/utils/AnnotationUtils.java
@@ -18,6 +18,7 @@ package org.apache.tika.utils;
 
 import java.lang.annotation.Annotation;
 import java.lang.reflect.AccessibleObject;
+import java.lang.reflect.InvocationTargetException;
 import java.security.AccessController;
 import java.security.PrivilegedAction;
 import java.util.ArrayList;
@@ -120,12 +121,17 @@ public class AnnotationUtils {
                 if (field.getType().isAssignableFrom(param.getType())) {
                     try {
                         field.assignValue(bean, param.getValue());
-                    } catch (Exception e) {
+                    } catch (InvocationTargetException e) {
+                        LOG.error("Error assigning value '{}' to '{}'", param.getValue(), param.getName());
+                        final Throwable cause = e.getCause() == null ? e : e.getCause();
+                        throw new TikaConfigException(cause.getMessage(), cause);
+                    } catch (IllegalAccessException e) {
+                        LOG.error("Error assigning value '{}' to '{}'", param.getValue(), param.getName());
                         throw new TikaConfigException(e.getMessage(), e);
                     }
                 } else {
                     String msg = String.format(Locale.ROOT,
-                            "Value '%s' of type '%s' cant be" +
+                            "Value '%s' of type '%s' can't be" +
                                     " assigned to field '%s' of defined type '%s'",
                             param.getValue(),
                             param.getValue().getClass(), field.getName(), field.getType());