Repository: oodt
Updated Branches:
  refs/heads/master ed5228286 -> 2fca19286


remove known null checks


Project: http://git-wip-us.apache.org/repos/asf/oodt/repo
Commit: http://git-wip-us.apache.org/repos/asf/oodt/commit/b7a48e0e
Tree: http://git-wip-us.apache.org/repos/asf/oodt/tree/b7a48e0e
Diff: http://git-wip-us.apache.org/repos/asf/oodt/diff/b7a48e0e

Branch: refs/heads/master
Commit: b7a48e0eb72a28f8616f0dc21d77929831d2d81e
Parents: 0c67a33
Author: Tom Barber <[email protected]>
Authored: Fri Oct 30 09:18:53 2015 +0000
Committer: Tom Barber <[email protected]>
Committed: Fri Oct 30 09:18:53 2015 +0000

----------------------------------------------------------------------
 .../org/apache/oodt/commons/io/LogWriter.java   |  5 +----
 .../org/apache/oodt/commons/util/JDBC_DB.java   | 10 +---------
 .../org/apache/oodt/commons/xml/XMLUtils.java   |  2 +-
 .../cas/curation/service/PolicyResource.java    | 21 +++++++++++---------
 .../oodt/cas/filemgr/catalog/LuceneCatalog.java | 21 ++------------------
 .../main/java/org/apache/oodt/grid/Server.java  |  6 ------
 .../apache/oodt/pcs/tools/PCSHealthMonitor.java |  4 ++--
 .../apache/oodt/pcs/input/PGEXMLFileUtils.java  | 12 +++++------
 .../apache/oodt/cas/pge/PGETaskInstance.java    | 17 +++++++---------
 .../parsers/DirStructXmlParser.java             |  7 -------
 .../cli/action/GetNodeByIdCliAction.java        |  4 ----
 .../repository/XMLWorkflowRepository.java       |  4 ----
 .../apache/oodt/cas/workflow/structs/Graph.java |  4 ++--
 .../cas/workflow/util/XmlStructFactory.java     |  5 +----
 14 files changed, 35 insertions(+), 87 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/oodt/blob/b7a48e0e/commons/src/main/java/org/apache/oodt/commons/io/LogWriter.java
----------------------------------------------------------------------
diff --git a/commons/src/main/java/org/apache/oodt/commons/io/LogWriter.java 
b/commons/src/main/java/org/apache/oodt/commons/io/LogWriter.java
index da60933..6dc1439 100644
--- a/commons/src/main/java/org/apache/oodt/commons/io/LogWriter.java
+++ b/commons/src/main/java/org/apache/oodt/commons/io/LogWriter.java
@@ -316,14 +316,11 @@ public class LogWriter extends java.io.Writer {
                        println("Null throwable");
                else {
                        StackTraceElement[] frames = t.getStackTrace();
-                       if (frames == null)
-                               println("Null stack trace in " + 
t.getClass().getName());
-                       else {
                                println(t.getClass().getName() + ":");
                          for (StackTraceElement frame : frames) {
                                println(frame);
                          }
-                       }
+
                }
        }
 

http://git-wip-us.apache.org/repos/asf/oodt/blob/b7a48e0e/commons/src/main/java/org/apache/oodt/commons/util/JDBC_DB.java
----------------------------------------------------------------------
diff --git a/commons/src/main/java/org/apache/oodt/commons/util/JDBC_DB.java 
b/commons/src/main/java/org/apache/oodt/commons/util/JDBC_DB.java
index d9ecebe..890eac7 100644
--- a/commons/src/main/java/org/apache/oodt/commons/util/JDBC_DB.java
+++ b/commons/src/main/java/org/apache/oodt/commons/util/JDBC_DB.java
@@ -274,10 +274,7 @@ public class JDBC_DB
                //time = System.currentTimeMillis();
                //System.err.println("###### Executing the query: " + (time - 
time0));
 
-               if (rs == null)
-               {
-                       return(null);
-               }
+
 
                return(rs);
 
@@ -307,11 +304,6 @@ public class JDBC_DB
 
                rs = stmt.executeQuery(sql_command);
 
-               if (rs == null)
-               {
-                       return(0);
-               }
-
                count = 0;
 
                while (rs.next())

http://git-wip-us.apache.org/repos/asf/oodt/blob/b7a48e0e/commons/src/main/java/org/apache/oodt/commons/xml/XMLUtils.java
----------------------------------------------------------------------
diff --git a/commons/src/main/java/org/apache/oodt/commons/xml/XMLUtils.java 
b/commons/src/main/java/org/apache/oodt/commons/xml/XMLUtils.java
index b48eade..466b374 100644
--- a/commons/src/main/java/org/apache/oodt/commons/xml/XMLUtils.java
+++ b/commons/src/main/java/org/apache/oodt/commons/xml/XMLUtils.java
@@ -137,7 +137,7 @@ public class XMLUtils {
 
     public static Element getFirstElement(String name, Element root) {
         NodeList list = root.getElementsByTagName(name);
-        if (list != null) {
+        if (list.getLength()>0) {
             return (Element) list.item(0);
         } else
             return null;

http://git-wip-us.apache.org/repos/asf/oodt/blob/b7a48e0e/curator/services/src/main/java/org/apache/oodt/cas/curation/service/PolicyResource.java
----------------------------------------------------------------------
diff --git 
a/curator/services/src/main/java/org/apache/oodt/cas/curation/service/PolicyResource.java
 
b/curator/services/src/main/java/org/apache/oodt/cas/curation/service/PolicyResource.java
index b0e0f53..596e612 100644
--- 
a/curator/services/src/main/java/org/apache/oodt/cas/curation/service/PolicyResource.java
+++ 
b/curator/services/src/main/java/org/apache/oodt/cas/curation/service/PolicyResource.java
@@ -19,8 +19,6 @@
 package org.apache.oodt.cas.curation.service;
 
 //OODT imports
-import net.sf.json.JSONObject;
-
 import org.apache.commons.lang.StringEscapeUtils;
 import org.apache.oodt.cas.filemgr.repository.XMLRepositoryManager;
 import org.apache.oodt.cas.filemgr.structs.Product;
@@ -29,18 +27,28 @@ import org.apache.oodt.cas.filemgr.structs.ProductType;
 import org.apache.oodt.cas.filemgr.structs.Query;
 import 
org.apache.oodt.cas.filemgr.structs.exceptions.RepositoryManagerException;
 
+import net.sf.json.JSONObject;
+
 import java.io.File;
 import java.io.FilenameFilter;
 import java.io.IOException;
 import java.net.MalformedURLException;
-import java.util.*;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Vector;
 import java.util.logging.Level;
 import java.util.logging.Logger;
 
 import javax.servlet.ServletContext;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
-import javax.ws.rs.*;
+import javax.ws.rs.DefaultValue;
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.Produces;
+import javax.ws.rs.QueryParam;
 import javax.ws.rs.core.Context;
 import javax.ws.rs.core.UriInfo;
 
@@ -89,11 +97,6 @@ public class PolicyResource extends CurationService {
     String policy;
     String productType;
 
-    if (pathToks == null) {
-      LOG.log(Level.WARNING, "malformed path token string: "
-          + Arrays.asList(pathToks));
-      return "";
-    }
 
     policy = pathToks.length > 0 ? pathToks[0]:null;
     productType = pathToks.length > 1 ? pathToks[1] : null;

http://git-wip-us.apache.org/repos/asf/oodt/blob/b7a48e0e/filemgr/src/main/java/org/apache/oodt/cas/filemgr/catalog/LuceneCatalog.java
----------------------------------------------------------------------
diff --git 
a/filemgr/src/main/java/org/apache/oodt/cas/filemgr/catalog/LuceneCatalog.java 
b/filemgr/src/main/java/org/apache/oodt/cas/filemgr/catalog/LuceneCatalog.java
index a3cfc72..f439c4e 100644
--- 
a/filemgr/src/main/java/org/apache/oodt/cas/filemgr/catalog/LuceneCatalog.java
+++ 
b/filemgr/src/main/java/org/apache/oodt/cas/filemgr/catalog/LuceneCatalog.java
@@ -142,11 +142,7 @@ public class LuceneCatalog implements Catalog {
                removeProduct(product);                 
         }
         
-        if (p == null) {
-            throw new CatalogException("Product ["+ product.getProductName()
-                                            + "] not found either in local 
cache or in index");
-
-        } else {
+        if (p != null) {
             p.setMetadata(m);
             if (hasMetadataAndRefs(p)) {
                 LOG.log(Level.FINE,
@@ -176,15 +172,6 @@ public class LuceneCatalog implements Catalog {
             removeProductDocument(product);
         }
 
-        if (p == null) {
-            // not in index
-            throw new CatalogException(
-                    "Attempt to remove metadata to a product: ["
-                            + product.getProductName()
-                            + "] that isn't in the index or the local cache!");
-
-        }
-
         Metadata currMet = p.getMetadata();
         List<String> metadataTypes = new ArrayList<String>();
 
@@ -328,11 +315,7 @@ public class LuceneCatalog implements Catalog {
                removeProduct(product);                 
         }
         
-        if (p == null) {
-            throw new CatalogException("Product ["+ product.getProductName()
-                                            + "] not found either in local 
cache or in index");
- 
-        } else {
+        if (p != null) {
             
p.getProduct().setProductReferences(product.getProductReferences());
             if (hasMetadataAndRefs(p)) {
                 LOG.log(Level.FINE,

http://git-wip-us.apache.org/repos/asf/oodt/blob/b7a48e0e/grid/src/main/java/org/apache/oodt/grid/Server.java
----------------------------------------------------------------------
diff --git a/grid/src/main/java/org/apache/oodt/grid/Server.java 
b/grid/src/main/java/org/apache/oodt/grid/Server.java
index 3babd2e..e4299a6 100755
--- a/grid/src/main/java/org/apache/oodt/grid/Server.java
+++ b/grid/src/main/java/org/apache/oodt/grid/Server.java
@@ -142,14 +142,8 @@ public abstract class Server implements Serializable {
   public static Server create(Configuration configuration, Element elem)
       throws SAXException {
     String type = elem.getAttribute("type");
-    if (type == null)
-      throw new SAXException("type attribute missing from <"
-          + elem.getNodeName() + ">");
 
     String className = elem.getAttribute("className");
-    if (className == null)
-      throw new SAXException("className attribute missing from <"
-          + elem.getNodeName() + ">");
 
     // Replace with a factory some day...
     if ("product".equals(type))

http://git-wip-us.apache.org/repos/asf/oodt/blob/b7a48e0e/pcs/core/src/main/java/org/apache/oodt/pcs/tools/PCSHealthMonitor.java
----------------------------------------------------------------------
diff --git 
a/pcs/core/src/main/java/org/apache/oodt/pcs/tools/PCSHealthMonitor.java 
b/pcs/core/src/main/java/org/apache/oodt/pcs/tools/PCSHealthMonitor.java
index 743994e..bfea4b4 100644
--- a/pcs/core/src/main/java/org/apache/oodt/pcs/tools/PCSHealthMonitor.java
+++ b/pcs/core/src/main/java/org/apache/oodt/pcs/tools/PCSHealthMonitor.java
@@ -325,7 +325,7 @@ public final class PCSHealthMonitor implements CoreMetKeys,
   }
 
   private List getIngestHealth() {
-    if (this.crawlProps.getCrawlers() == null) {
+    if (this.crawlProps.getCrawlers().size()==0) {
       return new Vector();
     }
 
@@ -529,7 +529,7 @@ public final class PCSHealthMonitor implements CoreMetKeys,
   }
 
   private void quickPrintIngestStatusHealth() {
-    if (this.crawlProps.getCrawlers() == null) {
+    if (this.crawlProps.getCrawlers().size()==0) {
       return;
     }
 

http://git-wip-us.apache.org/repos/asf/oodt/blob/b7a48e0e/pcs/input/src/main/java/org/apache/oodt/pcs/input/PGEXMLFileUtils.java
----------------------------------------------------------------------
diff --git 
a/pcs/input/src/main/java/org/apache/oodt/pcs/input/PGEXMLFileUtils.java 
b/pcs/input/src/main/java/org/apache/oodt/pcs/input/PGEXMLFileUtils.java
index b4d412b..0168d93 100644
--- a/pcs/input/src/main/java/org/apache/oodt/pcs/input/PGEXMLFileUtils.java
+++ b/pcs/input/src/main/java/org/apache/oodt/pcs/input/PGEXMLFileUtils.java
@@ -58,7 +58,7 @@ public final class PGEXMLFileUtils {
     NodeList matrixs = group.getElementsByTagName("matrix");
 
     // if it's null, return null
-    if (matrixs == null) {
+    if (matrixs.getLength()==0) {
       return null;
     }
 
@@ -122,7 +122,7 @@ public final class PGEXMLFileUtils {
     NodeList matrixs = group.getElementsByTagName("matrix");
 
     // if it's null, return null
-    if (matrixs == null) {
+    if (matrixs.getLength()==0) {
       return null;
     }
 
@@ -187,7 +187,7 @@ public final class PGEXMLFileUtils {
     NodeList scalars = group.getElementsByTagName("scalar");
 
     // if it's null, return null
-    if (scalars == null) {
+    if (scalars.getLength()==0) {
       return null;
     }
 
@@ -215,7 +215,7 @@ public final class PGEXMLFileUtils {
     NodeList scalars = group.getElementsByTagName("scalar");
 
     // if it's null, return null
-    if (scalars == null) {
+    if (scalars.getLength()==0) {
       return null;
     }
 
@@ -244,7 +244,7 @@ public final class PGEXMLFileUtils {
     NodeList vectors = group.getElementsByTagName("vector");
 
     // if it's null, return null
-    if (vectors == null) {
+    if (vectors.getLength()==0) {
       return null;
     }
 
@@ -288,7 +288,7 @@ public final class PGEXMLFileUtils {
     NodeList vectors = group.getElementsByTagName("vector");
 
     // if it's null, return null
-    if (vectors == null) {
+    if (vectors.getLength()==0) {
       return null;
     }
 

http://git-wip-us.apache.org/repos/asf/oodt/blob/b7a48e0e/pge/src/main/java/org/apache/oodt/cas/pge/PGETaskInstance.java
----------------------------------------------------------------------
diff --git a/pge/src/main/java/org/apache/oodt/cas/pge/PGETaskInstance.java 
b/pge/src/main/java/org/apache/oodt/cas/pge/PGETaskInstance.java
index 0dda943..bef0be2 100644
--- a/pge/src/main/java/org/apache/oodt/cas/pge/PGETaskInstance.java
+++ b/pge/src/main/java/org/apache/oodt/cas/pge/PGETaskInstance.java
@@ -16,10 +16,6 @@
  */
 package org.apache.oodt.cas.pge;
 
-import com.google.common.base.Splitter;
-import com.google.common.base.Strings;
-import com.google.common.collect.Lists;
-
 import org.apache.commons.lang.Validate;
 import org.apache.oodt.cas.crawl.AutoDetectProductCrawler;
 import org.apache.oodt.cas.crawl.ProductCrawler;
@@ -58,6 +54,11 @@ import org.apache.oodt.cas.workflow.util.ScriptFile;
 import org.apache.oodt.commons.exceptions.CommonsException;
 import org.apache.oodt.commons.exec.ExecUtils;
 import org.apache.xmlrpc.XmlRpcException;
+
+import com.google.common.base.Splitter;
+import com.google.common.base.Strings;
+import com.google.common.collect.Lists;
+
 import org.springframework.context.support.FileSystemXmlApplicationContext;
 
 import java.io.File;
@@ -423,13 +424,9 @@ public class PGETaskInstance implements 
WorkflowTaskInstance {
          pgeMetadata.replaceMetadata(PGE_RUNTIME, Long.toString(runTime));
 
       } catch (WorkflowException e) {
-        throw new PGEException("Exception when executing PGE commands '"
-                               + (sf != null ? sf.getCommands() : "NULL") + "' 
: "
-                               + e.getMessage(), e);
+        throw new PGEException("Exception when executing PGE commands '" + 
(sf.getCommands()) + "' : " + e.getMessage(), e);
       } catch (IOException e) {
-        throw new PGEException("Exception when executing PGE commands '"
-                               + (sf != null ? sf.getCommands() : "NULL") + "' 
: "
-                               + e.getMessage(), e);
+        throw new PGEException("Exception when executing PGE commands '" + 
(sf.getCommands()) + "' : " + e.getMessage(), e);
       }
    }
 

http://git-wip-us.apache.org/repos/asf/oodt/blob/b7a48e0e/pushpull/src/main/java/org/apache/oodt/cas/pushpull/filerestrictions/parsers/DirStructXmlParser.java
----------------------------------------------------------------------
diff --git 
a/pushpull/src/main/java/org/apache/oodt/cas/pushpull/filerestrictions/parsers/DirStructXmlParser.java
 
b/pushpull/src/main/java/org/apache/oodt/cas/pushpull/filerestrictions/parsers/DirStructXmlParser.java
index c1e8dc9..55836e6 100644
--- 
a/pushpull/src/main/java/org/apache/oodt/cas/pushpull/filerestrictions/parsers/DirStructXmlParser.java
+++ 
b/pushpull/src/main/java/org/apache/oodt/cas/pushpull/filerestrictions/parsers/DirStructXmlParser.java
@@ -18,7 +18,6 @@
 
 package org.apache.oodt.cas.pushpull.filerestrictions.parsers;
 
-//OODT imports
 import org.apache.oodt.cas.metadata.Metadata;
 import org.apache.oodt.cas.metadata.exceptions.CasMetadataException;
 import org.apache.oodt.cas.metadata.util.PathUtils;
@@ -45,7 +44,6 @@ import java.util.logging.Logger;
 
 import javax.xml.parsers.DocumentBuilderFactory;
 
-//JDK imports
 
 /**
  * 
@@ -81,7 +79,6 @@ public class DirStructXmlParser implements Parser {
                     // parse out starting path
                     String startingPath = ((Element) node)
                             .getAttribute("starting_path");
-                    if (startingPath != null) {
                         root = (currentFile = new VirtualFile(
                                 initialCdDir = startingPath, true))
                                 .getRootDir();
@@ -91,10 +88,6 @@ public class DirStructXmlParser implements Parser {
                             temp.setNoFiles(true);
                             temp = temp.getParentFile();
                         }
-                    } else {
-                        currentFile = root = VirtualFile.createRootDir();
-                    }
-
                     // parse the directory structure
                     parseDirstructXML(node.getChildNodes(), currentFile);
 

http://git-wip-us.apache.org/repos/asf/oodt/blob/b7a48e0e/resource/src/main/java/org/apache/oodt/cas/resource/cli/action/GetNodeByIdCliAction.java
----------------------------------------------------------------------
diff --git 
a/resource/src/main/java/org/apache/oodt/cas/resource/cli/action/GetNodeByIdCliAction.java
 
b/resource/src/main/java/org/apache/oodt/cas/resource/cli/action/GetNodeByIdCliAction.java
index 1fae3a3..32bfb2a 100644
--- 
a/resource/src/main/java/org/apache/oodt/cas/resource/cli/action/GetNodeByIdCliAction.java
+++ 
b/resource/src/main/java/org/apache/oodt/cas/resource/cli/action/GetNodeByIdCliAction.java
@@ -40,10 +40,6 @@ public class GetNodeByIdCliAction extends ResourceCliAction {
 
          ResourceNode node = getClient().getNodeById(nodeId);
 
-         if (node == null) {
-            throw new Exception("ResourceManager returned null ResourceNode"
-                  + " for nodeId '" + nodeId + "'");
-         }
          printer.println("node: [id=" + node.getNodeId() + ",capacity="
                + node.getCapacity() + ",url=" + node.getIpAddr() + "]");
       } catch (Exception e) {

http://git-wip-us.apache.org/repos/asf/oodt/blob/b7a48e0e/workflow/src/main/java/org/apache/oodt/cas/workflow/repository/XMLWorkflowRepository.java
----------------------------------------------------------------------
diff --git 
a/workflow/src/main/java/org/apache/oodt/cas/workflow/repository/XMLWorkflowRepository.java
 
b/workflow/src/main/java/org/apache/oodt/cas/workflow/repository/XMLWorkflowRepository.java
index f0eb8ee..354fcc3 100644
--- 
a/workflow/src/main/java/org/apache/oodt/cas/workflow/repository/XMLWorkflowRepository.java
+++ 
b/workflow/src/main/java/org/apache/oodt/cas/workflow/repository/XMLWorkflowRepository.java
@@ -367,7 +367,6 @@ public class XMLWorkflowRepository implements 
WorkflowRepository {
 
         List workflows = repo.getWorkflows();
 
-        if (workflows != null) {
           for (Object workflow : workflows) {
             Workflow w = (Workflow) workflow;
             System.out.println("Workflow: [id=" + w.getId() + ", name="
@@ -416,9 +415,6 @@ public class XMLWorkflowRepository implements 
WorkflowRepository {
             }
 
           }
-        } else {
-            System.out.println("No workflows defined!");
-        }
 
     }
 

http://git-wip-us.apache.org/repos/asf/oodt/blob/b7a48e0e/workflow/src/main/java/org/apache/oodt/cas/workflow/structs/Graph.java
----------------------------------------------------------------------
diff --git 
a/workflow/src/main/java/org/apache/oodt/cas/workflow/structs/Graph.java 
b/workflow/src/main/java/org/apache/oodt/cas/workflow/structs/Graph.java
index e8015c7..8daa2c2 100644
--- a/workflow/src/main/java/org/apache/oodt/cas/workflow/structs/Graph.java
+++ b/workflow/src/main/java/org/apache/oodt/cas/workflow/structs/Graph.java
@@ -102,7 +102,7 @@ public class Graph {
     }
 
     if ((graphElem.getNodeName().equals("workflow") || graphElem.getNodeName()
-        .equals("conditions")) && this.executionType == null) {
+        .equals("conditions")) && this.executionType.equals("")) {
       throw new WorkflowException("workflow model '" + graphElem.getNodeName()
           + "' missing execution type");
     } else {
@@ -113,7 +113,7 @@ public class Graph {
       throw new WorkflowException("Unsupported execution type id '"
           + this.executionType + "'");
 
-    if (!checkValue(this.modelId) && !checkValue(this.modelIdRef)) {
+    if (!checkValue(this.modelId) && !checkValue(this.modelIdRef)) {r
       this.modelId = UUID.randomUUID().toString();
     }
 

http://git-wip-us.apache.org/repos/asf/oodt/blob/b7a48e0e/workflow/src/main/java/org/apache/oodt/cas/workflow/util/XmlStructFactory.java
----------------------------------------------------------------------
diff --git 
a/workflow/src/main/java/org/apache/oodt/cas/workflow/util/XmlStructFactory.java
 
b/workflow/src/main/java/org/apache/oodt/cas/workflow/util/XmlStructFactory.java
index 0305b43..4216fef 100644
--- 
a/workflow/src/main/java/org/apache/oodt/cas/workflow/util/XmlStructFactory.java
+++ 
b/workflow/src/main/java/org/apache/oodt/cas/workflow/util/XmlStructFactory.java
@@ -213,9 +213,6 @@ public final class XmlStructFactory {
 
     NodeList configProperties = configNode.getElementsByTagName("property");
 
-    if (configProperties == null) {
-      return null;
-    }
 
     Properties properties = new Properties();
     for (int i = 0; i < configProperties.getLength(); i++) {
@@ -321,7 +318,7 @@ public final class XmlStructFactory {
 
   private static Element getFirstElement(String name, Element root) {
     NodeList list = root.getElementsByTagName(name);
-    if (list != null) {
+    if (list.getLength()>0) {
       return (Element) list.item(0);
     } else
       return null;

Reply via email to