>From 7e4a5e1a1e414016c4e86a211e5f71d8a1eeb9a2 Mon Sep 17 00:00:00 2001
From: Abhishek Koneru <akoneru@redhat.com>
Date: Thu, 5 Jul 2012 16:36:00 -0400
Subject: [PATCH] Fixes for Comments on Patch 20.

---
 .../src/com/netscape/cmscore/apps/CMSEngine.java   |    2 +-
 .../src/com/netscape/cmscore/security/PWUtil.java  |    6 +-
 .../com/netscape/cmscore/security/PWsdrCache.java  |    8 +-
 .../src/com/netscape/cmstools/PasswordCache.java   |    4 +-
 base/util/src/com/netscape/cmsutil/util/Utils.java |    2 +-
 .../src/netscape/security/util/ExtPrettyPrint.java |  240 +++++++++-----------
 6 files changed, 119 insertions(+), 143 deletions(-)

diff --git a/base/common/src/com/netscape/cmscore/apps/CMSEngine.java b/base/common/src/com/netscape/cmscore/apps/CMSEngine.java
index 5cfa3ef56af921e5dd61a612c0a876bf6c2eb2a8..13a8bb6bf9fbf7f7aafb2f2a605ca8b114eb88d3 100644
--- a/base/common/src/com/netscape/cmscore/apps/CMSEngine.java
+++ b/base/common/src/com/netscape/cmscore/apps/CMSEngine.java
@@ -1591,7 +1591,7 @@ public class CMSEngine implements ICMSEngine {
         } catch (IOException e) {
             e.printStackTrace();
         } catch (InterruptedException e) {
-            e.printStackTrace();
+            Thread.currentThread().interrupt();
         }
     } // end shutdownHttpServer
 
diff --git a/base/common/src/com/netscape/cmscore/security/PWUtil.java b/base/common/src/com/netscape/cmscore/security/PWUtil.java
index 4a15aa09b32e68e8032359512e799b0e4d663089..78678b98b27bcd31467b60124a699ee313796383 100644
--- a/base/common/src/com/netscape/cmscore/security/PWUtil.java
+++ b/base/common/src/com/netscape/cmscore/security/PWUtil.java
@@ -21,14 +21,12 @@ import org.mozilla.jss.util.Password;
 import org.mozilla.jss.util.PasswordCallback;
 
 public class PWUtil {
-    public static Password
-            readPasswordFromStream()
-                    throws PasswordCallback.GiveUpException {
+
+    public static Password readPasswordFromStream() throws PasswordCallback.GiveUpException {
 
         StringBuffer buf = new StringBuffer();
         String passwordString = "";
         int c;
-
         // System.out.println( "about to do read" );
         try {
             while ((c = System.in.read()) != -1) {
diff --git a/base/common/src/com/netscape/cmscore/security/PWsdrCache.java b/base/common/src/com/netscape/cmscore/security/PWsdrCache.java
index 4342dd800cef73f2e33e04de7bceda3f47991400..810605d4122a426c0e0c662edd24027e18a3face 100644
--- a/base/common/src/com/netscape/cmscore/security/PWsdrCache.java
+++ b/base/common/src/com/netscape/cmscore/security/PWsdrCache.java
@@ -542,7 +542,7 @@ public class PWsdrCache {
         return ((File.separator).equals("\\"));
     }
 
-    public static boolean exec(String cmd) throws EBaseException {
+    public static boolean exec(String cmd) throws IOException {
         String cmds[] = null;
 
         if (isNT()) {
@@ -563,12 +563,12 @@ public class PWsdrCache {
             process = Runtime.getRuntime().exec(cmds);
             process.waitFor();
         } catch (IOException e) {
-            throw new EBaseException(e.toString());
+            throw e;
         } catch (InterruptedException e) {
-            throw new EBaseException(e.toString());
+            Thread.currentThread().interrupt();
         }
 
-        if (process.exitValue() == 0) {
+        if (process != null && process.exitValue() == 0) {
 
             /**
              * pOut = new BufferedReader(
diff --git a/base/java-tools/src/com/netscape/cmstools/PasswordCache.java b/base/java-tools/src/com/netscape/cmstools/PasswordCache.java
index 5cc8142ca820ade5fe77d9f713ca27cdd5241f6a..89254a2a543229e13d8f9a6c9e22e4176cd567af 100644
--- a/base/java-tools/src/com/netscape/cmstools/PasswordCache.java
+++ b/base/java-tools/src/com/netscape/cmstools/PasswordCache.java
@@ -819,9 +819,9 @@ class PWsdrCache {
                 return false;
             }
         } catch (IOException e) {
-            e.printStackTrace();
+            throw e;
         } catch (InterruptedException e) {
-            e.printStackTrace();
+            Thread.currentThread().interrupt();
         }
         return false;
     }
diff --git a/base/util/src/com/netscape/cmsutil/util/Utils.java b/base/util/src/com/netscape/cmsutil/util/Utils.java
index b2b0119accb8d91e2e885c7c2b8bd6495cb31f2d..98becdc4c52992a3c1258f437479bed95857b4e8 100644
--- a/base/util/src/com/netscape/cmsutil/util/Utils.java
+++ b/base/util/src/com/netscape/cmsutil/util/Utils.java
@@ -90,7 +90,7 @@ public class Utils {
         } catch (IOException e) {
             e.printStackTrace();
         } catch (InterruptedException e) {
-            e.printStackTrace();
+            Thread.currentThread().interrupt();
         }
         return false;
     }
diff --git a/base/util/src/netscape/security/util/ExtPrettyPrint.java b/base/util/src/netscape/security/util/ExtPrettyPrint.java
index 05556525516e4140cf99d922fa89db3935664624..0788e1905052fe900118a8d4c32cd93846d03faf 100644
--- a/base/util/src/netscape/security/util/ExtPrettyPrint.java
+++ b/base/util/src/netscape/security/util/ExtPrettyPrint.java
@@ -255,74 +255,62 @@ public class ExtPrettyPrint {
     private String getNSCCommentExtension() {
         StringBuffer sb = new StringBuffer();
 
-        try {
-            sb.append(pp.indent(mIndentSize) + mResource.getString(
-                    PrettyPrintResources.TOKEN_IDENTIFIER));
-            sb.append(mResource.getString(PrettyPrintResources.TOKEN_NSC_COMMENT) +
-                    "- " + mExt.getExtensionId().toString() + "\n");
-            sb.append(pp.indent(mIndentSize + 4) + mResource.getString(
-                    PrettyPrintResources.TOKEN_CRITICAL));
-            if (mExt.isCritical()) {
-                sb.append(mResource.getString(
-                        PrettyPrintResources.TOKEN_YES) + "\n");
-            } else {
-                sb.append(mResource.getString(
-                        PrettyPrintResources.TOKEN_NO) + "\n");
-            }
-            sb.append(pp.indent(mIndentSize + 4) + ((NSCCommentExtension) mExt).toPrint(mIndentSize) + "\n");
-            return sb.toString();
-        } catch (Exception e) {
-            return sb.toString();
+        sb.append(pp.indent(mIndentSize) + mResource.getString(
+                PrettyPrintResources.TOKEN_IDENTIFIER));
+        sb.append(mResource.getString(PrettyPrintResources.TOKEN_NSC_COMMENT) +
+                "- " + mExt.getExtensionId().toString() + "\n");
+        sb.append(pp.indent(mIndentSize + 4) + mResource.getString(
+                PrettyPrintResources.TOKEN_CRITICAL));
+        if (mExt.isCritical()) {
+            sb.append(mResource.getString(
+                    PrettyPrintResources.TOKEN_YES) + "\n");
+        } else {
+            sb.append(mResource.getString(
+                    PrettyPrintResources.TOKEN_NO) + "\n");
         }
+        sb.append(pp.indent(mIndentSize + 4) + ((NSCCommentExtension) mExt).toPrint(mIndentSize) + "\n");
+        return sb.toString();
     }
 
     private String getNameConstraintsExtension() {
         StringBuffer sb = new StringBuffer();
 
-        try {
-            sb.append(pp.indent(mIndentSize) + mResource.getString(
-                    PrettyPrintResources.TOKEN_IDENTIFIER));
-            sb.append(mResource.getString(PrettyPrintResources.TOKEN_NAME_CONSTRAINTS) +
-                    "- " + mExt.getExtensionId().toString() + "\n");
-            sb.append(pp.indent(mIndentSize + 4) + mResource.getString(
-                    PrettyPrintResources.TOKEN_CRITICAL));
-            if (mExt.isCritical()) {
-                sb.append(mResource.getString(
-                        PrettyPrintResources.TOKEN_YES) + "\n");
-            } else {
-                sb.append(mResource.getString(
-                        PrettyPrintResources.TOKEN_NO) + "\n");
-            }
-
-            sb.append(pp.indent(mIndentSize + 4) + ((NameConstraintsExtension) mExt).toPrint(mIndentSize + 4));
-
-            return sb.toString();
-        } catch (Exception e) {
-            return sb.toString();
+        sb.append(pp.indent(mIndentSize) + mResource.getString(
+                PrettyPrintResources.TOKEN_IDENTIFIER));
+        sb.append(mResource.getString(PrettyPrintResources.TOKEN_NAME_CONSTRAINTS) +
+                "- " + mExt.getExtensionId().toString() + "\n");
+        sb.append(pp.indent(mIndentSize + 4) + mResource.getString(
+                PrettyPrintResources.TOKEN_CRITICAL));
+        if (mExt.isCritical()) {
+            sb.append(mResource.getString(
+                    PrettyPrintResources.TOKEN_YES) + "\n");
+        } else {
+            sb.append(mResource.getString(
+                    PrettyPrintResources.TOKEN_NO) + "\n");
         }
+
+        sb.append(pp.indent(mIndentSize + 4) + ((NameConstraintsExtension) mExt).toPrint(mIndentSize + 4));
+
+        return sb.toString();
     }
 
     private String getOCSPNoCheckExtension() {
         StringBuffer sb = new StringBuffer();
 
-        try {
-            sb.append(pp.indent(mIndentSize) + mResource.getString(
-                    PrettyPrintResources.TOKEN_IDENTIFIER));
-            sb.append(mResource.getString(PrettyPrintResources.TOKEN_OCSP_NOCHECK) +
-                    "- " + mExt.getExtensionId().toString() + "\n");
-            sb.append(pp.indent(mIndentSize + 4) + mResource.getString(
-                    PrettyPrintResources.TOKEN_CRITICAL));
-            if (mExt.isCritical()) {
-                sb.append(mResource.getString(
-                        PrettyPrintResources.TOKEN_YES) + "\n");
-            } else {
-                sb.append(mResource.getString(
-                        PrettyPrintResources.TOKEN_NO) + "\n");
-            }
-            return sb.toString();
-        } catch (Exception e) {
-            return sb.toString();
+        sb.append(pp.indent(mIndentSize) + mResource.getString(
+                PrettyPrintResources.TOKEN_IDENTIFIER));
+        sb.append(mResource.getString(PrettyPrintResources.TOKEN_OCSP_NOCHECK) +
+                "- " + mExt.getExtensionId().toString() + "\n");
+        sb.append(pp.indent(mIndentSize + 4) + mResource.getString(
+                PrettyPrintResources.TOKEN_CRITICAL));
+        if (mExt.isCritical()) {
+            sb.append(mResource.getString(
+                    PrettyPrintResources.TOKEN_YES) + "\n");
+        } else {
+            sb.append(mResource.getString(
+                    PrettyPrintResources.TOKEN_NO) + "\n");
         }
+        return sb.toString();
     }
 
     private String getSubjectInfoAccessExtension() {
@@ -816,7 +804,8 @@ public class ExtPrettyPrint {
             }
 
             return sb.toString();
-        } catch (Exception e) {
+        } catch (IOException e) {
+            e.printStackTrace();
             return "";
         }
     }
@@ -848,7 +837,8 @@ public class ExtPrettyPrint {
             }
 
             return sb.toString();
-        } catch (Exception e) {
+        } catch (IOException e) {
+            e.printStackTrace();
             return "";
         }
     }
@@ -1269,27 +1259,23 @@ public class ExtPrettyPrint {
     private String getInvalidityDateExtension() {
         StringBuffer sb = new StringBuffer();
 
-        try {
-            sb.append(pp.indent(mIndentSize) + mResource.getString(
-                    PrettyPrintResources.TOKEN_IDENTIFIER));
-            sb.append(mResource.getString(PrettyPrintResources.TOKEN_INVALIDITY_DATE) +
-                    "- " + mExt.getExtensionId().toString() + "\n");
-            sb.append(pp.indent(mIndentSize + 4) + mResource.getString(
-                    PrettyPrintResources.TOKEN_CRITICAL));
-            InvalidityDateExtension ext = (InvalidityDateExtension) mExt;
+        sb.append(pp.indent(mIndentSize) + mResource.getString(
+                PrettyPrintResources.TOKEN_IDENTIFIER));
+        sb.append(mResource.getString(PrettyPrintResources.TOKEN_INVALIDITY_DATE) +
+                "- " + mExt.getExtensionId().toString() + "\n");
+        sb.append(pp.indent(mIndentSize + 4) + mResource.getString(
+                PrettyPrintResources.TOKEN_CRITICAL));
+        InvalidityDateExtension ext = (InvalidityDateExtension) mExt;
 
-            if (mExt.isCritical()) {
-                sb.append(mResource.getString(PrettyPrintResources.TOKEN_YES) + "\n");
-            } else {
-                sb.append(mResource.getString(PrettyPrintResources.TOKEN_NO) + "\n");
-            }
-            sb.append(pp.indent(mIndentSize + 4) + mResource.getString(
-                    PrettyPrintResources.TOKEN_DATE_OF_INVALIDITY) +
-                    ext.getInvalidityDate().toString() + "\n");
-            return sb.toString();
-        } catch (Exception e) {
-            return "";
+        if (mExt.isCritical()) {
+            sb.append(mResource.getString(PrettyPrintResources.TOKEN_YES) + "\n");
+        } else {
+            sb.append(mResource.getString(PrettyPrintResources.TOKEN_NO) + "\n");
         }
+        sb.append(pp.indent(mIndentSize + 4) + mResource.getString(
+                PrettyPrintResources.TOKEN_DATE_OF_INVALIDITY) +
+                ext.getInvalidityDate().toString() + "\n");
+        return sb.toString();
     }
 
     /**
@@ -1345,27 +1331,23 @@ public class ExtPrettyPrint {
     private String getHoldInstructionExtension() {
         StringBuffer sb = new StringBuffer();
 
-        try {
-            sb.append(pp.indent(mIndentSize) + mResource.getString(
-                    PrettyPrintResources.TOKEN_IDENTIFIER));
-            sb.append(mResource.getString(PrettyPrintResources.TOKEN_HOLD_INSTRUCTION) +
-                    "- " + mExt.getExtensionId().toString() + "\n");
-            sb.append(pp.indent(mIndentSize + 4) + mResource.getString(
-                    PrettyPrintResources.TOKEN_CRITICAL));
-            HoldInstructionExtension ext = (HoldInstructionExtension) mExt;
+        sb.append(pp.indent(mIndentSize) + mResource.getString(
+                PrettyPrintResources.TOKEN_IDENTIFIER));
+        sb.append(mResource.getString(PrettyPrintResources.TOKEN_HOLD_INSTRUCTION) +
+                "- " + mExt.getExtensionId().toString() + "\n");
+        sb.append(pp.indent(mIndentSize + 4) + mResource.getString(
+                PrettyPrintResources.TOKEN_CRITICAL));
+        HoldInstructionExtension ext = (HoldInstructionExtension) mExt;
 
-            if (mExt.isCritical()) {
-                sb.append(mResource.getString(PrettyPrintResources.TOKEN_YES) + "\n");
-            } else {
-                sb.append(mResource.getString(PrettyPrintResources.TOKEN_NO) + "\n");
-            }
-            sb.append(pp.indent(mIndentSize + 4) + mResource.getString(
-                    PrettyPrintResources.TOKEN_HOLD_INSTRUCTION_CODE) +
-                    ext.getHoldInstructionCodeDescription() + "\n");
-            return sb.toString();
-        } catch (Exception e) {
-            return "";
+        if (mExt.isCritical()) {
+            sb.append(mResource.getString(PrettyPrintResources.TOKEN_YES) + "\n");
+        } else {
+            sb.append(mResource.getString(PrettyPrintResources.TOKEN_NO) + "\n");
         }
+        sb.append(pp.indent(mIndentSize + 4) + mResource.getString(
+                PrettyPrintResources.TOKEN_HOLD_INSTRUCTION_CODE) +
+                ext.getHoldInstructionCodeDescription() + "\n");
+        return sb.toString();
     }
 
     /**
@@ -1374,43 +1356,39 @@ public class ExtPrettyPrint {
     private String getPolicyConstraintsExtension() {
         StringBuffer sb = new StringBuffer();
 
-        try {
-            sb.append(pp.indent(mIndentSize) + mResource.getString(
-                    PrettyPrintResources.TOKEN_IDENTIFIER));
-            sb.append(
-                    mResource.getString(
-                            PrettyPrintResources.TOKEN_POLICY_CONSTRAINTS) +
-                            "- " + mExt.getExtensionId().toString() + "\n");
-            sb.append(pp.indent(mIndentSize + 4) + mResource.getString(
-                    PrettyPrintResources.TOKEN_CRITICAL));
-            if (mExt.isCritical()) {
-                sb.append(mResource.getString(PrettyPrintResources.TOKEN_YES) + "\n");
-            } else {
-                sb.append(mResource.getString(PrettyPrintResources.TOKEN_NO) + "\n");
-            }
-
-            PolicyConstraintsExtension ext = (PolicyConstraintsExtension) mExt;
-            int require = ext.getRequireExplicitMapping();
-            int inhibit = ext.getInhibitPolicyMapping();
-
-            sb.append(
-                    pp.indent(mIndentSize + 4) +
-                            mResource.getString(
-                                    PrettyPrintResources.TOKEN_REQUIRE_EXPLICIT_POLICY) +
-                            ((require == -1) ?
-                                    mResource.getString(PrettyPrintResources.TOKEN_NOT_SET) :
-                                    String.valueOf(require)) + "\n");
-            sb.append(
-                    pp.indent(mIndentSize + 4) +
-                            mResource.getString(
-                                    PrettyPrintResources.TOKEN_INHIBIT_POLICY_MAPPING) +
-                            ((inhibit == -1) ?
-                                    mResource.getString(PrettyPrintResources.TOKEN_NOT_SET) :
-                                    String.valueOf(inhibit)) + "\n");
-            return sb.toString();
-        } catch (Exception e) {
-            return "";
+        sb.append(pp.indent(mIndentSize) + mResource.getString(
+                PrettyPrintResources.TOKEN_IDENTIFIER));
+        sb.append(
+                mResource.getString(
+                        PrettyPrintResources.TOKEN_POLICY_CONSTRAINTS) +
+                        "- " + mExt.getExtensionId().toString() + "\n");
+        sb.append(pp.indent(mIndentSize + 4) + mResource.getString(
+                PrettyPrintResources.TOKEN_CRITICAL));
+        if (mExt.isCritical()) {
+            sb.append(mResource.getString(PrettyPrintResources.TOKEN_YES) + "\n");
+        } else {
+            sb.append(mResource.getString(PrettyPrintResources.TOKEN_NO) + "\n");
         }
+
+        PolicyConstraintsExtension ext = (PolicyConstraintsExtension) mExt;
+        int require = ext.getRequireExplicitMapping();
+        int inhibit = ext.getInhibitPolicyMapping();
+
+        sb.append(
+                pp.indent(mIndentSize + 4) +
+                        mResource.getString(
+                                PrettyPrintResources.TOKEN_REQUIRE_EXPLICIT_POLICY) +
+                        ((require == -1) ?
+                                mResource.getString(PrettyPrintResources.TOKEN_NOT_SET) :
+                                String.valueOf(require)) + "\n");
+        sb.append(
+                pp.indent(mIndentSize + 4) +
+                        mResource.getString(
+                                PrettyPrintResources.TOKEN_INHIBIT_POLICY_MAPPING) +
+                        ((inhibit == -1) ?
+                                mResource.getString(PrettyPrintResources.TOKEN_NOT_SET) :
+                                String.valueOf(inhibit)) + "\n");
+        return sb.toString();
     }
 
     /**
-- 
1.7.10.2

