--- old/src/share/classes/com/sun/jndi/ldap/LdapClient.java 2011-07-27 17:19:56.530370900 -0700 +++ new/src/share/classes/com/sun/jndi/ldap/LdapClient.java 2011-07-27 17:19:55.876305500 -0700 @@ -25,7 +25,6 @@ package com.sun.jndi.ldap; -import java.net.*; import java.io.*; import java.util.Vector; import java.util.Hashtable; @@ -81,7 +80,8 @@ static final boolean caseIgnore = true; // Default list of binary attributes - private static final Hashtable defaultBinaryAttrs = new Hashtable(23,0.75f); + private static final Hashtable defaultBinaryAttrs = + new Hashtable<>(23,0.75f); static { defaultBinaryAttrs.put("userpassword", Boolean.TRUE); //2.5.4.35 defaultBinaryAttrs.put("javaserializeddata", Boolean.TRUE); @@ -146,7 +146,7 @@ synchronized LdapResult authenticate(boolean initial, String name, Object pw, int version, - String authMechanism, Control[] ctls, Hashtable env) + String authMechanism, Control[] ctls, Hashtable env) throws NamingException { authenticateCalled = true; @@ -516,8 +516,8 @@ LdapResult search(String dn, int scope, int deref, int sizeLimit, int timeLimit, boolean attrsOnly, String attrs[], String filter, int batchSize, Control[] reqCtls, - Hashtable binaryAttrs, boolean waitFirstReply, - int replyQueueCapacity) + Hashtable binaryAttrs, + boolean waitFirstReply, int replyQueueCapacity) throws IOException, NamingException { ensureOpen(); @@ -586,7 +586,7 @@ * Retrieve the next batch of entries and/or referrals. */ LdapResult getSearchReply(int batchSize, LdapResult res, - Hashtable binaryAttrs) throws IOException, NamingException { + Hashtable binaryAttrs) throws IOException, NamingException { ensureOpen(); @@ -600,7 +600,7 @@ } private LdapResult getSearchReply(LdapRequest req, - int batchSize, LdapResult res, Hashtable binaryAttrs) + int batchSize, LdapResult res, Hashtable binaryAttrs) throws IOException, NamingException { if (batchSize == 0) @@ -610,7 +610,7 @@ res.entries.setSize(0); // clear the (previous) set of entries } else { res.entries = - new Vector(batchSize == Integer.MAX_VALUE ? 32 : batchSize); + new Vector<>(batchSize == Integer.MAX_VALUE ? 32 : batchSize); } if (res.referrals != null) { @@ -660,7 +660,7 @@ } else if ((seq == LDAP_REP_SEARCH_REF) && isLdapv3) { // handle LDAPv3 search reference - Vector URLs = new Vector(4); + Vector URLs = new Vector<>(4); // %%% Although not strictly correct, some LDAP servers // encode the SEQUENCE OF tag in the SearchResultRef @@ -676,7 +676,7 @@ } if (res.referrals == null) { - res.referrals = new Vector(4); + res.referrals = new Vector<>(4); } res.referrals.addElement(URLs); res.resControls = isLdapv3 ? parseControls(replyBer) : null; @@ -700,7 +700,8 @@ return res; } - private Attribute parseAttribute(BerDecoder ber, Hashtable binaryAttrs) + private Attribute parseAttribute(BerDecoder ber, + Hashtable binaryAttrs) throws IOException { int len[] = new int[1]; @@ -742,7 +743,8 @@ return len[0]; } - private boolean isBinaryValued(String attrid, Hashtable binaryAttrs) { + private boolean isBinaryValued(String attrid, + Hashtable binaryAttrs) { String id = attrid.toLowerCase(); return ((id.indexOf(";binary") != -1) || @@ -763,7 +765,7 @@ (replyBer.bytesLeft() > 0) && (replyBer.peekByte() == LDAP_REP_REFERRAL)) { - Vector URLs = new Vector(4); + Vector URLs = new Vector<>(4); int[] seqlen = new int[1]; replyBer.parseSeq(seqlen); @@ -775,18 +777,18 @@ } if (res.referrals == null) { - res.referrals = new Vector(4); + res.referrals = new Vector<>(4); } res.referrals.addElement(URLs); } } // package entry point; used by Connection - static Vector parseControls(BerDecoder replyBer) throws IOException { + static Vector parseControls(BerDecoder replyBer) throws IOException { // handle LDAPv3 controls (if present) if ((replyBer.bytesLeft() > 0) && (replyBer.peekByte() == LDAP_CONTROLS)) { - Vector ctls = new Vector(4); + Vector ctls = new Vector<>(4); String controlOID; boolean criticality = false; // default byte[] controlValue = null; // optional @@ -957,7 +959,7 @@ ber.beginSeq(Ber.ASN_SEQUENCE | Ber.ASN_CONSTRUCTOR); ber.encodeString(attr.getID(), isLdapv3); ber.beginSeq(Ber.ASN_SEQUENCE | Ber.ASN_CONSTRUCTOR | 1); - NamingEnumeration enum_ = attr.getAll(); + NamingEnumeration enum_ = attr.getAll(); Object val; while (enum_.hasMore()) { val = enum_.next(); @@ -1007,9 +1009,10 @@ ber.beginSeq(LDAP_REQ_ADD); ber.encodeString(entry.DN, isLdapv3); ber.beginSeq(Ber.ASN_SEQUENCE | Ber.ASN_CONSTRUCTOR); - NamingEnumeration enum_ = entry.attributes.getAll(); + NamingEnumeration enum_ = + entry.attributes.getAll(); while (enum_.hasMore()) { - attr = (Attribute)enum_.next(); + attr = enum_.next(); // zero values is not permitted if (hasNoValue(attr)) { @@ -1474,7 +1477,7 @@ // removeUnsolicited() is invoked to remove an LdapCtx from this client. // //////////////////////////////////////////////////////////////////////////// - private Vector unsolicited = new Vector(3); + private Vector unsolicited = new Vector<>(3); void addUnsolicited(LdapCtx ctx) { if (debug > 0) { System.err.println("LdapClient.addUnsolicited" + ctx); @@ -1500,70 +1503,70 @@ if (debug > 0) { System.err.println("LdapClient.processUnsolicited"); } - synchronized (unsolicited) { - try { - // Parse the response - LdapResult res = new LdapResult(); - - ber.parseSeq(null); // init seq - ber.parseInt(); // msg id; should be 0; ignored - if (ber.parseByte() != LDAP_REP_EXTENSION) { - throw new IOException( - "Unsolicited Notification must be an Extended Response"); - } - ber.parseLength(); - parseExtResponse(ber, res); - - if (DISCONNECT_OID.equals(res.extensionId)) { - // force closing of connection - forceClose(pooled); - } - - if (unsolicited.size() > 0) { - // Create an UnsolicitedNotification using the parsed data - // Need a 'ctx' object because we want to use the context's - // list of provider control factories. - UnsolicitedNotification notice = new UnsolicitedResponseImpl( - res.extensionId, - res.extensionValue, - res.referrals, - res.status, - res.errorMessage, - res.matchedDN, - (res.resControls != null) ? - ((LdapCtx)unsolicited.elementAt(0)).convertControls(res.resControls) : - null); + synchronized (unsolicited) { + try { + // Parse the response + LdapResult res = new LdapResult(); - // Fire UnsolicitedNotification events to listeners - notifyUnsolicited(notice); + ber.parseSeq(null); // init seq + ber.parseInt(); // msg id; should be 0; ignored + if (ber.parseByte() != LDAP_REP_EXTENSION) { + throw new IOException( + "Unsolicited Notification must be an Extended Response"); + } + ber.parseLength(); + parseExtResponse(ber, res); - // If "disconnect" notification, - // notify unsolicited listeners via NamingException if (DISCONNECT_OID.equals(res.extensionId)) { - notifyUnsolicited( - new CommunicationException("Connection closed")); + // force closing of connection + forceClose(pooled); } - } - } catch (IOException e) { - if (unsolicited.size() == 0) - return; // no one registered; ignore - NamingException ne = new CommunicationException( - "Problem parsing unsolicited notification"); - ne.setRootCause(e); + if (unsolicited.size() > 0) { + // Create an UnsolicitedNotification using the parsed data + // Need a 'ctx' object because we want to use the context's + // list of provider control factories. + UnsolicitedNotification notice = new UnsolicitedResponseImpl( + res.extensionId, + res.extensionValue, + res.referrals, + res.status, + res.errorMessage, + res.matchedDN, + (res.resControls != null) ? + unsolicited.elementAt(0).convertControls(res.resControls) : + null); + + // Fire UnsolicitedNotification events to listeners + notifyUnsolicited(notice); + + // If "disconnect" notification, + // notify unsolicited listeners via NamingException + if (DISCONNECT_OID.equals(res.extensionId)) { + notifyUnsolicited( + new CommunicationException("Connection closed")); + } + } + } catch (IOException e) { + if (unsolicited.size() == 0) + return; // no one registered; ignore - notifyUnsolicited(ne); + NamingException ne = new CommunicationException( + "Problem parsing unsolicited notification"); + ne.setRootCause(e); + + notifyUnsolicited(ne); - } catch (NamingException e) { - notifyUnsolicited(e); + } catch (NamingException e) { + notifyUnsolicited(e); + } } - } } private void notifyUnsolicited(Object e) { for (int i = 0; i < unsolicited.size(); i++) { - ((LdapCtx)unsolicited.elementAt(i)).fireUnsolicited(e); + unsolicited.elementAt(i).fireUnsolicited(e); } if (e instanceof NamingException) { unsolicited.setSize(0); // no more listeners after exception @@ -1584,7 +1587,7 @@ static LdapClient getInstance(boolean usePool, String hostname, int port, String factory, int connectTimeout, int readTimeout, OutputStream trace, int version, String authMechanism, Control[] ctls, String protocol, - String user, Object passwd, Hashtable env) throws NamingException { + String user, Object passwd, Hashtable env) throws NamingException { if (usePool) { if (LdapPoolManager.isPoolingAllowed(factory, trace,