diff -r 4ddff5909b4f -r 3176f6c55af1 jdk/src/java.naming/share/classes/com/sun/jndi/ldap/LdapCtx.java --- a/jdk/src/java.naming/share/classes/com/sun/jndi/ldap/LdapCtx.java Mon Apr 11 12:27:48 2016 +0800 +++ b/jdk/src/java.naming/share/classes/com/sun/jndi/ldap/LdapCtx.java Mon Apr 11 08:00:21 2016 +0100 @@ -2978,7 +2978,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); @@ -3047,7 +3048,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);