>From 55d4e2cfe928b23a4cd8107cf6e1afafa7c9809a Mon Sep 17 00:00:00 2001
From: Abhishek Koneru <akoneru@redhat.com>
Date: Tue, 5 Jun 2012 12:16:51 -0400
Subject: [PATCH] Fixes for NULL_RETURN cases review comments

---
 base/ca/src/com/netscape/ca/CRLIssuingPoint.java   |   38 ++++++++++----------
 .../src/com/netscape/certsrv/util/StatsEvent.java  |    6 +---
 .../netscape/cmscore/ldap/LdapPredicateParser.java |   16 ++++-----
 .../cmscore/policy/PolicyPredicateParser.java      |   16 ++++-----
 .../netscape/cmscore/security/CertificateInfo.java |    8 ++---
 5 files changed, 39 insertions(+), 45 deletions(-)

diff --git a/base/ca/src/com/netscape/ca/CRLIssuingPoint.java b/base/ca/src/com/netscape/ca/CRLIssuingPoint.java
index 56dcc24570110a54878b685ee00661e9175833d1..5dd823737ac116bfbc10958ddf7d83a892a0e479 100755
--- a/base/ca/src/com/netscape/ca/CRLIssuingPoint.java
+++ b/base/ca/src/com/netscape/ca/CRLIssuingPoint.java
@@ -1694,23 +1694,24 @@ public class CRLIssuingPoint implements ICRLIssuingPoint, Runnable {
      * <P>
      */
     public void run() {
-        while (mEnable && ((mEnableCRLCache && mCacheUpdateInterval > 0) ||
-                           (mInitialized == CRL_IP_NOT_INITIALIZED) ||
-                            mDoLastAutoUpdate || (mEnableCRLUpdates &&
+        try {
+            while (mEnable && ((mEnableCRLCache && mCacheUpdateInterval > 0) ||
+                    (mInitialized == CRL_IP_NOT_INITIALIZED) ||
+                    mDoLastAutoUpdate || (mEnableCRLUpdates &&
+                    ((mEnableDailyUpdates && mDailyUpdates != null &&
+                            mTimeListSize > 0) ||
+                            (mEnableUpdateFreq && mAutoUpdateInterval > 0) ||
+                    mDoManualUpdate)))) {
+
+                synchronized (this) {
+                    long delay = 0;
+                    long delay2 = 0;
+                    boolean doCacheUpdate = false;
+                    boolean scheduledUpdates = mEnableCRLUpdates &&
                             ((mEnableDailyUpdates && mDailyUpdates != null &&
-                                    mTimeListSize > 0) ||
-                                    (mEnableUpdateFreq && mAutoUpdateInterval > 0) ||
-                              mDoManualUpdate)))) {
+                            mTimeListSize > 0) ||
+                            (mEnableUpdateFreq && mAutoUpdateInterval > 0));
 
-            synchronized (this) {
-                long delay = 0;
-                long delay2 = 0;
-                boolean doCacheUpdate = false;
-                boolean scheduledUpdates = mEnableCRLUpdates &&
-                        ((mEnableDailyUpdates && mDailyUpdates != null &&
-                        mTimeListSize > 0) ||
-                        (mEnableUpdateFreq && mAutoUpdateInterval > 0));
-                try {
                     if (mInitialized == CRL_IP_NOT_INITIALIZED)
                         initCRL();
 
@@ -1766,11 +1767,12 @@ public class CRLIssuingPoint implements ICRLIssuingPoint, Runnable {
                             mSignatureAlgorithmForManualUpdate = null;
                         }
                     }
-                } catch (EBaseException e1) {
-                    // TODO Auto-generated catch block
-                    e1.printStackTrace();
+
                 }
             }
+        } catch (EBaseException e1) {
+            // TODO Auto-generated catch block
+            e1.printStackTrace();
         }
         mUpdateThread = null;
     }
diff --git a/base/common/src/com/netscape/certsrv/util/StatsEvent.java b/base/common/src/com/netscape/certsrv/util/StatsEvent.java
index c431a3908cd7e6d102287c265d3741b4a4020c00..4137aa3b2198cd9bd7d836f9da6fb14a43ca82d8 100755
--- a/base/common/src/com/netscape/certsrv/util/StatsEvent.java
+++ b/base/common/src/com/netscape/certsrv/util/StatsEvent.java
@@ -63,9 +63,7 @@ public class StatsEvent {
      */
     public Enumeration<String> getSubEventNames() {
         Vector<String> names = new Vector<String>();
-        for (String s : mSubEvents.keySet()) {
-            names.add(s);
-        }
+        names.addAll(mSubEvents.keySet());
         return names.elements();
     }
 
@@ -83,9 +81,7 @@ public class StatsEvent {
         mTimeTaken = 0;
         mTimeTakenSqSum = 0;
         for (StatsEvent c : mSubEvents.values()) {
-            if (c != null) {
                 c.resetCounters();
-            }
         }
     }
 
diff --git a/base/common/src/com/netscape/cmscore/ldap/LdapPredicateParser.java b/base/common/src/com/netscape/cmscore/ldap/LdapPredicateParser.java
index 71f88989592717e8868019ec870466817907ab77..8c2b730d57f900a283d81bd2c012f4a1caf02d39 100755
--- a/base/common/src/com/netscape/cmscore/ldap/LdapPredicateParser.java
+++ b/base/common/src/com/netscape/cmscore/ldap/LdapPredicateParser.java
@@ -326,15 +326,13 @@ class PredicateTokenizer {
                 Debug.trace("Malformed expression: Null Token");
             throw new ELdapException(CMS.getUserMessage("CMS_LDAP_BAD_LDAP_EXPRESSION"));
         }
-        if (toReturn == null)
-            return null;
-        else {
-            String trimmed = toReturn.trim();
 
-            if (trimmed == null || trimmed.length() == 0)
-                return nextToken();
-            else
-                return trimmed;
-        }
+        String trimmed = toReturn.trim();
+
+        if (trimmed.length() == 0)
+            return nextToken();
+        else
+            return trimmed;
+
     }
 }
diff --git a/base/common/src/com/netscape/cmscore/policy/PolicyPredicateParser.java b/base/common/src/com/netscape/cmscore/policy/PolicyPredicateParser.java
index 579d9ff5b48d16855ebfec35479450bbc1e679cb..09316ceffb9e405f762cf6c33d95f9db89083ffe 100755
--- a/base/common/src/com/netscape/cmscore/policy/PolicyPredicateParser.java
+++ b/base/common/src/com/netscape/cmscore/policy/PolicyPredicateParser.java
@@ -329,15 +329,13 @@ class PredicateTokenizer {
                 Debug.trace("Malformed Predicate Expression : No Tokens");
             throw new EPolicyException("Malformed Predicate Expression : No Tokens");
         }
-        if (toReturn == null)
-            return null;
-        else {
-            String trimmed = toReturn.trim();
 
-            if (trimmed == null || trimmed.length() == 0)
-                return nextToken();
-            else
-                return trimmed;
-        }
+        String trimmed = toReturn.trim();
+
+        if (trimmed.length() == 0)
+            return nextToken();
+        else
+            return trimmed;
+
     }
 }
diff --git a/base/common/src/com/netscape/cmscore/security/CertificateInfo.java b/base/common/src/com/netscape/cmscore/security/CertificateInfo.java
index 040abc3c29659a6ad4ce3c8e03161cb7afee094c..fef733a11ae7eb279fdb50bc00b715bed767b027 100755
--- a/base/common/src/com/netscape/cmscore/security/CertificateInfo.java
+++ b/base/common/src/com/netscape/cmscore/security/CertificateInfo.java
@@ -187,10 +187,10 @@ public abstract class CertificateInfo {
 
             if (algm == null) {
                 String hashtype = (String) mProperties.get(ConfigConstants.PR_HASH_TYPE);
-
-                algm = KeyCertUtil.getSigningAlgorithm(getKeyAlgorithm(), hashtype);
+                String key = getKeyAlgorithm();
+                algm = KeyCertUtil.getSigningAlgorithm(key, hashtype);
                 if (algm == null) {
-                    throw new NoSuchAlgorithmException();
+                    throw new NoSuchAlgorithmException("No Algorithm for Key : " + key + " and Hashtype : " + hashtype);
                 }
                 mProperties.put(Constants.PR_SIGNATURE_ALGORITHM, algm);
             }
@@ -212,7 +212,7 @@ public abstract class CertificateInfo {
         } catch (IOException e) {
             throw new EBaseException(CMS.getUserMessage("CMS_BASE_INVALID_CERT", e.toString()));
         } catch (NoSuchAlgorithmException e) {
-            throw new EBaseException(CMS.getUserMessage("CMS_BASE_ALG_NOT_SUPPORTED", ""));
+            throw new EBaseException(CMS.getUserMessage("CMS_BASE_ALG_NOT_SUPPORTED", e.toString()));
         }
 
         return certInfo;
-- 
1.7.10.2

