>From 77acc4e8822bd3740dcc17e64053c4ebd3ba451d Mon Sep 17 00:00:00 2001
From: Abhishek Koneru <akoneru@redhat.com>
Date: Thu, 28 Jun 2012 10:51:58 -0400
Subject: [PATCH] Fixes for Review Comments for PATCH 17

---
 base/common/src/com/netscape/cmscore/dbs/BigIntegerMapper.java  |    7 ++++---
 base/common/src/com/netscape/cmscore/dbs/DateArrayMapper.java   |    6 +++---
 base/common/src/com/netscape/cmscore/dbs/KeyRecordMapper.java   |    2 +-
 base/common/src/com/netscape/cmscore/dbs/LongMapper.java        |    3 ---
 base/common/src/com/netscape/cmscore/request/RequestRecord.java |    7 +++----
 5 files changed, 11 insertions(+), 14 deletions(-)

diff --git a/base/common/src/com/netscape/cmscore/dbs/BigIntegerMapper.java b/base/common/src/com/netscape/cmscore/dbs/BigIntegerMapper.java
index d59f081db71800d0ea54d7bf34cb28c43b828394..7d92c79cda3b9733f8c32b2fcdc80fde911b32d7 100644
--- a/base/common/src/com/netscape/cmscore/dbs/BigIntegerMapper.java
+++ b/base/common/src/com/netscape/cmscore/dbs/BigIntegerMapper.java
@@ -24,6 +24,7 @@ import java.util.Vector;
 import netscape.ldap.LDAPAttribute;
 import netscape.ldap.LDAPAttributeSet;
 
+import com.netscape.certsrv.apps.CMS;
 import com.netscape.certsrv.base.EBaseException;
 import com.netscape.certsrv.dbs.IDBAttrMapper;
 import com.netscape.certsrv.dbs.IDBObj;
@@ -62,6 +63,9 @@ public class BigIntegerMapper implements IDBAttrMapper {
     public void mapObjectToLDAPAttributeSet(IDBObj parent,
             String name, Object obj, LDAPAttributeSet attrs)
             throws EBaseException {
+        if (obj == null) {
+            throw new EBaseException(CMS.getUserMessage("CMS_DBS_SERIALIZE_FAILED", name));
+        }
         attrs.add(new LDAPAttribute(mLdapName,
                 BigIntegerToDB((BigInteger) obj)));
     }
@@ -101,9 +105,6 @@ public class BigIntegerMapper implements IDBAttrMapper {
     }
 
     public static String BigIntegerToDB(BigInteger i) {
-        if (i == null) {
-            return null;
-        }
         int len = i.toString().length();
         String ret = null;
 
diff --git a/base/common/src/com/netscape/cmscore/dbs/DateArrayMapper.java b/base/common/src/com/netscape/cmscore/dbs/DateArrayMapper.java
index 7e55222f4d5b127b4b95a1e4fc2697039241c4e1..99d54be60ea788f7ac25abaf252f6286f92940f2 100644
--- a/base/common/src/com/netscape/cmscore/dbs/DateArrayMapper.java
+++ b/base/common/src/com/netscape/cmscore/dbs/DateArrayMapper.java
@@ -63,10 +63,10 @@ public class DateArrayMapper implements IDBAttrMapper {
     public void mapObjectToLDAPAttributeSet(IDBObj parent,
             String name, Object obj, LDAPAttributeSet attrs)
             throws EBaseException {
-        Date dates[] = (Date[]) obj;
-
-        if (dates == null)
+        if (obj == null)
             throw new EBaseException(CMS.getUserMessage("CMS_DBS_SERIALIZE_FAILED", name));
+        Date dates[] = (Date[]) obj;
+
         LDAPAttribute attr = new LDAPAttribute(mLdapName);
 
         for (int i = 0; i < dates.length; i++) {
diff --git a/base/common/src/com/netscape/cmscore/dbs/KeyRecordMapper.java b/base/common/src/com/netscape/cmscore/dbs/KeyRecordMapper.java
index 8cf2c12ebece8c0129dff54af5c5283dd98d0f1c..b124857ca0c77054fb581e0228d6ddf01a8ccbae 100644
--- a/base/common/src/com/netscape/cmscore/dbs/KeyRecordMapper.java
+++ b/base/common/src/com/netscape/cmscore/dbs/KeyRecordMapper.java
@@ -59,7 +59,7 @@ public class KeyRecordMapper implements IDBAttrMapper {
 
     public void mapObjectToLDAPAttributeSet(IDBObj parent, String name,
             Object obj, LDAPAttributeSet attrs) throws EBaseException {
-        if(obj == null){
+        if (obj == null) {
             throw new EBaseException(CMS.getUserMessage("CMS_DBS_SERIALIZE_FAILED", name));
         }
         try {
diff --git a/base/common/src/com/netscape/cmscore/dbs/LongMapper.java b/base/common/src/com/netscape/cmscore/dbs/LongMapper.java
index 2fece86aecd7ddbc10a784508455851430bb762f..3c066ca43c60ab0f09a7eff6dbd7ae51da368ecd 100644
--- a/base/common/src/com/netscape/cmscore/dbs/LongMapper.java
+++ b/base/common/src/com/netscape/cmscore/dbs/LongMapper.java
@@ -103,9 +103,6 @@ public class LongMapper implements IDBAttrMapper {
     }
 
     public static String LongToDB(Long i) {
-        if (i == null) {
-            return null;
-        }
         int len = i.toString().length();
         String ret = null;
 
diff --git a/base/common/src/com/netscape/cmscore/request/RequestRecord.java b/base/common/src/com/netscape/cmscore/request/RequestRecord.java
index 2c81a1354e3511c2f8dcd08b3fb8ab436fbe7e4e..023dd9478a0fdbc3f150b1a590fa9357b598afaa 100644
--- a/base/common/src/com/netscape/cmscore/request/RequestRecord.java
+++ b/base/common/src/com/netscape/cmscore/request/RequestRecord.java
@@ -498,18 +498,15 @@ class RequestAttrsMapper
             }
 
             os.writeObject(null);
-            os.flush();
 
-            attrs.add(new LDAPAttribute(Schema.LDAP_ATTR_REQUEST_ATTRS,
-                    bos.toByteArray()));
         } catch (Exception x) {
             if (parent != null)
                 Debug.trace("Output Mapping Error in requeset ID " +
                         ((RequestRecord) parent).getRequestId().toString() + " : " + x);
             //if (Debug.ON) {
             Debug.printStackTrace(x);
-            throw new EBaseException(CMS.getUserMessage("CMS_DBS_SERIALIZE_FAILED", name));
             //}
+            throw new EBaseException(CMS.getUserMessage("CMS_DBS_SERIALIZE_FAILED", name));
         } finally {
             if (os != null) {
                 try {
@@ -526,6 +523,8 @@ class RequestAttrsMapper
                 }
             }
         }
+        attrs.add(new LDAPAttribute(Schema.LDAP_ATTR_REQUEST_ATTRS,
+                bos.toByteArray()));
     }
 
     private byte[] encode(Object value)
-- 
1.7.10.2

