You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tika.apache.org by ju...@apache.org on 2010/02/18 16:58:06 UTC

svn commit: r911457 - /lucene/tika/trunk/tika-core/src/main/java/org/apache/tika/config/TikaConfig.java

Author: jukka
Date: Thu Feb 18 15:58:06 2010
New Revision: 911457

URL: http://svn.apache.org/viewvc?rev=911457&view=rev
Log:
TIKA-378: TikaConfig should notify users if it cannot initialize some parser

Throw TikaExceptions when unable to load parser classes. This is a less likely scenario now that the main parser classes all can be loaded even when the required external dependencies are not present, thus any load problems are more likely caused by invalid configuration instead of deployment decisions.

Note that this change reverts the TIKA-217 solution. This should be fine especially since we no longer try to support Java 1.4.

Modified:
    lucene/tika/trunk/tika-core/src/main/java/org/apache/tika/config/TikaConfig.java

Modified: lucene/tika/trunk/tika-core/src/main/java/org/apache/tika/config/TikaConfig.java
URL: http://svn.apache.org/viewvc/lucene/tika/trunk/tika-core/src/main/java/org/apache/tika/config/TikaConfig.java?rev=911457&r1=911456&r2=911457&view=diff
==============================================================================
--- lucene/tika/trunk/tika-core/src/main/java/org/apache/tika/config/TikaConfig.java (original)
+++ lucene/tika/trunk/tika-core/src/main/java/org/apache/tika/config/TikaConfig.java Thu Feb 18 15:58:06 2010
@@ -108,9 +108,15 @@
         for (int i = 0; i < nodes.getLength(); i++) {
             Element node = (Element) nodes.item(i);
             String name = node.getAttribute("class");
+
             try {
                 Class<?> parserClass = Class.forName(name);
-                Parser parser = (Parser) parserClass.newInstance();
+                Object instance = parserClass.newInstance();
+                if (!(instance instanceof Parser)) {
+                    throw new TikaException(
+                            "Configured class is not a Tika Parser: " + name);
+                }
+                Parser parser = (Parser) instance;
 
                 NodeList mimes = node.getElementsByTagName("mime");
                 if (mimes.getLength() > 0) {
@@ -123,9 +129,15 @@
                         parsers.put(type.toString(), parser);
                     }
                 }
-            } catch (Throwable t) {
-                // TODO: Log warning about an invalid parser configuration
-                // For now we just ignore this parser class
+            } catch (ClassNotFoundException e) {
+                throw new TikaException(
+                        "Configured parser class not found: " + name, e);
+            } catch (IllegalAccessException e) {
+                throw new TikaException(
+                        "Unable to access a parser class: " + name, e);
+            } catch (InstantiationException e) {
+                throw new TikaException(
+                        "Unable to instantiate a parser class: " + name, e);
             }
         }
     }