You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tika.apache.org by ti...@apache.org on 2025/03/31 18:12:58 UTC

(tika) branch branch_2x updated: TIKA-4397: remove unneded null check; replace comparison with ""; use isempty()

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

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


The following commit(s) were added to refs/heads/branch_2x by this push:
     new f962046ad TIKA-4397: remove unneded null check; replace comparison with ""; use isempty()
f962046ad is described below

commit f962046adabef29616bce3eb15ecba750c2ada82
Author: Tilman Hausherr <ti...@apache.org>
AuthorDate: Mon Mar 31 20:12:13 2025 +0200

    TIKA-4397: remove unneded null check; replace comparison with ""; use isempty()
---
 .../java/org/apache/tika/config/TikaConfig.java    | 39 +++++++++++-----------
 1 file changed, 20 insertions(+), 19 deletions(-)

diff --git a/tika-core/src/main/java/org/apache/tika/config/TikaConfig.java b/tika-core/src/main/java/org/apache/tika/config/TikaConfig.java
index 895ff048f..d1057d54f 100644
--- a/tika-core/src/main/java/org/apache/tika/config/TikaConfig.java
+++ b/tika-core/src/main/java/org/apache/tika/config/TikaConfig.java
@@ -233,14 +233,14 @@ public class TikaConfig {
             LOG.debug("loading tika config from system property 'tika.config'");
         }
 
-        if (config == null || config.trim().equals("")) {
+        if (StringUtils.isBlank(config)) {
             config = System.getenv("TIKA_CONFIG");
             if (!StringUtils.isBlank(config)) {
                 LOG.debug("loading tika config from environment variable 'TIKA_CONFIG'");
             }
         }
 
-        if (config == null || config.trim().equals("")) {
+        if (StringUtils.isBlank(config)) {
             LOG.debug("loading tika config from defaults; no config file specified");
             this.serviceLoader = new ServiceLoader();
             this.mimeTypes = getDefaultMimeTypes(getContextClassLoader());
@@ -364,17 +364,18 @@ public class TikaConfig {
     }
 
     private static String getText(Node node) {
-        if (node.getNodeType() == Node.TEXT_NODE) {
-            return node.getNodeValue();
-        } else if (node.getNodeType() == Node.ELEMENT_NODE) {
-            StringBuilder builder = new StringBuilder();
-            NodeList list = node.getChildNodes();
-            for (int i = 0; i < list.getLength(); i++) {
-                builder.append(getText(list.item(i)));
-            }
-            return builder.toString();
-        } else {
-            return "";
+        switch (node.getNodeType()) {
+            case Node.TEXT_NODE:
+                return node.getNodeValue();
+            case Node.ELEMENT_NODE:
+                StringBuilder builder = new StringBuilder();
+                NodeList list = node.getChildNodes();
+                for (int i = 0; i < list.getLength(); i++) {
+                    builder.append(getText(list.item(i)));
+                }
+                return builder.toString();
+            default:
+                return "";
         }
     }
 
@@ -517,7 +518,7 @@ public class TikaConfig {
 
     private static InitializableProblemHandler getInitializableProblemHandler(
             String initializableProblemHandler) throws TikaConfigException {
-        if (initializableProblemHandler == null || initializableProblemHandler.length() == 0) {
+        if (initializableProblemHandler.isEmpty()) {
             return InitializableProblemHandler.DEFAULT;
         }
         if (InitializableProblemHandler.IGNORE.toString()
@@ -540,7 +541,7 @@ public class TikaConfig {
 
     public static void mustNotBeEmpty(String paramName, String paramValue)
             throws TikaConfigException {
-        if (paramValue == null || paramValue.trim().equals("")) {
+        if (StringUtils.isBlank(paramValue)) {
             throw new IllegalArgumentException(
                     "parameter '" + paramName + "' must be set in the config file");
         }
@@ -713,12 +714,12 @@ public class TikaConfig {
         T loadOne(Element element, MimeTypes mimeTypes, ServiceLoader loader)
                 throws TikaException, IOException {
             String name = element.getAttribute("class");
-            if (name == null) {
-                throw new TikaConfigException("class attribute must not be null: " + element);
+            if (name.isEmpty()) {
+                throw new TikaConfigException("class attribute must not be empty: " + element);
             }
             String initProbHandler = element.getAttribute("initializableProblemHandler");
             InitializableProblemHandler initializableProblemHandler;
-            if (initProbHandler == null || initProbHandler.length() == 0) {
+            if (initProbHandler.isEmpty()) {
                 initializableProblemHandler = loader.getInitializableProblemHandler();
             } else {
                 initializableProblemHandler = getInitializableProblemHandler(initProbHandler);
@@ -995,7 +996,7 @@ public class TikaConfig {
             if (parser == null && ParserDecorator.class.isAssignableFrom(parserClass)) {
                 try {
                     CompositeParser cp = null;
-                    if (childParsers.size() == 1 && excludeParsers.size() == 0 &&
+                    if (childParsers.size() == 1 && excludeParsers.isEmpty() &&
                             childParsers.get(0) instanceof CompositeParser) {
                         cp = (CompositeParser) childParsers.get(0);
                     } else {