>From d3bc02bd6aef01670d5f853f4046e3dbac264ad2 Mon Sep 17 00:00:00 2001
From: Abhishek Koneru <akoneru@redhat.com>
Date: Sat, 2 Jun 2012 01:33:30 -0400
Subject: [PATCH] Fixes for review comments for NULL_RETURNS Coverity Issues

---
 base/ca/src/com/netscape/ca/CAService.java         |    2 +-
 base/ca/src/com/netscape/ca/CRLIssuingPoint.java   |  117 +++++++++++---------
 base/common/src/UserMessages.properties            |    3 +-
 .../src/com/netscape/certsrv/util/StatsEvent.java  |   33 +++---
 .../cmscore/cert/CrossCertPairSubsystem.java       |   18 +--
 .../netscape/cmscore/connector/HttpPKIMessage.java |    6 +-
 .../cmscore/connector/RequestTransfer.java         |   10 +-
 .../src/com/netscape/cmscore/dbs/DBRegistry.java   |   14 +--
 .../netscape/cmscore/ldap/LdapPredicateParser.java |   17 +--
 .../netscape/cmscore/ldap/PublisherProcessor.java  |   71 +++++-------
 .../com/netscape/cmscore/logging/LogSubsystem.java |    5 +-
 .../cmscore/policy/PolicyPredicateParser.java      |   21 ++--
 .../netscape/cmscore/security/CertificateInfo.java |    5 +-
 .../com/netscape/cmscore/usrgrp/UGSubsystem.java   |   73 ++----------
 .../src/com/netscape/kra/EnrollmentService.java    |    4 +-
 .../src/com/netscape/cmsutil/http/HttpMessage.java |    8 +-
 .../netscape/security/util/PrettyPrintFormat.java  |    9 +-
 .../netscape/security/x509/KeyUsageExtension.java  |    9 +-
 18 files changed, 173 insertions(+), 252 deletions(-)

diff --git a/base/ca/src/com/netscape/ca/CAService.java b/base/ca/src/com/netscape/ca/CAService.java
index 5fb749b5e61a41fb87a105b670dac3f358364487..12011ced4f85507dd769d71ae411db556dd6f515 100755
--- a/base/ca/src/com/netscape/ca/CAService.java
+++ b/base/ca/src/com/netscape/ca/CAService.java
@@ -1501,7 +1501,7 @@ class getCertsForChallenge implements IServant {
         BigInteger[] serialNoArray =
                 request.getExtDataInBigIntegerArray(CAService.SERIALNO_ARRAY);
         if (serialNoArray == null) {
-            throw new EBaseException("No Serial Numbers for fetching the certificates");
+            throw new ECAException(CMS.getLogMessage("CMS_CA_MISSING_SERIAL_NUMBER"));
         }
         X509CertImpl[] certs = new X509CertImpl[serialNoArray.length];
 
diff --git a/base/ca/src/com/netscape/ca/CRLIssuingPoint.java b/base/ca/src/com/netscape/ca/CRLIssuingPoint.java
index 3f7dfc8d1157b3d2c695b4f66c93c04ab570bda6..56dcc24570110a54878b685ee00661e9175833d1 100755
--- a/base/ca/src/com/netscape/ca/CRLIssuingPoint.java
+++ b/base/ca/src/com/netscape/ca/CRLIssuingPoint.java
@@ -756,8 +756,9 @@ public class CRLIssuingPoint implements ICRLIssuingPoint, Runnable {
      * Initializes CRL cache and republishes CRL if requested
      * Called from auto update thread (run()).
      * Do not call it from init(), because it will block CMS on start.
+     * @throws EBaseException
      */
-    private void initCRL() {
+    private void initCRL() throws EBaseException {
         ICRLIssuingPointRecord crlRecord = null;
 
         mLastCacheUpdate = System.currentTimeMillis() + mCacheUpdateInterval;
@@ -1709,60 +1710,65 @@ public class CRLIssuingPoint implements ICRLIssuingPoint, Runnable {
                         ((mEnableDailyUpdates && mDailyUpdates != null &&
                         mTimeListSize > 0) ||
                         (mEnableUpdateFreq && mAutoUpdateInterval > 0));
+                try {
+                    if (mInitialized == CRL_IP_NOT_INITIALIZED)
+                        initCRL();
 
-                if (mInitialized == CRL_IP_NOT_INITIALIZED)
-                    initCRL();
-                if (mInitialized == CRL_IP_INITIALIZED && (!mEnable))
-                    break;
+                    if (mInitialized == CRL_IP_INITIALIZED && (!mEnable))
+                        break;
 
-                if ((mEnableCRLUpdates && mDoManualUpdate) || mDoLastAutoUpdate) {
-                    delay = 0;
-                } else if (scheduledUpdates) {
-                    delay = findNextUpdate(true, false);
-                }
+                    if ((mEnableCRLUpdates && mDoManualUpdate) || mDoLastAutoUpdate) {
+                        delay = 0;
+                    } else if (scheduledUpdates) {
+                        delay = findNextUpdate(true, false);
+                    }
 
-                if (mEnableCRLCache && mCacheUpdateInterval > 0) {
-                    delay2 = mLastCacheUpdate + mCacheUpdateInterval -
-                             System.currentTimeMillis();
-                    if (delay2 < delay ||
-                            (!(scheduledUpdates || mDoLastAutoUpdate ||
-                            (mEnableCRLUpdates && mDoManualUpdate)))) {
-                        delay = delay2;
-                        if (delay <= 0) {
-                            doCacheUpdate = true;
-                            mLastCacheUpdate = System.currentTimeMillis();
+                    if (mEnableCRLCache && mCacheUpdateInterval > 0) {
+                        delay2 = mLastCacheUpdate + mCacheUpdateInterval -
+                                System.currentTimeMillis();
+                        if (delay2 < delay ||
+                                (!(scheduledUpdates || mDoLastAutoUpdate ||
+                                (mEnableCRLUpdates && mDoManualUpdate)))) {
+                            delay = delay2;
+                            if (delay <= 0) {
+                                doCacheUpdate = true;
+                                mLastCacheUpdate = System.currentTimeMillis();
+                            }
                         }
                     }
-                }
 
-                if (delay > 0) {
-                    try {
-                        wait(delay);
-                    } catch (InterruptedException e) {
-                    }
-                } else {
-                    try {
-                        if (doCacheUpdate) {
-                            updateCRLCacheRepository();
-                        } else if (mAutoUpdateInterval > 0 || mDoLastAutoUpdate || mDoManualUpdate) {
-                            updateCRL();
+                    if (delay > 0) {
+                        try {
+                            wait(delay);
+                        } catch (InterruptedException e) {
                         }
-                    } catch (Exception e) {
-                        log(ILogger.LL_FAILURE, CMS.getLogMessage("CMSCORE_CA_ISSUING_CRL",
-                                (doCacheUpdate) ? "update CRL cache" : "update CRL", e.toString()));
-                        if (Debug.on()) {
-                            Debug.trace((doCacheUpdate) ? "update CRL cache" : "update CRL" + " error " + e);
-                            Debug.printStackTrace(e);
+                    } else {
+                        try {
+                            if (doCacheUpdate) {
+                                updateCRLCacheRepository();
+                            } else if (mAutoUpdateInterval > 0 || mDoLastAutoUpdate || mDoManualUpdate) {
+                                updateCRL();
+                            }
+                        } catch (Exception e) {
+                            log(ILogger.LL_FAILURE, CMS.getLogMessage("CMSCORE_CA_ISSUING_CRL",
+                                    (doCacheUpdate) ? "update CRL cache" : "update CRL", e.toString()));
+                            if (Debug.on()) {
+                                Debug.trace((doCacheUpdate) ? "update CRL cache" : "update CRL" + " error " + e);
+                                Debug.printStackTrace(e);
+                            }
+                        }
+                        // put this here to prevent continuous loop if internal
+                        // db is down.
+                        if (mDoLastAutoUpdate)
+                            mDoLastAutoUpdate = false;
+                        if (mDoManualUpdate) {
+                            mDoManualUpdate = false;
+                            mSignatureAlgorithmForManualUpdate = null;
                         }
                     }
-                    // put this here to prevent continuous loop if internal
-                    // db is down.
-                    if (mDoLastAutoUpdate)
-                        mDoLastAutoUpdate = false;
-                    if (mDoManualUpdate) {
-                        mDoManualUpdate = false;
-                        mSignatureAlgorithmForManualUpdate = null;
-                    }
+                } catch (EBaseException e1) {
+                    // TODO Auto-generated catch block
+                    e1.printStackTrace();
                 }
             }
         }
@@ -1886,8 +1892,9 @@ public class CRLIssuingPoint implements ICRLIssuingPoint, Runnable {
 
     /**
      * recovers CRL cache
+     * @throws EBaseException
      */
-    private void recoverCRLCache() {
+    private void recoverCRLCache() throws EBaseException {
         if (mEnableCacheRecovery) {
             // 553815 - original filter was not aligned with any VLV index
             // String filter = "(&(requeststate=complete)"+
@@ -1943,22 +1950,24 @@ public class CRLIssuingPoint implements ICRLIssuingPoint, Runnable {
                             Debug.trace("Revocation Request : Revoked Certificates is a Null or has Invalid Values");
                         }
                         log(ILogger.LL_FAILURE, "Revoked Certificates is a Null or has Invalid Values");
+                        throw new EBaseException("Revocation Request : Revoked Certificates is a Null or has Invalid Values");
                     }
                 } else if (IRequest.UNREVOCATION_REQUEST.equals(request.getRequestType())) {
                     BigInteger serialNo[] = request.getExtDataInBigIntegerArray(IRequest.OLD_SERIALS);
-                    if(serialNo !=null){
-                    for (int j = 0; j < serialNo.length; j++) {
-                        if (Debug.on()) {
-                            Debug.trace("recoverCRLCache U j=" + j + "  length=" + serialNo.length +
+                    if (serialNo != null) {
+                        for (int j = 0; j < serialNo.length; j++) {
+                            if (Debug.on()) {
+                                Debug.trace("recoverCRLCache U j=" + j + "  length=" + serialNo.length +
                                         "  SerialNumber=0x" + serialNo[j].toString(16));
+                            }
+                            updateRevokedCert(UNREVOKED_CERT, serialNo[j], null);
                         }
-                        updateRevokedCert(UNREVOKED_CERT, serialNo[j], null);
-                    }
-                    }else{
+                    } else {
                         if (Debug.on()) {
                             Debug.trace("Unrevocation Request : Serial Numbers is a Null or has Invalid Values");
                         }
                         log(ILogger.LL_FAILURE, "Unrevocation Request : Serial Numbers is a Null or has Invalid Values");
+                        throw new EBaseException("Unrevocation Request : Serial Numbers is a Null or has Invalid Values");
                     }
                 }
             }
diff --git a/base/common/src/UserMessages.properties b/base/common/src/UserMessages.properties
index 1c78c98ce32a2831d75d08c550f9393e10fa145d..694c31d6513b0ada39bd96227fbc00f9c472a68f 100755
--- a/base/common/src/UserMessages.properties
+++ b/base/common/src/UserMessages.properties
@@ -50,7 +50,7 @@ CMS_INVALID_OPERATION=Invalid operation
 #  ProcessCertReq servlet
 #  ProcessReq servelt
 #######################################################
-CMS_BASE_CERT_NOT_FOUND=Certificate not found
+CMS_BASE_CERT_NOT_FOUND=Certificate not found or invalid
 CMS_BASE_ENCODE_CERT_FAILED=Failed to encode certificate
 CMS_BASE_NOT_TOKEN_CERT=The certificate being deleted is not a token certificate
 CMS_BASE_CERT_ERROR=Certificate Error: {0}
@@ -459,6 +459,7 @@ CMS_DBS_SETBACK_MAXSERIAL=The serial number is already in use.\nYou can only set
 CMS_DBS_LDIF_FAILED=Failed to create ldif file: {0}
 CMS_DBS_COPY_LDIF_FAILED=Failed to copy ldif file: {0}
 CMS_DBS_RECORD_NOT_FOUND=Record not found
+CMS_DBS_MISSING_OBJECT_CLASS=Missing Object Class
 #######################################################
 # Jobs
 #
diff --git a/base/common/src/com/netscape/certsrv/util/StatsEvent.java b/base/common/src/com/netscape/certsrv/util/StatsEvent.java
index 44f209c2c586ed963adb9e49b591d5e5faf49e07..bc48820c7d6f81a14250716b25e485de793210f7 100755
--- a/base/common/src/com/netscape/certsrv/util/StatsEvent.java
+++ b/base/common/src/com/netscape/certsrv/util/StatsEvent.java
@@ -18,6 +18,8 @@
 package com.netscape.certsrv.util;
 
 import java.util.Enumeration;
+import java.util.HashMap;
+import java.util.Map;
 import java.util.Vector;
 
 /**
@@ -34,7 +36,7 @@ public class StatsEvent {
     private long mTimeTaken = 0;
     private long mTimeTakenSqSum = 0;
     private long mNoOfOperations = 0;
-    private Vector<StatsEvent> mSubEvents = new Vector<StatsEvent>();
+    private Map<String,StatsEvent> mSubEvents = new HashMap<String,StatsEvent>();
     private StatsEvent mParent = null;
 
     public StatsEvent(StatsEvent parent) {
@@ -53,19 +55,15 @@ public class StatsEvent {
     }
 
     public void addSubEvent(StatsEvent st) {
-        mSubEvents.addElement(st);
+        mSubEvents.put(st.getName(), st);
     }
 
     /**
      * Retrieves a list of sub transaction names.
      */
     public Enumeration<String> getSubEventNames() {
-        Vector<String> names = new Vector<String>();
-        Enumeration<StatsEvent> e = mSubEvents.elements();
-        while (e.hasMoreElements()) {
-            StatsEvent st = e.nextElement();
-            names.addElement(st.getName());
-        }
+        @SuppressWarnings("unchecked")
+        Vector<String> names = (Vector<String>) mSubEvents.keySet();
         return names.elements();
     }
 
@@ -73,14 +71,7 @@ public class StatsEvent {
      * Retrieves a sub transaction.
      */
     public StatsEvent getSubEvent(String name) {
-        Enumeration<StatsEvent> e = mSubEvents.elements();
-        while (e.hasMoreElements()) {
-            StatsEvent st = e.nextElement();
-            if (st.getName().equals(name)) {
-                return st;
-            }
-        }
-        return null;
+        return mSubEvents.get(name);
     }
 
     public void resetCounters() {
@@ -89,13 +80,19 @@ public class StatsEvent {
         mNoOfOperations = 0;
         mTimeTaken = 0;
         mTimeTakenSqSum = 0;
-        Enumeration<String> e = getSubEventNames();
+        for (Map.Entry<String, StatsEvent> s : mSubEvents.entrySet()) {
+            StatsEvent c = s.getValue();
+            if (c != null) {
+                c.resetCounters();
+            }
+        }
+       /* Enumeration<String> e = getSubEventNames();
         while (e.hasMoreElements()) {
             String n = e.nextElement();
             StatsEvent c = getSubEvent(n);
             if (c != null)
                 c.resetCounters();
-        }
+        }*/
     }
 
     public long getMax() {
diff --git a/base/common/src/com/netscape/cmscore/cert/CrossCertPairSubsystem.java b/base/common/src/com/netscape/cmscore/cert/CrossCertPairSubsystem.java
index ff14f07611a32727ed11a0285b2da2675f198914..dd7918bd561015ff360a7c498d04e30f61b1227f 100755
--- a/base/common/src/com/netscape/cmscore/cert/CrossCertPairSubsystem.java
+++ b/base/common/src/com/netscape/cmscore/cert/CrossCertPairSubsystem.java
@@ -188,9 +188,6 @@ public class CrossCertPairSubsystem implements ICrossCertPairSubsystem {
 
         try {
             conn = getConn();
-            if (conn == null) {
-                throw new LDAPException("No LDAP Connection Available");
-            }
             LDAPSearchResults res = conn.search(mBaseDN, LDAPv2.SCOPE_SUB,
                     DN_XCERTS, null, false);
 
@@ -402,9 +399,6 @@ public class CrossCertPairSubsystem implements ICrossCertPairSubsystem {
 
         try {
             conn = getConn();
-            if (conn == null) {
-                throw new LDAPException("No LDAP Connection Available");
-            }
             // search in internal db for xcerts
             LDAPSearchResults res = conn.search(mBaseDN, LDAPv2.SCOPE_SUB,
                     DN_XCERTS, null, false);
@@ -460,10 +454,16 @@ public class CrossCertPairSubsystem implements ICrossCertPairSubsystem {
     }
 
     protected LDAPConnection getConn() throws ELdapException {
-        if (mLdapConnFactory != null)
-            return mLdapConnFactory.getConn();
+        if (mLdapConnFactory != null) {
+            LDAPConnection conn = mLdapConnFactory.getConn();
+            if (conn == null) {
+                throw new ELdapException("No Ldap Connection Available");
+            } else {
+                return conn;
+            }
+        }
 
-        return null;
+        throw new ELdapException("Ldap Connection Factory is null");
     }
 
     protected void returnConn(LDAPConnection conn) throws ELdapException {
diff --git a/base/common/src/com/netscape/cmscore/connector/HttpPKIMessage.java b/base/common/src/com/netscape/cmscore/connector/HttpPKIMessage.java
index 220a527eeb9a8ea6d1fc806290a7435c249b128e..4b35662fa063178b1d1eadff17bfc3b421a0af19 100755
--- a/base/common/src/com/netscape/cmscore/connector/HttpPKIMessage.java
+++ b/base/common/src/com/netscape/cmscore/connector/HttpPKIMessage.java
@@ -73,14 +73,10 @@ public class HttpPKIMessage implements IHttpPKIMessage {
                 + r.getRequestId().toString() + " requestStatus=" + reqStatus + " instance=" + r);
 
         String attrs[] = RequestTransfer.getTransferAttributes(r);
-        int len = 0;
-        if (attrs != null)
-            len = attrs.length;
-
         String[] names = attrs;
         Object value = null;
 
-        for (int i = 0; i < len; i++) {
+        for (int i = 0; i < attrs.length; i++) {
             String key = names[i];
             if (r.isSimpleExtDataValue(key)) {
                 value = r.getExtDataInString(key);
diff --git a/base/common/src/com/netscape/cmscore/connector/RequestTransfer.java b/base/common/src/com/netscape/cmscore/connector/RequestTransfer.java
index 7e756b0f46a20f5602bfc30605965a248ac44c39..b3479aea0b24c4bca60146c31e638129b0b59bb4 100755
--- a/base/common/src/com/netscape/cmscore/connector/RequestTransfer.java
+++ b/base/common/src/com/netscape/cmscore/connector/RequestTransfer.java
@@ -91,12 +91,7 @@ public class RequestTransfer {
                 v.addElement(k);
             }
             CMS.debug("RequestTransfer: attribute size=" + v.size());
-            if (v.size() == 0)
-                return null;
-            String attrs[] = new String[v.size()];
-
-            v.copyInto(attrs);
-            return attrs;
+            return v.toArray(new String[v.size()]);
         } else {
             return transferAttributes;
         }
@@ -107,9 +102,6 @@ public class RequestTransfer {
                 src.getRequestId().toString() +
                 " destId=" + dest.getRequestId().toString());
         String attrs[] = getTransferAttributes(src);
-        if (attrs == null) {
-            return;
-        }
 
         for (int i = 0; i < attrs.length; i++) {
             String key = attrs[i];
diff --git a/base/common/src/com/netscape/cmscore/dbs/DBRegistry.java b/base/common/src/com/netscape/cmscore/dbs/DBRegistry.java
index 67ec3e6d8d608f1aac58f6e668f679fc07dab86f..2b6a63a62f81ad09f71eadfebceedcae766b5ad3 100755
--- a/base/common/src/com/netscape/cmscore/dbs/DBRegistry.java
+++ b/base/common/src/com/netscape/cmscore/dbs/DBRegistry.java
@@ -457,11 +457,11 @@ public class DBRegistry implements IDBRegistry, ISubsystem {
      * Creates object from attribute set.
      */
     public IDBObj createObject(LDAPAttributeSet attrs)
-            throws EBaseException {
+            throws EDBException {
         // map object class attribute to object
         LDAPAttribute attr = attrs.getAttribute("objectclass");
         if (attr == null) {
-            throw new EBaseException("Cannot fing Object Class to create the Object");
+            throw new EDBException(CMS.getLogMessage("CMS_DBS_MISSING_OBJECT_CLASS"));
         }
 
         //CMS.debug("createObject: attrs " + attrs.toString());
@@ -469,16 +469,8 @@ public class DBRegistry implements IDBRegistry, ISubsystem {
         attrs.remove("objectclass");
 
         // sort the object class values
-        @SuppressWarnings("unchecked")
-        Enumeration<String> vals = attr.getStringValues();
-        Vector<String> v = new Vector<String>();
 
-        while (vals.hasMoreElements()) {
-            v.addElement(vals.nextElement());
-        }
-        String s[] = new String[v.size()];
-
-        v.copyInto(s);
+        String[] s = attr.getStringValueArray();
         String sorted = sortAndConcate(s).toLowerCase();
         NameAndObject no = mOCldapNames.get(sorted);
 
diff --git a/base/common/src/com/netscape/cmscore/ldap/LdapPredicateParser.java b/base/common/src/com/netscape/cmscore/ldap/LdapPredicateParser.java
index 51b69a42225afb38ddd48442801b7ba8e0be2136..71f88989592717e8868019ec870466817907ab77 100755
--- a/base/common/src/com/netscape/cmscore/ldap/LdapPredicateParser.java
+++ b/base/common/src/com/netscape/cmscore/ldap/LdapPredicateParser.java
@@ -69,15 +69,9 @@ public class LdapPredicateParser {
         // reverse-polish notation.
         String token = pt.nextToken();
 
-        if (token != null) {
-            if (getOP(token) != EXPRESSION) {
-                if (Debug.ON)
-                    Debug.trace("Malformed expression: " + predicateExpression);
-                throw new ELdapException(CMS.getUserMessage("CMS_LDAP_BAD_LDAP_EXPRESSION", predicateExpression));
-            }
-        } else {
+        if (getOP(token) != EXPRESSION) {
             if (Debug.ON)
-                Debug.trace("Malformed expression: Null Token");
+                Debug.trace("Malformed expression: " + predicateExpression);
             throw new ELdapException(CMS.getUserMessage("CMS_LDAP_BAD_LDAP_EXPRESSION", predicateExpression));
         }
         ILdapExpression current = parseExpression(token);
@@ -280,7 +274,7 @@ class PredicateTokenizer {
         return (currentIndex != -1);
     }
 
-    public String nextToken() {
+    public String nextToken() throws ELdapException {
         if (nextToken != null) {
             String toReturn = nextToken;
 
@@ -328,8 +322,9 @@ class PredicateTokenizer {
             }
         } else {
             // Cannot happen; Assert here.
-            toReturn = null;
-            System.out.println("We shouldn't be here!");
+            if (Debug.ON)
+                Debug.trace("Malformed expression: Null Token");
+            throw new ELdapException(CMS.getUserMessage("CMS_LDAP_BAD_LDAP_EXPRESSION"));
         }
         if (toReturn == null)
             return null;
diff --git a/base/common/src/com/netscape/cmscore/ldap/PublisherProcessor.java b/base/common/src/com/netscape/cmscore/ldap/PublisherProcessor.java
index f0baad45899c7d0af51183d3e40f9ea18164b0bb..ab99b4f0669a933d8a1c60e7b83437270c07bd95 100755
--- a/base/common/src/com/netscape/cmscore/ldap/PublisherProcessor.java
+++ b/base/common/src/com/netscape/cmscore/ldap/PublisherProcessor.java
@@ -492,24 +492,24 @@ public class PublisherProcessor implements
 
             //this is the only rule we support now
             LdapRule rule = (LdapRule) (mRuleInsts.get(name));
-            if (rule.getType() != null) {
-                if (rule.enabled() && rule.getType().equals(publishingType)) {
-                    // check if the predicate match
-                    ILdapExpression exp = rule.getPredicate();
 
-                    try {
-                        SessionContext sc = SessionContext.getContext();
+            if (rule.enabled() && publishingType.equals(rule.getType())) {
+                // check if the predicate match
+                ILdapExpression exp = rule.getPredicate();
 
-                        if (exp != null && !exp.evaluate(sc))
-                            continue;
-                    } catch (Exception ex) {
-                        // do nothing
-                    }
-                    rules.addElement(rule);
-                    if (Debug.ON)
-                        Debug.trace("added rule " + name + " for " + publishingType);
+                try {
+                    SessionContext sc = SessionContext.getContext();
+
+                    if (exp != null && !exp.evaluate(sc))
+                        continue;
+                } catch (Exception ex) {
+                    // do nothing
                 }
+                rules.addElement(rule);
+                if (Debug.ON)
+                    Debug.trace("added rule " + name + " for " + publishingType);
             }
+
         }
         return rules.elements();
     }
@@ -520,40 +520,29 @@ public class PublisherProcessor implements
         }
 
         Vector<ILdapRule> rules = new Vector<ILdapRule>();
-        Enumeration<String> e = mRuleInsts.keys();
+        Enumeration<ILdapRule> e = mRuleInsts.elements();
 
         while (e.hasMoreElements()) {
-            String name = e.nextElement();
-
-            if (name == null) {
-                if (Debug.ON)
-                    Debug.trace("rule name is " + "null");
-                return null;
-            } else {
-                if (Debug.ON)
-                    Debug.trace("rule name is " + name);
-            }
-
             //this is the only rule we support now
-            LdapRule rule = (LdapRule) (mRuleInsts.get(name));
-            if (rule.getType() != null) {
-                if (rule.enabled() && rule.getType().equals(publishingType)) {
-                    // check if the predicate match
-                    ILdapExpression exp = rule.getPredicate();
+            LdapRule rule = (LdapRule) e.nextElement();
 
-                    try {
-                        if (exp != null && !exp.evaluate(req))
-                            continue;
-                    } catch (Exception ex) {
-                        ex.printStackTrace();
-                    }
+            if (rule.enabled() && publishingType.equals(rule.getType())) {
+                // check if the predicate match
+                ILdapExpression exp = rule.getPredicate();
 
-                    rules.addElement(rule);
-                    if (Debug.ON)
-                        Debug.trace("added rule " + name + " for " + publishingType +
-                                " request: " + req.getRequestId());
+                try {
+                    if (exp != null && !exp.evaluate(req))
+                        continue;
+                } catch (Exception ex) {
+                    ex.printStackTrace();
                 }
+
+                rules.addElement(rule);
+                if (Debug.ON)
+                    Debug.trace("added rule " + rule.getInstanceName() + " for " + publishingType +
+                            " request: " + req.getRequestId());
             }
+
         }
         return rules.elements();
     }
diff --git a/base/common/src/com/netscape/cmscore/logging/LogSubsystem.java b/base/common/src/com/netscape/cmscore/logging/LogSubsystem.java
index a0b698016a50e057d88fe8addaf3da13dc9c4ed5..82b515846d68a98edc01730f41fe0de29d695a7f 100755
--- a/base/common/src/com/netscape/cmscore/logging/LogSubsystem.java
+++ b/base/common/src/com/netscape/cmscore/logging/LogSubsystem.java
@@ -203,7 +203,10 @@ public class LogSubsystem implements ILogSubsystem {
 
         try {
             return cs.getString("pluginName", "");
-        } catch (Exception e) {
+        } catch (EBaseException e) {
+            e.printStackTrace();
+            return "";
+        } catch (NullPointerException e) {
             e.printStackTrace();
             return "";
         }
diff --git a/base/common/src/com/netscape/cmscore/policy/PolicyPredicateParser.java b/base/common/src/com/netscape/cmscore/policy/PolicyPredicateParser.java
index 5d79c42bbdb8b2eb77dfacbce8ccbc24724b578d..579d9ff5b48d16855ebfec35479450bbc1e679cb 100755
--- a/base/common/src/com/netscape/cmscore/policy/PolicyPredicateParser.java
+++ b/base/common/src/com/netscape/cmscore/policy/PolicyPredicateParser.java
@@ -69,17 +69,13 @@ public class PolicyPredicateParser {
         // The first token cannot be an operator. We are not dealing with
         // reverse-polish notation.
         String token = pt.nextToken();
-        if (token != null) {
-            if (getOP(token) != EXPRESSION) {
-                if (Debug.ON)
-                    Debug.trace("Malformed expression: " + predicateExpression);
-                throw new EPolicyException(CMS.getUserMessage("CMS_POLICY_BAD_POLICY_EXPRESSION", predicateExpression));
-            }
-        } else {
+
+        if (getOP(token) != EXPRESSION) {
             if (Debug.ON)
-                Debug.trace("Malformed Predicate Expression : No Tokens");
-            throw new EPolicyException("Malformed Predicate Expression : No Tokens");
+                Debug.trace("Malformed expression: " + predicateExpression);
+            throw new EPolicyException(CMS.getUserMessage("CMS_POLICY_BAD_POLICY_EXPRESSION", predicateExpression));
         }
+
         IExpression current = parseExpression(token);
         boolean malformed = false;
         Vector<IExpression> expSet = new Vector<IExpression>();
@@ -281,7 +277,7 @@ class PredicateTokenizer {
         return (currentIndex != -1);
     }
 
-    public String nextToken() {
+    public String nextToken() throws EPolicyException {
         if (nextToken != null) {
             String toReturn = nextToken;
 
@@ -329,8 +325,9 @@ class PredicateTokenizer {
             }
         } else {
             // Cannot happen; Assert here.
-            toReturn = null;
-            System.out.println("We shouldn't be here!");
+            if (Debug.ON)
+                Debug.trace("Malformed Predicate Expression : No Tokens");
+            throw new EPolicyException("Malformed Predicate Expression : No Tokens");
         }
         if (toReturn == null)
             return null;
diff --git a/base/common/src/com/netscape/cmscore/security/CertificateInfo.java b/base/common/src/com/netscape/cmscore/security/CertificateInfo.java
index 9a9da4f43a1925d9bed0cef038800c3f4cc72a2b..3274552970749ad3adc1e362638caedc56594bf0 100755
--- a/base/common/src/com/netscape/cmscore/security/CertificateInfo.java
+++ b/base/common/src/com/netscape/cmscore/security/CertificateInfo.java
@@ -189,12 +189,15 @@ public abstract class CertificateInfo {
                 String hashtype = (String) mProperties.get(ConfigConstants.PR_HASH_TYPE);
 
                 algm = KeyCertUtil.getSigningAlgorithm(getKeyAlgorithm(), hashtype);
+                if (algm == null) {
+                    throw new NoSuchAlgorithmException();
+                }
                 mProperties.put(Constants.PR_SIGNATURE_ALGORITHM, algm);
             }
 
             AlgorithmId sigAlgId = getAlgorithmId();
 
-            if ((sigAlgId == null) && (algm != null)) {
+            if (algm != null) {
                 byte[] encodedOID = ASN1Util.encode(algm.toOID());
 
                 sigAlgId = new AlgorithmId(new ObjectIdentifier(
diff --git a/base/common/src/com/netscape/cmscore/usrgrp/UGSubsystem.java b/base/common/src/com/netscape/cmscore/usrgrp/UGSubsystem.java
index 508c7064b16d2a9671127d63672c6abe2fe991da..50b289d459f07d4c89b31c7f2bb50aef9f7c3415 100755
--- a/base/common/src/com/netscape/cmscore/usrgrp/UGSubsystem.java
+++ b/base/common/src/com/netscape/cmscore/usrgrp/UGSubsystem.java
@@ -204,9 +204,6 @@ public final class UGSubsystem implements IUGSubsystem {
 
                 try {
                     ldapconn = getConn();
-                    if (ldapconn == null) {
-                        throw new LDAPException("No LDAP Connection Available");
-                    }
                     // read DN
                     LDAPSearchResults res =
                             ldapconn.search(userid,
@@ -240,9 +237,6 @@ public final class UGSubsystem implements IUGSubsystem {
 
         try {
             ldapconn = getConn();
-            if (ldapconn == null) {
-                throw new LDAPException("No LDAP Connection Available");
-            }
             String filter = LDAP_ATTR_USER_CERT_STRING + "=" + getCertificateString(cert);
             LDAPSearchResults res =
                     ldapconn.search(getUserBaseDN(),
@@ -293,9 +287,6 @@ public final class UGSubsystem implements IUGSubsystem {
 
         try {
             ldapconn = getConn();
-            if (ldapconn == null) {
-                throw new LDAPException("No LDAP Connection Available");
-            }
             LDAPSearchResults res = ldapconn.search(getUserBaseDN(),
                     LDAPv2.SCOPE_SUB, "(" + filter + ")",
                     null, false);
@@ -327,9 +318,6 @@ public final class UGSubsystem implements IUGSubsystem {
 
         try {
             ldapconn = getConn();
-            if (ldapconn == null) {
-                throw new LDAPException("No LDAP Connection Available");
-            }
             LDAPSearchResults res = ldapconn.search(getUserBaseDN(),
                     LDAPv2.SCOPE_SUB, "(uid=" + filter + ")",
                     null, false);
@@ -367,9 +355,6 @@ public final class UGSubsystem implements IUGSubsystem {
             attrs[1] = "cn";
 
             ldapconn = getConn();
-            if (ldapconn == null) {
-                throw new LDAPException("No LDAP Connection Available");
-            }
             LDAPSearchConstraints cons = new LDAPSearchConstraints();
 
             cons.setMaxResults(0);
@@ -708,9 +693,6 @@ public final class UGSubsystem implements IUGSubsystem {
 
         try {
             ldapconn = getConn();
-            if (ldapconn == null) {
-                throw new LDAPException("No LDAP Connection Available");
-            }
             ldapconn.add(entry);
         } catch (ELdapException e) {
             log(ILogger.LL_FAILURE, CMS.getLogMessage("CMSCORE_USRGRP_ADD_USER", e.toString()));
@@ -753,9 +735,6 @@ public final class UGSubsystem implements IUGSubsystem {
 
             try {
                 ldapconn = getConn();
-                if (ldapconn == null) {
-                    throw new LDAPException("No LDAP Connection Available");
-                }
                 ldapconn.modify("uid=" + user.getUserID() +
                         "," + getUserBaseDN(), addCert);
                 // for audit log
@@ -903,9 +882,6 @@ public final class UGSubsystem implements IUGSubsystem {
 
                 try {
                     ldapconn = getConn();
-                    if (ldapconn == null) {
-                        throw new LDAPException("No LDAP Connection Available");
-                    }
                     ldapconn.modify("uid=" + user.getUserID() +
                             "," + getUserBaseDN(), attrs);
                     certCount++;
@@ -948,9 +924,6 @@ public final class UGSubsystem implements IUGSubsystem {
 
         try {
             ldapconn = getConn();
-            if (ldapconn == null) {
-                throw new LDAPException("No LDAP Connection Available");
-            }
             String groupDN = "cn=" + grp.getGroupID() +
                     "," + getGroupBaseDN();
             LDAPAttribute memberAttr = new LDAPAttribute(
@@ -983,9 +956,6 @@ public final class UGSubsystem implements IUGSubsystem {
 
         try {
             ldapconn = getConn();
-            if (ldapconn == null) {
-                throw new LDAPException("No LDAP Connection Available");
-            }
             ldapconn.delete("uid=" + userid + "," + getUserBaseDN());
             // for audit log
             SessionContext sessionContext = SessionContext.getContext();
@@ -1028,9 +998,6 @@ public final class UGSubsystem implements IUGSubsystem {
 
         try {
             ldapconn = getConn();
-            if (ldapconn == null) {
-                throw new LDAPException("No LDAP Connection Available");
-            }
             if ((st = user.getFullName()) != null) {
                 attrs.add(LDAPModification.REPLACE,
                         new LDAPAttribute("sn", st));
@@ -1148,9 +1115,6 @@ public final class UGSubsystem implements IUGSubsystem {
 
         try {
             ldapconn = getConn();
-            if (ldapconn == null) {
-                throw new LDAPException("No LDAP Connection Available");
-            }
             LDAPSearchResults res =
                     ldapconn.search(getGroupBaseDN(), LDAPv2.SCOPE_SUB,
                             "(&(objectclass=groupofuniquenames)(cn=" + filter + "))",
@@ -1195,9 +1159,6 @@ public final class UGSubsystem implements IUGSubsystem {
             attrs[1] = "description";
 
             ldapconn = getConn();
-            if (ldapconn == null) {
-                throw new LDAPException("No LDAP Connection Available");
-            }
             LDAPSearchResults res =
                     ldapconn.search(getGroupBaseDN(), LDAPv2.SCOPE_SUB,
                             "(&(objectclass=groupofuniquenames)(cn=" + filter + "))",
@@ -1312,9 +1273,6 @@ public final class UGSubsystem implements IUGSubsystem {
 
         try {
             ldapconn = getConn();
-            if (ldapconn == null) {
-                throw new LDAPException("No LDAP Connection Available");
-            }
             // read the group object
             LDAPSearchResults res = ldapconn.search(name,
                     LDAPConnection.SCOPE_BASE, "(objectclass=*)", null, false);
@@ -1344,9 +1302,6 @@ public final class UGSubsystem implements IUGSubsystem {
 
         try {
             ldapconn = getConn();
-            if (ldapconn == null) {
-                throw new LDAPException("No LDAP Connection Available");
-            }
             LDAPEntry entry = ldapconn.read(name);
             LDAPAttribute attr = entry.getAttribute(OBJECTCLASS_ATTR);
 
@@ -1419,9 +1374,6 @@ public final class UGSubsystem implements IUGSubsystem {
             attrs[0] = "cn";
 
             ldapconn = getConn();
-            if (ldapconn == null) {
-                throw new LDAPException("No LDAP Connection Available");
-            }
 
             String filter = "(uniquemember=" + userid + ")";
             Debug.trace("authorization search base: " + basedn);
@@ -1496,9 +1448,6 @@ public final class UGSubsystem implements IUGSubsystem {
                     "," + getGroupBaseDN(), attrs);
 
             ldapconn = getConn();
-            if (ldapconn == null) {
-                throw new LDAPException("No LDAP Connection Available");
-            }
             ldapconn.add(entry);
         } catch (LDAPException e) {
             log(ILogger.LL_FAILURE, CMS.getLogMessage("CMSCORE_USRGRP_ADD_GROUP", e.toString()));
@@ -1528,9 +1477,6 @@ public final class UGSubsystem implements IUGSubsystem {
 
         try {
             ldapconn = getConn();
-            if (ldapconn == null) {
-                throw new LDAPException("No LDAP Connection Available");
-            }
             ldapconn.delete("cn=" + name + "," + getGroupBaseDN());
         } catch (LDAPException e) {
             log(ILogger.LL_FAILURE, CMS.getLogMessage("CMSCORE_USRGRP_REMOVE_GROUP", e.toString()));
@@ -1585,9 +1531,6 @@ public final class UGSubsystem implements IUGSubsystem {
             }
 
             ldapconn = getConn();
-            if (ldapconn == null) {
-                throw new LDAPException("No LDAP Connection Available");
-            }
             ldapconn.modify("cn=" + grp.getGroupID() +
                     "," + getGroupBaseDN(), mod);
         } catch (LDAPException e) {
@@ -1636,9 +1579,6 @@ public final class UGSubsystem implements IUGSubsystem {
 
         try {
             ldapconn = getConn();
-            if (ldapconn == null) {
-                throw new LDAPException("No LDAP Connection Available");
-            }
             LDAPSearchResults res = ldapconn.search(getUserBaseDN(),
                     LDAPv2.SCOPE_SUB, "(uid=" + u + ")", null, false);
 
@@ -1713,9 +1653,16 @@ public final class UGSubsystem implements IUGSubsystem {
     }
 
     protected LDAPConnection getConn() throws ELdapException {
-        if (mLdapConnFactory == null)
-            return null;
-        return mLdapConnFactory.getConn();
+        if (mLdapConnFactory != null) {
+            LDAPConnection conn = mLdapConnFactory.getConn();
+            if (conn == null) {
+                throw new ELdapException("No Ldap Connection Available");
+            } else {
+                return conn;
+            }
+        }
+
+        throw new ELdapException("Ldap Connection Factory is Unavailable");
     }
 
     protected void returnConn(LDAPConnection conn) {
diff --git a/base/kra/src/com/netscape/kra/EnrollmentService.java b/base/kra/src/com/netscape/kra/EnrollmentService.java
index 89f47c9a3984ff1eba27c06b8f71aeb05a066b6f..666619cdb0de77d6420ec4985af60fce309b316e 100755
--- a/base/kra/src/com/netscape/kra/EnrollmentService.java
+++ b/base/kra/src/com/netscape/kra/EnrollmentService.java
@@ -735,7 +735,7 @@ public class EnrollmentService implements IService {
                 request.getExtDataInCertInfoArray(IRequest.CERT_INFO);
         CertificateX509Key pX509Key = null;
         if (certInfo == null) {
-            throw new EBaseException("Invalid or NULL Certificates found");
+            throw new EBaseException(CMS.getLogMessage("CMS_BASE_CERT_NOT_FOUND"));
         }
         try {
             pX509Key = (CertificateX509Key)
@@ -788,7 +788,7 @@ public class EnrollmentService implements IService {
         X509CertInfo certInfo[] =
                 request.getExtDataInCertInfoArray(IRequest.CERT_INFO);
         if (certInfo == null) {
-            throw new EBaseException("Invalid or NULL Certificates found");
+            throw new EBaseException(CMS.getLogMessage("CMS_BASE_CERT_NOT_FOUND"));
         }
         CertificateSubjectName pSub = null;
 
diff --git a/base/util/src/com/netscape/cmsutil/http/HttpMessage.java b/base/util/src/com/netscape/cmsutil/http/HttpMessage.java
index 468539b8ee2d497b570d7b2966c146d2ec361954..44f608900d84008de48334786d106b60a150578c 100755
--- a/base/util/src/com/netscape/cmsutil/http/HttpMessage.java
+++ b/base/util/src/com/netscape/cmsutil/http/HttpMessage.java
@@ -119,10 +119,10 @@ public class HttpMessage {
             throws IOException {
         String line = reader.readLine();
 
-        //        if (line == null) {
-        //           throw new HttpEofException("End of stream reached");
-        //      }
-        if (line == null || line.equals("")) {
+        if (line == null) {
+            throw new HttpEofException("End of stream reached");
+        }
+        if (line.equals("")) {
             throw new HttpProtocolException("Bad Http req/resp line " + line);
         }
         mLine = line;
diff --git a/base/util/src/netscape/security/util/PrettyPrintFormat.java b/base/util/src/netscape/security/util/PrettyPrintFormat.java
index 4df4473d07ad6e18302f38e2f81f430acf76e624..30ae33b107a110be400c7b74572366f90180ccc4 100755
--- a/base/util/src/netscape/security/util/PrettyPrintFormat.java
+++ b/base/util/src/netscape/security/util/PrettyPrintFormat.java
@@ -102,14 +102,13 @@ public class PrettyPrintFormat {
 
     public String toHexString(byte[] in, int indentSize,
             int lineLen, String separator) {
+        if (in == null) {
+            return "";
+        }
         StringBuffer sb = new StringBuffer();
         int hexCount = 0;
         char c[];
         int j = 0;
-        int len = 0;
-        if (in != null) {
-            len = in.length;
-        }
 
         if (lineLen == 0) {
             c = new char[in.length * 3 + 1];
@@ -120,7 +119,7 @@ public class PrettyPrintFormat {
         char sep = separator.charAt(0);
 
         sb.append(indent(indentSize));
-        for (int i = 0; i < len; i++) {
+        for (int i = 0; i < in.length; i++) {
             if (lineLen > 0 && hexCount == lineLen) {
                 c[j++] = '\n';
                 sb.append(c, 0, j);
diff --git a/base/util/src/netscape/security/x509/KeyUsageExtension.java b/base/util/src/netscape/security/x509/KeyUsageExtension.java
index 96b5fe367aa8edd5b09d42a71adf88d03ea15f03..8cbfc880aed6ecb33aab628357536e6f1e12918d 100755
--- a/base/util/src/netscape/security/x509/KeyUsageExtension.java
+++ b/base/util/src/netscape/security/x509/KeyUsageExtension.java
@@ -210,11 +210,12 @@ public class KeyUsageExtension extends Extension
         }
         this.extensionValue = extValue;
         DerValue val = new DerValue(extValue);
-        try {
-            this.bitString = val.getUnalignedBitString().toBooleanArray();
-        } catch (Exception e) {
-            this.bitString = null;
+        BitArray bitArray = val.getUnalignedBitString();
+        if (bitArray == null) {
+            throw new IOException("Invalid bit string");
         }
+        this.bitString = bitArray.toBooleanArray();
+
     }
 
     /**
-- 
1.7.10.2

