>From b5fc3f68054ae9ee15d184035d7fa573dde93bab Mon Sep 17 00:00:00 2001
From: Abhishek Koneru <akoneru@redhat.com>
Date: Thu, 24 May 2012 16:11:53 -0400
Subject: [PATCH] Fixes for Coverity Issues
 CALL_SUPER,UNCONFIRMEDCAST,DEAD_STORE,TOSTRING_ARRAY

---
 .../src/com/netscape/certsrv/request/ARequestNotifier.java    |    4 ++--
 base/common/src/com/netscape/cmscore/apps/CMSEngine.java      |    1 -
 base/common/src/com/netscape/cmscore/connector/Resender.java  |    4 +---
 .../com/netscape/cmscore/ldapconn/LdapAnonConnFactory.java    |    9 ++++++++-
 .../com/netscape/cmscore/ldapconn/LdapBoundConnFactory.java   |    9 ++++++++-
 .../src/com/netscape/cmscore/selftests/SelfTestSubsystem.java |    4 +---
 base/java-tools/src/com/netscape/cmstools/AtoB.java           |    2 +-
 base/java-tools/src/com/netscape/cmstools/CMCRevoke.java      |    2 +-
 base/java-tools/src/com/netscape/cmstools/DRMTool.java        |    2 +-
 .../java-tools/src/com/netscape/cmstools/PrettyPrintCert.java |    2 +-
 base/java-tools/src/com/netscape/cmstools/PrettyPrintCrl.java |    2 +-
 base/silent/src/com/netscape/pkisilent/ConfigureSubCA.java    |    2 +-
 base/silent/src/com/netscape/pkisilent/common/CMSLDAP.java    |    4 ++--
 base/silent/src/com/netscape/pkisilent/common/Request.java    |    2 +-
 .../security/extensions/ExtendedKeyUsageExtension.java        |    1 +
 .../netscape/security/extensions/GenericASN1Extension.java    |    3 ++-
 .../security/extensions/InhibitAnyPolicyExtension.java        |    1 +
 .../netscape/security/extensions/OCSPNoCheckExtension.java    |    1 +
 base/util/src/netscape/security/pkcs/PKCS7.java               |    2 +-
 .../security/x509/CRLDistributionPointsExtension.java         |    1 +
 .../util/src/netscape/security/x509/FreshestCRLExtension.java |    1 +
 .../security/x509/IssuingDistributionPointExtension.java      |    2 +-
 22 files changed, 38 insertions(+), 23 deletions(-)

diff --git a/base/common/src/com/netscape/certsrv/request/ARequestNotifier.java b/base/common/src/com/netscape/certsrv/request/ARequestNotifier.java
index ba3d9f2939f5ce96f0ea8b921785d1b5986c958e..f8f7588a7bef9fa27d1fc61ff45d22fc0053273a 100644
--- a/base/common/src/com/netscape/certsrv/request/ARequestNotifier.java
+++ b/base/common/src/com/netscape/certsrv/request/ARequestNotifier.java
@@ -91,13 +91,13 @@ public class ARequestNotifier implements IRequestNotifier {
             mRequestQueue = mCA.getRequestQueue();
         if (mIsPublishingQueueEnabled && mSavePublishingStatus > 0 && mRequestQueue != null) {
             mPublishingStatus = mRequestQueue.getPublishingStatus();
-            BigInteger status = new BigInteger("-2");
             try {
-                status = new BigInteger(mPublishingStatus);
+                BigInteger status = new BigInteger(mPublishingStatus);
                 if (status.compareTo(BigInteger.ZERO) > -1) {
                     recoverPublishingQueue(mPublishingStatus);
                 }
             } catch (Exception e) {
+                e.printStackTrace();
             }
         }
 
diff --git a/base/common/src/com/netscape/cmscore/apps/CMSEngine.java b/base/common/src/com/netscape/cmscore/apps/CMSEngine.java
index 19fc5162b0f4ff43b1bec1ff6dc9004a2f6748ec..5d3277aa12fa69ff79d01156ba4bfbc1ee113ce3 100644
--- a/base/common/src/com/netscape/cmscore/apps/CMSEngine.java
+++ b/base/common/src/com/netscape/cmscore/apps/CMSEngine.java
@@ -894,7 +894,6 @@ public class CMSEngine implements ICMSEngine {
 
         // load dyn subsystems.
         mDynSubsystems = new SubsystemInfo[nsubsystems];
-        ssnames = ssconfig.getSubStoreNames();
         for (int i = 0; i < mDynSubsystems.length; i++) {
             IConfigStore config =
                     ssconfig.getSubStore(String.valueOf(i));
diff --git a/base/common/src/com/netscape/cmscore/connector/Resender.java b/base/common/src/com/netscape/cmscore/connector/Resender.java
index e1b19749a8b6edaa345470d3f3ed1763df9b10f6..73a399fdcc8f1deea8f69c29a3895c6b4f6e66c5 100644
--- a/base/common/src/com/netscape/cmscore/connector/Resender.java
+++ b/base/common/src/com/netscape/cmscore/connector/Resender.java
@@ -216,11 +216,9 @@ public class Resender implements IResender {
             RequestStatus replyStatus =
                     RequestStatus.fromString(replymsg.reqStatus);
             int index = replymsg.reqId.lastIndexOf(':');
-            RequestId replyRequestId =
-                    new RequestId(replymsg.reqId.substring(index + 1));
 
             if (Debug.ON)
-                Debug.trace("reply request id " + replyRequestId +
+                Debug.trace("reply request id " + replymsg.reqId.substring(index + 1) +
                         " for request " + r.getRequestId());
 
             if (replyStatus != RequestStatus.COMPLETE) {
diff --git a/base/common/src/com/netscape/cmscore/ldapconn/LdapAnonConnFactory.java b/base/common/src/com/netscape/cmscore/ldapconn/LdapAnonConnFactory.java
index 1edee3812c587a3df4a3b7ce1ec9cf543cf6ae71..79f2e91c43ce444616a57092dc142b8ddef82841 100644
--- a/base/common/src/com/netscape/cmscore/ldapconn/LdapAnonConnFactory.java
+++ b/base/common/src/com/netscape/cmscore/ldapconn/LdapAnonConnFactory.java
@@ -338,8 +338,15 @@ public class LdapAnonConnFactory implements ILdapConnFactory {
         if (conn == null) {
             return;
         }
+        AnonConnection anon = null;
+
         // check if conn is valid and from this factory.
-        AnonConnection anon = (AnonConnection) conn;
+        if (conn instanceof AnonConnection) {
+            anon = (AnonConnection) conn;
+        } else {
+            log(ILogger.LL_WARN, "returnConn : Connection is not an AnonConnection");
+            return;
+        }
 
         if (anon.getFacId() != mConns) {
             // returning a connection not from this factory.
diff --git a/base/common/src/com/netscape/cmscore/ldapconn/LdapBoundConnFactory.java b/base/common/src/com/netscape/cmscore/ldapconn/LdapBoundConnFactory.java
index 1da965a3a0bfd97752fa2dfee469de75ecca6d5f..c3e84f13607f8dd2b8422c33f35bac39a9d84daa 100644
--- a/base/common/src/com/netscape/cmscore/ldapconn/LdapBoundConnFactory.java
+++ b/base/common/src/com/netscape/cmscore/ldapconn/LdapBoundConnFactory.java
@@ -413,7 +413,14 @@ public class LdapBoundConnFactory implements ILdapBoundConnFactory {
         if (conn == null) {
             return;
         }
-        BoundConnection boundconn = (BoundConnection) conn;
+        BoundConnection boundconn = null;
+
+        if (conn instanceof BoundConnection) {
+            boundconn = (BoundConnection) conn;
+        } else {
+            log(ILogger.LL_WARN, "returnConn : Connection is not an BoundConnection");
+            return;
+        }
 
         if (boundconn.getFacId() != mConns) {
             log(ILogger.LL_WARN, "returnConn: unknown connection.");
diff --git a/base/common/src/com/netscape/cmscore/selftests/SelfTestSubsystem.java b/base/common/src/com/netscape/cmscore/selftests/SelfTestSubsystem.java
index 0ae6af0c31d0e31aa4183869727fb7d458d6b310..6f5d29730013781a1646a35b57abc9e95d0a3599 100644
--- a/base/common/src/com/netscape/cmscore/selftests/SelfTestSubsystem.java
+++ b/base/common/src/com/netscape/cmscore/selftests/SelfTestSubsystem.java
@@ -1249,9 +1249,7 @@ public class SelfTestSubsystem
             throws EBaseException {
         // strip preceding/trailing whitespace
         // from passed-in String parameters
-        if (id != null) {
-            id = id.trim();
-        } else {
+        if (id == null) {
             log(mLogger,
                     CMS.getLogMessage(
                             "CMSCORE_SELFTESTS_PROPERTY_NAME_IS_NULL"));
diff --git a/base/java-tools/src/com/netscape/cmstools/AtoB.java b/base/java-tools/src/com/netscape/cmstools/AtoB.java
index 51fb3cc17fb30ed41166aa66f88448bf6753a847..ee82da2e0468755a221d7a822021e23c389fc577 100644
--- a/base/java-tools/src/com/netscape/cmstools/AtoB.java
+++ b/base/java-tools/src/com/netscape/cmstools/AtoB.java
@@ -60,7 +60,7 @@ public class AtoB {
     public static void main(String argv[]) {
 
         BufferedReader inputBlob = null;
-        String asciiBASE64BlobChunk = "";
+        String asciiBASE64BlobChunk;
         StringBuffer asciiBASE64Blob = new StringBuffer();
 
         byte binaryBASE64Blob[] = null;
diff --git a/base/java-tools/src/com/netscape/cmstools/CMCRevoke.java b/base/java-tools/src/com/netscape/cmstools/CMCRevoke.java
index d76e93a5257f0f38649b8121aa635ff7610851ee..aaf9fbb1793861ceb632380e68185f83d85fc85d 100644
--- a/base/java-tools/src/com/netscape/cmstools/CMCRevoke.java
+++ b/base/java-tools/src/com/netscape/cmstools/CMCRevoke.java
@@ -280,7 +280,7 @@ public class CMCRevoke {
         SignerIdentifier si = null;
         ContentInfo fullEnrollmentReq = null;
         String tokenname = "internal";
-        String asciiBASE64Blob = "";
+        String asciiBASE64Blob = null;
 
         try {
 
diff --git a/base/java-tools/src/com/netscape/cmstools/DRMTool.java b/base/java-tools/src/com/netscape/cmstools/DRMTool.java
index bb53f1bb31462362a58be2459a80e3cd46cf7823..efd83e892deca14210ce35c865ea344448c6cd02 100644
--- a/base/java-tools/src/com/netscape/cmstools/DRMTool.java
+++ b/base/java-tools/src/com/netscape/cmstools/DRMTool.java
@@ -1445,7 +1445,7 @@ public class DRMTool {
      */
     private static PublicKey getPublicKey() {
         BufferedReader inputCert = null;
-        String encodedBASE64CertChunk = "";
+        String encodedBASE64CertChunk;
         StringBuffer encodedBASE64Cert = new StringBuffer();
         byte decodedBASE64Cert[] = null;
         X509CertImpl cert = null;
diff --git a/base/java-tools/src/com/netscape/cmstools/PrettyPrintCert.java b/base/java-tools/src/com/netscape/cmstools/PrettyPrintCert.java
index a713fb5a35078fbd7e9d90eadf91dd5eb8957300..90d1eff9eefdc5ec2671ade8ca7bf6d2fb297ba4 100644
--- a/base/java-tools/src/com/netscape/cmstools/PrettyPrintCert.java
+++ b/base/java-tools/src/com/netscape/cmstools/PrettyPrintCert.java
@@ -79,7 +79,7 @@ public class PrettyPrintCert {
     public static void main(String argv[]) {
 
         BufferedReader inputCert = null;
-        String encodedBASE64CertChunk = "";
+        String encodedBASE64CertChunk;
         StringBuffer encodedBASE64Cert = new StringBuffer();
 
         byte decodedBASE64Cert[] = null;
diff --git a/base/java-tools/src/com/netscape/cmstools/PrettyPrintCrl.java b/base/java-tools/src/com/netscape/cmstools/PrettyPrintCrl.java
index e9056dd480856f0dcd55d2580a5968a1aaca6fd2..ebee526d05ee50537c8d0de689e318e95861b056 100644
--- a/base/java-tools/src/com/netscape/cmstools/PrettyPrintCrl.java
+++ b/base/java-tools/src/com/netscape/cmstools/PrettyPrintCrl.java
@@ -79,7 +79,7 @@ public class PrettyPrintCrl {
         X509CRLImpl crl = null;
         Locale aLocale = null;
         CrlPrettyPrint CrlDetails = null;
-        String pp = "";
+        String pp;
         FileOutputStream outputCrl = null;
 
         // (1) Check that at least one argument was submitted to the program
diff --git a/base/silent/src/com/netscape/pkisilent/ConfigureSubCA.java b/base/silent/src/com/netscape/pkisilent/ConfigureSubCA.java
index 85b4ab53e46a732323cbafb47bcc649eb9e16c4d..32fe687a86b2173ee1a16e7e7c0967721d7ecca7 100644
--- a/base/silent/src/com/netscape/pkisilent/ConfigureSubCA.java
+++ b/base/silent/src/com/netscape/pkisilent/ConfigureSubCA.java
@@ -23,13 +23,13 @@ import java.io.UnsupportedEncodingException;
 import java.net.URLEncoder;
 import java.util.ArrayList;
 
+import com.netscape.cmsutil.util.Utils;
 import com.netscape.pkisilent.argparser.ArgParser;
 import com.netscape.pkisilent.argparser.StringHolder;
 import com.netscape.pkisilent.common.ComCrypto;
 import com.netscape.pkisilent.common.ParseXML;
 import com.netscape.pkisilent.http.HTTPClient;
 import com.netscape.pkisilent.http.HTTPResponse;
-import com.netscape.cmsutil.util.Utils;
 
 public class ConfigureSubCA {
 
diff --git a/base/silent/src/com/netscape/pkisilent/common/CMSLDAP.java b/base/silent/src/com/netscape/pkisilent/common/CMSLDAP.java
index ae9bc276ea5da652f466a46449787f2682a8f15a..7558dc88f58d8d4cc7222bcfd8cee219222efb60 100644
--- a/base/silent/src/com/netscape/pkisilent/common/CMSLDAP.java
+++ b/base/silent/src/com/netscape/pkisilent/common/CMSLDAP.java
@@ -557,11 +557,11 @@ public class CMSLDAP {
         String PASSWORD = args[3];
         String BASEDN = args[4];
 
-        String s =
+        /*String s =
                 "MIICFzCCAYCgAwIBAgIBBjANBgkqhkiG9w0BAQQFADBDMRswGQYDVQQKExJhY2NlcHRhY25ldGVz\ndDEwMjQxFzAVBgNVBAsTDmFjY2VwdGFuY2V0ZXN0MQswCQYDVQQDEwJjYTAeFw0wMzA0MTEyMTUx\nMzZaFw0wNDA0MTAwOTQ2NTVaMFwxCzAJBgNVBAYTAlVTMQwwCgYDVQQKEwNTU0wxHTAbBgNVBAsT\nFHNzbHRlc3QxMDUwMDk3ODkzNzQ1MSAwHgYDVQQDExdqdXBpdGVyMi5uc2NwLmFvbHR3Lm5ldDBc\nMA0GCSqGSIb3DQEBAQUAA0sAMEgCQQDCsCTIIQ+bJMfPHi6kwa7HF+/xSTVHcpZ5zsodXsNWjPlD\noRu/5KAO8NotfwGnYmALWdYnqXCF0q0gkaJQalQTAgMBAAGjRjBEMA4GA1UdDwEB/wQEAwIFoDAR\nBglghkgBhvhCAQEEBAMCBkAwHwYDVR0jBBgwFoAUzxZkSySZT/Y3SxGMEiNyHnLUOPAwDQYJKoZI\nhvcNAQEEBQADgYEALtpqMOtZt6j5KlghDFgdg/dvf36nWiZwC1ap6+ka22shLkA/RjmOix97btzT\nQ+8LcmdkAW5iap4YbtrCu0wdN6IbIEXoQI1QGZBoKO2o02utssXANmTnRCyH/GX2KefQlp1NSRj9\nZNZ+GRT2Qk/8G5Ds9vVjm1I5+/AkzI9jS14=";
 
         s = "-----BEGIN CERTIFICATE-----" + "\n" + s + "\n"
-                + "-----END CERTIFICATE-----\n";
+                + "-----END CERTIFICATE-----\n";*/
 
         try {
 
diff --git a/base/silent/src/com/netscape/pkisilent/common/Request.java b/base/silent/src/com/netscape/pkisilent/common/Request.java
index e0255ef59e771a0e42900ee83f274aba8bcc1a74..978426c50625ad1f88f9bb593f005e265bc8e2dc 100644
--- a/base/silent/src/com/netscape/pkisilent/common/Request.java
+++ b/base/silent/src/com/netscape/pkisilent/common/Request.java
@@ -664,7 +664,7 @@ public class Request extends TestClient {
             con.setQueryString(query);
             con.setActionURL(ACTION_STRING);
             con.Send();
-            StringBuffer s = new StringBuffer();
+            StringBuffer s;
 
             s = con.getPage();
 
diff --git a/base/util/src/netscape/security/extensions/ExtendedKeyUsageExtension.java b/base/util/src/netscape/security/extensions/ExtendedKeyUsageExtension.java
index 391df90dce57ffd1e4bed9f24bf90cf59da4cf5a..a966ca1dbba66443454411546e0f80ced901897a 100644
--- a/base/util/src/netscape/security/extensions/ExtendedKeyUsageExtension.java
+++ b/base/util/src/netscape/security/extensions/ExtendedKeyUsageExtension.java
@@ -131,6 +131,7 @@ public class ExtendedKeyUsageExtension extends Extension implements CertAttrSet
         }
     }
 
+    @Override
     public String toString() {
         String presentation = "oid=" + ExtendedKeyUsageExtension.OID + " ";
 
diff --git a/base/util/src/netscape/security/extensions/GenericASN1Extension.java b/base/util/src/netscape/security/extensions/GenericASN1Extension.java
index d6bd012230a08d3ab800f087072c03dfad3aa26b..80617869c67dae017b98c542cab8474f0d57531f 100644
--- a/base/util/src/netscape/security/extensions/GenericASN1Extension.java
+++ b/base/util/src/netscape/security/extensions/GenericASN1Extension.java
@@ -270,8 +270,9 @@ public class GenericASN1Extension extends Extension
     /**
      * Returns a printable representation of the GenericASN1Extension.
      */
+    @Override
     public String toString() {
-        return (null);
+        return super.toString();
     }
 
     /**
diff --git a/base/util/src/netscape/security/extensions/InhibitAnyPolicyExtension.java b/base/util/src/netscape/security/extensions/InhibitAnyPolicyExtension.java
index 181360f52b77f8bc3596c243ece63c986ad2fa57..2ccc53ffd22ecedd28f12e6b87fd8cac288956ad 100644
--- a/base/util/src/netscape/security/extensions/InhibitAnyPolicyExtension.java
+++ b/base/util/src/netscape/security/extensions/InhibitAnyPolicyExtension.java
@@ -101,6 +101,7 @@ public class InhibitAnyPolicyExtension
         return mSkipCerts;
     }
 
+    @Override
     public String toString() {
         String presentation = "ObjectId: " + OID + " ";
 
diff --git a/base/util/src/netscape/security/extensions/OCSPNoCheckExtension.java b/base/util/src/netscape/security/extensions/OCSPNoCheckExtension.java
index 511255e3ac53223a85fa1d0bf721c21d9226a03c..3d89e1d504645a259e5e40615590493e2f4d202a 100644
--- a/base/util/src/netscape/security/extensions/OCSPNoCheckExtension.java
+++ b/base/util/src/netscape/security/extensions/OCSPNoCheckExtension.java
@@ -95,6 +95,7 @@ public class OCSPNoCheckExtension extends Extension implements CertAttrSet {
         }
     }
 
+    @Override
     public String toString() {
         String presentation = "oid=" + OID + " ";
 
diff --git a/base/util/src/netscape/security/pkcs/PKCS7.java b/base/util/src/netscape/security/pkcs/PKCS7.java
index 4bedc06fe9c3ccc331780aed6e206b73bfd0050f..4ecb2966cbf6e25d20a1e6bc427947f8cc83b596 100644
--- a/base/util/src/netscape/security/pkcs/PKCS7.java
+++ b/base/util/src/netscape/security/pkcs/PKCS7.java
@@ -72,7 +72,7 @@ public class PKCS7 {
         int len = 0;
         byte[] newbuf = new byte[len];
         byte[] oldbuf = new byte[len];
-        byte[] data = new byte[len];
+        byte[] data;
 
         do {
             newbuf = new byte[dis.available()];
diff --git a/base/util/src/netscape/security/x509/CRLDistributionPointsExtension.java b/base/util/src/netscape/security/x509/CRLDistributionPointsExtension.java
index 327322b1c9b2513fcf004ee77c53e30dbbbe8802..4180473d41e953e7ce34b1b1f2e595a1aa096db0 100644
--- a/base/util/src/netscape/security/x509/CRLDistributionPointsExtension.java
+++ b/base/util/src/netscape/security/x509/CRLDistributionPointsExtension.java
@@ -186,6 +186,7 @@ public class CRLDistributionPointsExtension extends Extension
         }
     }
 
+    @Override
     public String toString() {
         return NAME;
     }
diff --git a/base/util/src/netscape/security/x509/FreshestCRLExtension.java b/base/util/src/netscape/security/x509/FreshestCRLExtension.java
index b27f01a6122edb6d788f308587c2791b90ac59a0..f108b459948ca836db520f8f4c74910d46e20922 100644
--- a/base/util/src/netscape/security/x509/FreshestCRLExtension.java
+++ b/base/util/src/netscape/security/x509/FreshestCRLExtension.java
@@ -191,6 +191,7 @@ public class FreshestCRLExtension extends Extension
     // because it is so complicated. Therefore, we only provide a
     // minimal implementation.
     /////////////////////////////////////////////////////////////
+    @Override
     public String toString() {
         return NAME;
     }
diff --git a/base/util/src/netscape/security/x509/IssuingDistributionPointExtension.java b/base/util/src/netscape/security/x509/IssuingDistributionPointExtension.java
index b1cf611806db181900ddd4be3ac787c1df457b55..67ace692e5b82807259e610fa71f97d13c5845a3 100644
--- a/base/util/src/netscape/security/x509/IssuingDistributionPointExtension.java
+++ b/base/util/src/netscape/security/x509/IssuingDistributionPointExtension.java
@@ -285,7 +285,7 @@ public class IssuingDistributionPointExtension extends Extension
     /**
      * Returns a printable representation of the IssuingDistributionPointExtension
      */
-
+    @Override
     public String toString() {
         return NAME;
     }
-- 
1.7.10.2

