changeset 8470:fe453cb558d3

8149450: LdapCtx.processReturnCode() throwing Null Pointer Exception Reviewed-by: xuelei
author coffeys
date Mon, 11 Apr 2016 08:00:21 +0100
parents c54643d2a32b
children 4092c1c94820
files src/share/classes/com/sun/jndi/ldap/LdapCtx.java src/share/classes/com/sun/jndi/ldap/LdapReferralException.java
diffstat 2 files changed, 10 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/src/share/classes/com/sun/jndi/ldap/LdapCtx.java	Tue Jul 18 06:45:42 2017 +0100
+++ b/src/share/classes/com/sun/jndi/ldap/LdapCtx.java	Mon Apr 11 08:00:21 2016 +0100
@@ -2975,7 +2975,8 @@
             r = new LdapReferralException(resolvedName, resolvedObj, remainName,
                 msg, envprops, fullDN, handleReferrals, reqCtls);
             // only one set of URLs is present
-            r.setReferralInfo(res.referrals.elementAt(0), false);
+            r.setReferralInfo(res.referrals == null ? null :
+                    res.referrals.elementAt(0), false);
 
             if (hopCount > 1) {
                 r.setHopCount(hopCount);
@@ -3044,7 +3045,7 @@
              *     assume name resolution has not yet completed.
              */
             if (((res.entries == null) || (res.entries.isEmpty())) &&
-                (res.referrals.size() == 1)) {
+                ((res.referrals != null) && (res.referrals.size() == 1))) {
 
                 r.setReferralInfo(res.referrals, false);
 
--- a/src/share/classes/com/sun/jndi/ldap/LdapReferralException.java	Tue Jul 18 06:45:42 2017 +0100
+++ b/src/share/classes/com/sun/jndi/ldap/LdapReferralException.java	Mon Apr 11 08:00:21 2016 +0100
@@ -217,13 +217,15 @@
             System.out.println("LdapReferralException.setReferralInfo");
 
         this.referrals = referrals;
-        if (referrals != null) {
-            referralCount = referrals.size();
-        }
+        referralCount = (referrals == null) ? 0 : referrals.size();
 
         if (debug) {
-            for (int i = 0; i < referralCount; i++) {
-                System.out.println("  [" + i + "] " + referrals.elementAt(i));
+            if (referrals != null) {
+                for (int i = 0; i < referralCount; i++) {
+                    System.out.println("  [" + i + "] " + referrals.elementAt(i));
+                }
+            } else {
+                System.out.println("setReferralInfo : referrals == null");
             }
         }
     }