diff --git a/jdk/src/java.naming/share/classes/com/sun/jndi/ldap/LdapCtx.java b/jdk/src/java.naming/share/classes/com/sun/jndi/ldap/LdapCtx.java index 0e44f735a97..5308478c9f9 100644 --- a/jdk/src/java.naming/share/classes/com/sun/jndi/ldap/LdapCtx.java +++ b/jdk/src/java.naming/share/classes/com/sun/jndi/ldap/LdapCtx.java @@ -2978,7 +2978,8 @@ final public class LdapCtx extends ComponentDirContext 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); @@ -3047,7 +3048,7 @@ final public class LdapCtx extends ComponentDirContext * 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); diff --git a/jdk/src/java.naming/share/classes/com/sun/jndi/ldap/LdapReferralException.java b/jdk/src/java.naming/share/classes/com/sun/jndi/ldap/LdapReferralException.java index 4b3e06d9285..62437c77657 100644 --- a/jdk/src/java.naming/share/classes/com/sun/jndi/ldap/LdapReferralException.java +++ b/jdk/src/java.naming/share/classes/com/sun/jndi/ldap/LdapReferralException.java @@ -217,13 +217,15 @@ final public class LdapReferralException extends 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"); } } }