--- old/make/com/sun/jndi/Makefile 2011-07-27 17:17:29.404659800 -0700 +++ new/make/com/sun/jndi/Makefile 2011-07-27 17:17:28.763595700 -0700 @@ -28,6 +28,8 @@ # BUILDDIR = ../../.. +SUBDIRS_MAKEFLAGS += JAVAC_MAX_WARNINGS=true +SUBDIRS_MAKEFLAGS += JAVAC_WARNINGS_FATAL=true include $(BUILDDIR)/common/Defs.gmk SUBDIRS = toolkit cosnaming ldap rmi dns --- old/make/javax/others/Makefile 2011-07-27 17:17:36.241343400 -0700 +++ new/make/javax/others/Makefile 2011-07-27 17:17:35.631282400 -0700 @@ -28,6 +28,7 @@ # BUILDDIR = ../.. +JAVAC_MAX_WARNINGS = true include $(BUILDDIR)/common/Defs.gmk # --- old/src/share/classes/com/sun/jndi/cosnaming/CNBindingEnumeration.java 2011-07-27 17:17:42.591978400 -0700 +++ new/src/share/classes/com/sun/jndi/cosnaming/CNBindingEnumeration.java 2011-07-27 17:17:41.940913300 -0700 @@ -32,8 +32,6 @@ import java.util.Hashtable; import org.omg.CosNaming.*; -import org.omg.CosNaming.NamingContextPackage.*; -import org.omg.CORBA.*; /** * Implements the JNDI NamingEnumeration interface for COS @@ -44,7 +42,8 @@ * @author Rosanna Lee */ -final class CNBindingEnumeration implements NamingEnumeration { +final class CNBindingEnumeration + implements NamingEnumeration { private static final int DEFAULT_BATCHSIZE = 100; private BindingListHolder _bindingList; // list of bindings @@ -52,105 +51,105 @@ private int counter; // pointer in _bindingList private int batchsize = DEFAULT_BATCHSIZE; // how many to ask for each time private CNCtx _ctx; // ctx to list - private Hashtable _env; // environment for getObjectInstance + private Hashtable _env; // environment for getObjectInstance private boolean more = false; // iterator done? private boolean isLookedUpCtx = false; // iterating on a context beneath this context ? - /** - * Creates a CNBindingEnumeration object. - * @param ctx Context to enumerate - */ - CNBindingEnumeration(CNCtx ctx, boolean isLookedUpCtx, Hashtable env) { - // Get batch size to use - String batch = (env != null ? - (String)env.get(javax.naming.Context.BATCHSIZE) : null); - if (batch != null) { - try { - batchsize = Integer.parseInt(batch); - } catch (NumberFormatException e) { - throw new IllegalArgumentException("Batch size not numeric: " + batch); - } - } - _ctx = ctx; - _ctx.incEnumCount(); - this.isLookedUpCtx = isLookedUpCtx; - _env = env; - _bindingList = new BindingListHolder(); - BindingIteratorHolder _bindingIterH = new BindingIteratorHolder(); - - // Perform listing and request that bindings be returned in _bindingIter - // Upon return,_bindingList returns a zero length list - _ctx._nc.list(0, _bindingList, _bindingIterH); - - _bindingIter = _bindingIterH.value; - - // Get first batch using _bindingIter - if (_bindingIter != null) { - more = _bindingIter.next_n(batchsize, _bindingList); - } else { - more = false; + /** + * Creates a CNBindingEnumeration object. + * @param ctx Context to enumerate + */ + CNBindingEnumeration(CNCtx ctx, boolean isLookedUpCtx, Hashtable env) { + // Get batch size to use + String batch = (env != null ? + (String)env.get(javax.naming.Context.BATCHSIZE) : null); + if (batch != null) { + try { + batchsize = Integer.parseInt(batch); + } catch (NumberFormatException e) { + throw new IllegalArgumentException("Batch size not numeric: " + batch); + } + } + _ctx = ctx; + _ctx.incEnumCount(); + this.isLookedUpCtx = isLookedUpCtx; + _env = env; + _bindingList = new BindingListHolder(); + BindingIteratorHolder _bindingIterH = new BindingIteratorHolder(); + + // Perform listing and request that bindings be returned in _bindingIter + // Upon return,_bindingList returns a zero length list + _ctx._nc.list(0, _bindingList, _bindingIterH); + + _bindingIter = _bindingIterH.value; + + // Get first batch using _bindingIter + if (_bindingIter != null) { + more = _bindingIter.next_n(batchsize, _bindingList); + } else { + more = false; + } + counter = 0; } - counter = 0; - } - /** - * Returns the next binding in the list. - * @exception NamingException any naming exception. - */ + /** + * Returns the next binding in the list. + * @exception NamingException any naming exception. + */ - public java.lang.Object next() throws NamingException { - if (more && counter >= _bindingList.value.length) { - getMore(); - } - if (more && counter < _bindingList.value.length) { - org.omg.CosNaming.Binding bndg = _bindingList.value[counter]; - counter++; - return mapBinding(bndg); - } else { - throw new NoSuchElementException(); - } - } + public javax.naming.Binding next() throws NamingException { + if (more && counter >= _bindingList.value.length) { + getMore(); + } + if (more && counter < _bindingList.value.length) { + org.omg.CosNaming.Binding bndg = _bindingList.value[counter]; + counter++; + return mapBinding(bndg); + } else { + throw new NoSuchElementException(); + } + } - /** + /** * Returns true or false depending on whether there are more bindings. * @return boolean value */ - public boolean hasMore() throws NamingException { - // If there's more, check whether current bindingList has been exhausted, - // and if so, try to get more. - // If no more, just say so. - return more ? (counter < _bindingList.value.length || getMore()) : false; - } + public boolean hasMore() throws NamingException { + // If there's more, check whether current bindingList has been exhausted, + // and if so, try to get more. + // If no more, just say so. + return more ? (counter < _bindingList.value.length || getMore()) : false; + } - /** - * Returns true or false depending on whether there are more bindings. - * Need to define this to satisfy the Enumeration api requirement. - * @return boolean value - */ + /** + * Returns true or false depending on whether there are more bindings. + * Need to define this to satisfy the Enumeration api requirement. + * @return boolean value + */ - public boolean hasMoreElements() { - try { - return hasMore(); - } catch (NamingException e) { - return false; - } - } + public boolean hasMoreElements() { + try { + return hasMore(); + } catch (NamingException e) { + return false; + } + } - /** + /** * Returns the next binding in the list. * @exception NoSuchElementException Thrown when the end of the * list is reached. */ - public java.lang.Object nextElement() { + public javax.naming.Binding nextElement() { try { return next(); } catch (NamingException ne) { throw new NoSuchElementException(); } - } + } public void close() throws NamingException { more = false; @@ -197,7 +196,7 @@ return more; } - /** + /** * Constructs a JNDI Binding object from the COS Naming binding * object. * @exception NameNotFound No objects under the name. @@ -232,5 +231,5 @@ String fullName = CNNameParser.cosNameToInsString(comps); jbndg.setNameInNamespace(fullName); return jbndg; - } + } } --- old/src/share/classes/com/sun/jndi/cosnaming/CNCtx.java 2011-07-27 17:17:48.718591000 -0700 +++ new/src/share/classes/com/sun/jndi/cosnaming/CNCtx.java 2011-07-27 17:17:48.055524700 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1999, 2005, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1999, 2011, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -30,7 +30,6 @@ import javax.naming.spi.ResolveResult; import java.util.Hashtable; -import java.util.Vector; import java.net.MalformedURLException; import java.net.URL; import java.io.InputStream; @@ -63,7 +62,7 @@ public NamingContext _nc; // public for accessing underlying NamingContext private NameComponent[] _name = null; - Hashtable _env; // used by ExceptionMapper + Hashtable _env; // used by ExceptionMapper static final CNNameParser parser = new CNNameParser(); private static final String FED_PROP = "com.sun.jndi.cosnaming.federation"; @@ -82,11 +81,12 @@ * @param env Environment properties for initializing name service. * @exception NamingException Cannot initialize ORB or naming context. */ - CNCtx(Hashtable env) throws NamingException { + @SuppressWarnings("unchecked") + CNCtx(Hashtable env) throws NamingException { if (env != null) { - env = (Hashtable) env.clone(); + env = (Hashtable)env.clone(); } - _env = env; + _env = (Hashtable)env; federation = "true".equals(env != null ? env.get(FED_PROP) : null); initOrbAndRootContext(env); } @@ -97,13 +97,14 @@ /** * This method is used by the iiop and iiopname URL Context factories. */ - public static ResolveResult createUsingURL(String url, Hashtable env) + @SuppressWarnings("unchecked") + public static ResolveResult createUsingURL(String url, Hashtable env) throws NamingException { CNCtx ctx = new CNCtx(); if (env != null) { - env = (Hashtable) env.clone(); + env = (Hashtable) env.clone(); } - ctx._env = env; + ctx._env = (Hashtable)env; String rest = ctx.initUsingUrl( env != null ? (org.omg.CORBA.ORB) env.get("java.naming.corba.orb") @@ -128,8 +129,8 @@ * @param name The name of this context relative to the root */ - CNCtx(ORB orb, OrbReuseTracker tracker, NamingContext nctx, Hashtable env, - NameComponent[]name) + CNCtx(ORB orb, OrbReuseTracker tracker, NamingContext nctx, + Hashtable env, NameComponent[]name) throws NamingException { if (orb == null || nctx == null) throw new ConfigurationException( @@ -207,7 +208,7 @@ * @exception NamingException When an error occurs while initializing the * ORB or the naming context. */ - private void initOrbAndRootContext(Hashtable env) throws NamingException { + private void initOrbAndRootContext(Hashtable env) throws NamingException { org.omg.CORBA.ORB inOrb = null; String ncIor = null; @@ -240,7 +241,7 @@ // If name supplied in URL, resolve it to a NamingContext if (insName.length() > 0) { - _name = parser.nameToCosName(parser.parse(insName)); + _name = CNNameParser.nameToCosName(parser.parse(insName)); try { org.omg.CORBA.Object obj = _nc.resolve(_name); _nc = NamingContextHelper.narrow(obj); @@ -271,7 +272,7 @@ } - private String initUsingUrl(ORB orb, String url, Hashtable env) + private String initUsingUrl(ORB orb, String url, Hashtable env) throws NamingException { if (url.startsWith("iiop://") || url.startsWith("iiopname://")) { return initUsingIiopUrl(orb, url, env); @@ -283,17 +284,14 @@ /** * Handles "iiop" and "iiopname" URLs (INS 98-10-11) */ - private String initUsingIiopUrl(ORB defOrb, String url, Hashtable env) + private String initUsingIiopUrl(ORB defOrb, String url, Hashtable env) throws NamingException { try { IiopUrl parsedUrl = new IiopUrl(url); - Vector addrs = parsedUrl.getAddresses(); - IiopUrl.Address addr; NamingException savedException = null; - - for (int i = 0; i < addrs.size(); i++) { - addr = (IiopUrl.Address)addrs.elementAt(i); + + for (IiopUrl.Address addr : parsedUrl.getAddresses()) { try { if (defOrb != null) { @@ -341,7 +339,7 @@ /** * Initializes using "corbaname" URL (INS 99-12-03) */ - private String initUsingCorbanameUrl(ORB orb, String url, Hashtable env) + private String initUsingCorbanameUrl(ORB orb, String url, Hashtable env) throws NamingException { try { CorbanameUrl parsedUrl = new CorbanameUrl(url); @@ -731,7 +729,7 @@ // as per JNDI spec if (leafNotFound(e, path[path.length-1])) { - ; // do nothing + // do nothing } else { throw ExceptionMapper.mapException(e, this, path); } @@ -829,7 +827,7 @@ * with a non-null argument * @return a list of name-class objects as a NameClassEnumeration. */ - public NamingEnumeration list(String name) throws NamingException { + public NamingEnumeration list(String name) throws NamingException { return list(new CompositeName(name)); } @@ -840,9 +838,10 @@ * @exception NamingException All exceptions thrown by lookup * @return a list of name-class objects as a NameClassEnumeration. */ - public NamingEnumeration list(Name name) + @SuppressWarnings("unchecked") + public NamingEnumeration list(Name name) throws NamingException { - return listBindings(name); + return (NamingEnumeration)listBindings(name); } /** @@ -852,7 +851,7 @@ * @exception NamingException all exceptions returned by lookup * @return a list of bindings as a BindingEnumeration. */ - public NamingEnumeration listBindings(String name) + public NamingEnumeration listBindings(String name) throws NamingException { return listBindings(new CompositeName(name)); } @@ -864,7 +863,7 @@ * @exception NamingException all exceptions returned by lookup. * @return a list of bindings as a BindingEnumeration. */ - public NamingEnumeration listBindings(Name name) + public NamingEnumeration listBindings(Name name) throws NamingException { if (_nc == null) throw new ConfigurationException( @@ -1064,11 +1063,12 @@ * Returns the current environment. * @return Environment. */ - public Hashtable getEnvironment() throws NamingException { + @SuppressWarnings("unchecked") + public Hashtable getEnvironment() throws NamingException { if (_env == null) { - return new Hashtable(5, 0.75f); + return new Hashtable<>(5, 0.75f); } else { - return (Hashtable)_env.clone(); + return (Hashtable)_env.clone(); } } @@ -1090,25 +1090,27 @@ * @param propVal The ORB. * @return the previous value of this property if any. */ + @SuppressWarnings("unchecked") public java.lang.Object addToEnvironment(String propName, java.lang.Object propValue) throws NamingException { if (_env == null) { - _env = new Hashtable(7, 0.75f); + _env = new Hashtable<>(7, 0.75f); } else { // copy-on-write - _env = (Hashtable)_env.clone(); + _env = (Hashtable)_env.clone(); } return _env.put(propName, propValue); } // Record change but do not reinitialize ORB + @SuppressWarnings("unchecked") public java.lang.Object removeFromEnvironment(String propName) throws NamingException { if (_env != null && _env.get(propName) != null) { // copy-on-write - _env = (Hashtable)_env.clone(); + _env = (Hashtable)_env.clone(); return _env.remove(propName); } return null; --- old/src/share/classes/com/sun/jndi/cosnaming/CNNameParser.java 2011-07-27 17:17:55.160235100 -0700 +++ new/src/share/classes/com/sun/jndi/cosnaming/CNNameParser.java 2011-07-27 17:17:54.467165800 -0700 @@ -67,7 +67,7 @@ * @return a non-null CompoundName */ public Name parse(String name) throws NamingException { - Vector comps = insStringToStringifiedComps(name); + Vector comps = insStringToStringifiedComps(name); return new CNCompoundName(comps.elements()); } @@ -128,11 +128,11 @@ * each element of the vector contains a stringified form of * a NameComponent. */ - private static Vector insStringToStringifiedComps(String str) + private static Vector insStringToStringifiedComps(String str) throws InvalidNameException { int len = str.length(); - Vector components = new Vector(10); + Vector components = new Vector<>(10); char[] id = new char[len]; char[] kind = new char[len]; int idCount, kindCount; @@ -306,7 +306,7 @@ * and stringifying code of the default CompoundName. */ static final class CNCompoundName extends CompoundName { - CNCompoundName(Enumeration enum_) { + CNCompoundName(Enumeration enum_) { super(enum_, CNNameParser.mySyntax); } @@ -315,12 +315,12 @@ } public Name getPrefix(int posn) { - Enumeration comps = super.getPrefix(posn).getAll(); + Enumeration comps = super.getPrefix(posn).getAll(); return new CNCompoundName(comps); } public Name getSuffix(int posn) { - Enumeration comps = super.getSuffix(posn).getAll(); + Enumeration comps = super.getSuffix(posn).getAll(); return new CNCompoundName(comps); } --- old/src/share/classes/com/sun/jndi/cosnaming/ExceptionMapper.java 2011-07-27 17:18:01.351854200 -0700 +++ new/src/share/classes/com/sun/jndi/cosnaming/ExceptionMapper.java 2011-07-27 17:18:00.702789300 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1999, 2005, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1999, 2011, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -102,10 +102,10 @@ private static final NamingException tryFed(NotFound e, CNCtx ctx, NameComponent[] inputName) throws NamingException { - NameComponent[] rest = ((NotFound) e).rest_of_name; + NameComponent[] rest = e.rest_of_name; if (debug) { - System.out.println(((NotFound)e).why.value()); + System.out.println(e.why.value()); System.out.println(rest.length); } --- old/src/share/classes/com/sun/jndi/cosnaming/IiopUrl.java 2011-07-27 17:18:07.419460900 -0700 +++ new/src/share/classes/com/sun/jndi/cosnaming/IiopUrl.java 2011-07-27 17:18:06.787397700 -0700 @@ -68,7 +68,7 @@ static final private int DEFAULT_IIOPNAME_PORT = 9999; static final private int DEFAULT_IIOP_PORT = 900; static final private String DEFAULT_HOST = "localhost"; - private Vector addresses; + private Vector
addresses; private String stringName; public static class Address { @@ -149,7 +149,7 @@ } } - public Vector getAddresses() { + public Vector
getAddresses() { return addresses; } @@ -185,7 +185,7 @@ } else { stringName = UrlUtil.decode(url.substring(addrEnd+1)); } - addresses = new Vector(3); + addresses = new Vector<>(3); if (oldFormat) { // Only one host:port part, not multiple addresses.addElement( --- old/src/share/classes/com/sun/jndi/dns/DnsClient.java 2011-07-27 17:18:13.634082300 -0700 +++ new/src/share/classes/com/sun/jndi/dns/DnsClient.java 2011-07-27 17:18:13.036022500 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -524,7 +524,7 @@ "\tResponse Q:" + resps); } byte[] pkt; - if ((pkt = (byte[]) resps.get(xid)) != null) { + if ((pkt = resps.get(xid)) != null) { checkResponseCode(new Header(pkt, pkt.length)); synchronized (queuesLock) { resps.remove(xid); --- old/src/share/classes/com/sun/jndi/dns/DnsContext.java 2011-07-27 17:18:20.512770100 -0700 +++ new/src/share/classes/com/sun/jndi/dns/DnsContext.java 2011-07-27 17:18:19.883707200 -0700 @@ -47,7 +47,7 @@ DnsName domain; // fully-qualified domain name of this context, // with a root (empty) label at position 0 - Hashtable environment; + Hashtable environment; private boolean envShared; // true if environment is possibly shared // and so must be copied on write private boolean parentIsDns; // was this DnsContext created by @@ -95,14 +95,15 @@ * There must be at least one server. * The environment must not be null; it is cloned before being stored. */ - public DnsContext(String domain, String[] servers, Hashtable environment) + @SuppressWarnings("unchecked") + public DnsContext(String domain, String[] servers, Hashtable environment) throws NamingException { this.domain = new DnsName(domain.endsWith(".") ? domain : domain + "."); this.servers = servers; - this.environment = (Hashtable) environment.clone(); + this.environment = (Hashtable) environment.clone(); envShared = false; parentIsDns = false; resolver = null; @@ -154,14 +155,15 @@ /* * Override default with a noncloning version. */ - protected Hashtable p_getEnvironment() { + protected Hashtable p_getEnvironment() { return environment; } - public Hashtable getEnvironment() throws NamingException { - return (Hashtable) environment.clone(); + public Hashtable getEnvironment() throws NamingException { + return (Hashtable) environment.clone(); } + @SuppressWarnings("unchecked") public Object addToEnvironment(String propName, Object propVal) throws NamingException { @@ -189,7 +191,7 @@ return environment.put(propName, propVal); } else if (environment.get(propName) != propVal) { // copy on write - environment = (Hashtable) environment.clone(); + environment = (Hashtable) environment.clone(); envShared = false; return environment.put(propName, propVal); } else { @@ -197,6 +199,7 @@ } } + @SuppressWarnings("unchecked") public Object removeFromEnvironment(String propName) throws NamingException { @@ -222,7 +225,7 @@ return environment.remove(propName); } else if (environment.get(propName) != null) { // copy-on-write - environment = (Hashtable) environment.clone(); + environment = (Hashtable) environment.clone(); envShared = false; return environment.remove(propName); } else { @@ -307,7 +310,7 @@ return c_lookup(name, cont); } - public NamingEnumeration c_list(Name name, Continuation cont) + public NamingEnumeration c_list(Name name, Continuation cont) throws NamingException { cont.setSuccess(); try { @@ -322,7 +325,7 @@ } } - public NamingEnumeration c_listBindings(Name name, Continuation cont) + public NamingEnumeration c_listBindings(Name name, Continuation cont) throws NamingException { cont.setSuccess(); try { @@ -457,7 +460,7 @@ new OperationNotSupportedException()); } - public NamingEnumeration c_search(Name name, + public NamingEnumeration c_search(Name name, Attributes matchingAttributes, String[] attributesToReturn, Continuation cont) @@ -465,7 +468,7 @@ throw new OperationNotSupportedException(); } - public NamingEnumeration c_search(Name name, + public NamingEnumeration c_search(Name name, String filter, SearchControls cons, Continuation cont) @@ -473,7 +476,7 @@ throw new OperationNotSupportedException(); } - public NamingEnumeration c_search(Name name, + public NamingEnumeration c_search(Name name, String filterExpr, Object[] filterArgs, SearchControls cons, @@ -608,7 +611,7 @@ BasicAttributes attrs = new BasicAttributes(true); for (int i = 0; i < rrs.answer.size(); i++) { - ResourceRecord rr = (ResourceRecord) rrs.answer.elementAt(i); + ResourceRecord rr = rrs.answer.elementAt(i); int rrtype = rr.getType(); int rrclass = rr.getRrclass(); @@ -952,19 +955,15 @@ //---------- /* - * An enumeration of name/classname pairs. - * - * Nodes that have children or that are zone cuts are returned with - * classname DirContext. Other nodes are returned with classname - * Object even though they are DirContexts as well, since this might - * make the namespace easier to browse. + * Common base class for NameClassPairEnumeration and BindingEnumeration. + * Inheritors can implement different NamingEnumeration interfaces. */ -class NameClassPairEnumeration implements NamingEnumeration { +class BaseNameClassPairEnumeration { - protected Enumeration nodes; // nodes to be enumerated, or null if none + protected Enumeration nodes; // nodes to be enumerated, or null if none protected DnsContext ctx; // context being enumerated - NameClassPairEnumeration(DnsContext ctx, Hashtable nodes) { + BaseNameClassPairEnumeration(DnsContext ctx, Hashtable nodes) { this.ctx = ctx; this.nodes = (nodes != null) ? nodes.elements() @@ -987,11 +986,31 @@ return more; } - public Object next() throws NamingException { + public boolean hasMoreElements() { + return hasMore(); + } +} + +/* + * An enumeration of name/classname pairs. + * + * Nodes that have children or that are zone cuts are returned with + * classname DirContext. Other nodes are returned with classname + * Object even though they are DirContexts as well, since this might + * make the namespace easier to browse. + */ +class NameClassPairEnumeration extends BaseNameClassPairEnumeration + implements NamingEnumeration { + + NameClassPairEnumeration(DnsContext ctx, Hashtable nodes) { + super(ctx, nodes); + } + + public NameClassPair next() throws NamingException { if (!hasMore()) { throw new java.util.NoSuchElementException(); } - NameNode nnode = (NameNode) nodes.nextElement(); + NameNode nnode = nodes.nextElement(); String className = (nnode.isZoneCut() || (nnode.getChildren() != null)) ? "javax.naming.directory.DirContext" @@ -1005,12 +1024,8 @@ ncp.setNameInNamespace(ctx.fullyQualify(cname).toString()); return ncp; } - - public boolean hasMoreElements() { - return hasMore(); - } - - public Object nextElement() { + + public NameClassPair nextElement() { try { return next(); } catch (NamingException e) { @@ -1024,9 +1039,10 @@ /* * An enumeration of Bindings. */ -class BindingEnumeration extends NameClassPairEnumeration { +class BindingEnumeration extends BaseNameClassPairEnumeration + implements NamingEnumeration { - BindingEnumeration(DnsContext ctx, Hashtable nodes) { + BindingEnumeration(DnsContext ctx, Hashtable nodes) { super(ctx, nodes); } @@ -1035,11 +1051,11 @@ // close(); // } - public Object next() throws NamingException { + public Binding next() throws NamingException { if (!hasMore()) { throw (new java.util.NoSuchElementException()); } - NameNode nnode = (NameNode) nodes.nextElement(); + NameNode nnode = nodes.nextElement(); String label = nnode.getLabel(); Name compName = (new DnsName()).add(label); @@ -1065,4 +1081,14 @@ throw ne; } } + + public Binding nextElement() { + try { + return next(); + } catch (NamingException e) { + throw (new java.util.NoSuchElementException( + "javax.naming.NamingException was thrown: " + + e.getMessage())); + } + } } --- old/src/share/classes/com/sun/jndi/dns/DnsContextFactory.java 2011-07-27 17:18:27.161434900 -0700 +++ new/src/share/classes/com/sun/jndi/dns/DnsContextFactory.java 2011-07-27 17:18:26.524371200 -0700 @@ -59,7 +59,7 @@ public Context getInitialContext(Hashtable env) throws NamingException { if (env == null) { - env = new Hashtable(5); + env = new Hashtable<>(5); } return urlToContext(getInitCtxUrl(env), env); } @@ -75,7 +75,7 @@ * components are overridden by "domain". */ public static DnsContext getContext(String domain, - DnsUrl[] urls, Hashtable env) + DnsUrl[] urls, Hashtable env) throws NamingException { String[] servers = serversForUrls(urls); @@ -95,7 +95,7 @@ ).isEmpty(); } - private static Context urlToContext(String url, Hashtable env) + private static Context urlToContext(String url, Hashtable env) throws NamingException { DnsUrl[] urls; @@ -212,7 +212,7 @@ * Reads environment to find URL(s) of initial context. * Default URL is "dns:". */ - private static String getInitCtxUrl(Hashtable env) { + private static String getInitCtxUrl(Hashtable env) { String url = (String) env.get(Context.PROVIDER_URL); return ((url != null) ? url : DEFAULT_URL); } @@ -223,34 +223,31 @@ * @param oneIsEnough return output once there exists one ok * @return the filtered list, all non-permitted input removed */ - private static List filterNameServers(List input, boolean oneIsEnough) { + private static List filterNameServers(List input, boolean oneIsEnough) { SecurityManager security = System.getSecurityManager(); if (security == null || input == null || input.isEmpty()) { return input; } else { - List output = new ArrayList(); - for (Object o: input) { - if (o instanceof String) { - String platformServer = (String)o; - int colon = platformServer.indexOf(':', - platformServer.indexOf(']') + 1); - - int p = (colon < 0) - ? DEFAULT_PORT - : Integer.parseInt( - platformServer.substring(colon + 1)); - String s = (colon < 0) - ? platformServer - : platformServer.substring(0, colon); - try { - security.checkConnect(s, p); - output.add(platformServer); - if (oneIsEnough) { - return output; - } - } catch (SecurityException se) { - continue; + List output = new ArrayList<>(); + for (String platformServer: input) { + int colon = platformServer.indexOf(':', + platformServer.indexOf(']') + 1); + + int p = (colon < 0) + ? DEFAULT_PORT + : Integer.parseInt( + platformServer.substring(colon + 1)); + String s = (colon < 0) + ? platformServer + : platformServer.substring(0, colon); + try { + security.checkConnect(s, p); + output.add(platformServer); + if (oneIsEnough) { + return output; } + } catch (SecurityException se) { + continue; } } return output; --- old/src/share/classes/com/sun/jndi/dns/DnsName.java 2011-07-27 17:18:33.829101600 -0700 +++ new/src/share/classes/com/sun/jndi/dns/DnsName.java 2011-07-27 17:18:33.180036700 -0700 @@ -29,7 +29,6 @@ import java.util.ArrayList; import java.util.Comparator; import java.util.Enumeration; -import java.util.Iterator; import javax.naming.*; @@ -111,7 +110,7 @@ // The labels of this domain name, as a list of strings. Index 0 // corresponds to the leftmost (least significant) label: note that // this is the reverse of the ordering used by the Name interface. - private ArrayList labels = new ArrayList(); + private ArrayList labels = new ArrayList<>(); // The number of octets needed to carry this domain name in a DNS // packet. Equal to the sum of the lengths of each label, plus the @@ -152,9 +151,7 @@ domain = n.domain; octets = n.octets; } else { - Iterator iter = labels.iterator(); - while (iter.hasNext()) { - String label = (String) iter.next(); + for (String label: labels) { if (label.length() > 0) { octets += (short) (label.length() + 1); } @@ -165,10 +162,8 @@ public String toString() { if (domain == null) { - StringBuffer buf = new StringBuffer(); - Iterator iter = labels.iterator(); - while (iter.hasNext()) { - String label = (String) iter.next(); + StringBuilder buf = new StringBuilder(); + for (String label: labels) { if (buf.length() > 0 || label.length() == 0) { buf.append('.'); } @@ -183,9 +178,8 @@ * Does this domain name follow host name syntax? */ public boolean isHostName() { - Iterator iter = labels.iterator(); - while (iter.hasNext()) { - if (!isHostNameLabel((String) iter.next())) { + for (String label: labels) { + if (!isHostNameLabel(label)) { return false; } } @@ -241,16 +235,16 @@ throw new ArrayIndexOutOfBoundsException(); } int i = size() - pos - 1; // index of "pos" component in "labels" - return (String) labels.get(i); + return labels.get(i); } - public Enumeration getAll() { - return new Enumeration() { + public Enumeration getAll() { + return new Enumeration() { int pos = 0; public boolean hasMoreElements() { return (pos < size()); } - public Object nextElement() { + public String nextElement() { if (pos < size()) { return get(pos++); } @@ -276,7 +270,7 @@ throw new ArrayIndexOutOfBoundsException(); } int i = size() - pos - 1; // index of element to remove in "labels" - String label = (String) labels.remove(i); + String label = labels.remove(i); int len = label.length(); if (len > 0) { octets -= (short) (len + 1); @@ -530,7 +524,7 @@ /* * Append a label to buf, escaping as needed. */ - private static void escape(StringBuffer buf, String label) { + private static void escape(StringBuilder buf, String label) { for (int i = 0; i < label.length(); i++) { char c = label.charAt(i); if (c == '.' || c == '\\') { --- old/src/share/classes/com/sun/jndi/dns/NameNode.java 2011-07-27 17:18:40.737792400 -0700 +++ new/src/share/classes/com/sun/jndi/dns/NameNode.java 2011-07-27 17:18:40.055724200 -0700 @@ -52,7 +52,7 @@ private String label; // name of this node relative to its // parent, or null for root of a tree - private Hashtable children = null; // child nodes + private Hashtable children = null; // child nodes private boolean isZoneCut = false; // true if this node is a zone cut private int depth = 0; // depth in tree (0 for root) @@ -97,7 +97,7 @@ * Returns the children of this node, or null if there are none. * The caller must not modify the Hashtable returned. */ - Hashtable getChildren() { + Hashtable getChildren() { return children; } @@ -108,7 +108,7 @@ */ NameNode get(String key) { return (children != null) - ? (NameNode) children.get(key) + ? children.get(key) : null; } @@ -140,9 +140,9 @@ NameNode child = null; if (node.children == null) { - node.children = new Hashtable(); + node.children = new Hashtable<>(); } else { - child = (NameNode) node.children.get(key); + child = node.children.get(key); } if (child == null) { child = newNameNode(label); --- old/src/share/classes/com/sun/jndi/dns/Resolver.java 2011-07-27 17:18:47.355454100 -0700 +++ new/src/share/classes/com/sun/jndi/dns/Resolver.java 2011-07-27 17:18:46.699388500 -0700 @@ -125,8 +125,7 @@ } // Look for an SOA record giving the zone's top node. for (int i = 0; i < rrs.authority.size(); i++) { - ResourceRecord rr = (ResourceRecord) - rrs.authority.elementAt(i); + ResourceRecord rr = rrs.authority.elementAt(i); if (rr.getType() == ResourceRecord.TYPE_SOA) { DnsName zone = rr.getName(); if (fqdn.endsWith(zone)) { @@ -152,7 +151,7 @@ ResourceRecords rrs = query(zone, rrclass, ResourceRecord.TYPE_SOA, recursion, false); for (int i = 0; i < rrs.answer.size(); i++) { - ResourceRecord rr = (ResourceRecord) rrs.answer.elementAt(i); + ResourceRecord rr = rrs.answer.elementAt(i); if (rr.getType() == ResourceRecord.TYPE_SOA) { return rr; } @@ -175,8 +174,7 @@ recursion, false); String[] ns = new String[rrs.answer.size()]; for (int i = 0; i < ns.length; i++) { - ResourceRecord rr = (ResourceRecord) - rrs.answer.elementAt(i); + ResourceRecord rr = rrs.answer.elementAt(i); if (rr.getType() != ResourceRecord.TYPE_NS) { throw new CommunicationException("Corrupted DNS message"); } --- old/src/share/classes/com/sun/jndi/dns/ResourceRecords.java 2011-07-27 17:18:53.999118400 -0700 +++ new/src/share/classes/com/sun/jndi/dns/ResourceRecords.java 2011-07-27 17:18:53.365055000 -0700 @@ -45,10 +45,10 @@ // Four sections: question, answer, authority, additional. // The question section is treated as being made up of (shortened) // resource records, although this isn't technically how it's defined. - Vector question = new Vector(); - Vector answer = new Vector(); - Vector authority = new Vector(); - Vector additional = new Vector(); + Vector question = new Vector<>(); + Vector answer = new Vector<>(); + Vector authority = new Vector<>(); + Vector additional = new Vector<>(); /* * True if these resource records are from a zone transfer. In @@ -80,7 +80,7 @@ if (answer.size() == 0) { return -1; } - return ((ResourceRecord) answer.firstElement()).getType(); + return answer.firstElement().getType(); } /* @@ -91,7 +91,7 @@ if (answer.size() == 0) { return -1; } - return ((ResourceRecord) answer.lastElement()).getType(); + return answer.lastElement().getType(); } /* --- old/src/share/classes/com/sun/jndi/dns/ZoneNode.java 2011-07-27 17:19:00.639782400 -0700 +++ new/src/share/classes/com/sun/jndi/dns/ZoneNode.java 2011-07-27 17:18:59.970715500 -0700 @@ -55,7 +55,7 @@ class ZoneNode extends NameNode { - private SoftReference contentsRef = null; // the zone's namespace + private SoftReference contentsRef = null; // the zone's namespace private long serialNumber = -1; // the zone data's serial number private Date expiration = null; // time when the zone's data expires @@ -88,7 +88,7 @@ */ synchronized NameNode getContents() { return (contentsRef != null) - ? (NameNode) contentsRef.get() + ? contentsRef.get() : null; } @@ -130,7 +130,7 @@ NameNode newContents = new NameNode(null); for (int i = 0; i < rrs.answer.size(); i++) { - ResourceRecord rr = (ResourceRecord) rrs.answer.elementAt(i); + ResourceRecord rr = rrs.answer.elementAt(i); DnsName n = rr.getName(); // Ignore resource records whose names aren't within the zone's @@ -144,9 +144,9 @@ } } // The zone's SOA record is the first record in the answer section. - ResourceRecord soa = (ResourceRecord) rrs.answer.firstElement(); + ResourceRecord soa = rrs.answer.firstElement(); synchronized (this) { - contentsRef = new SoftReference(newContents); + contentsRef = new SoftReference(newContents); serialNumber = getSerialNumber(soa); setExpiration(getMinimumTtl(soa)); return newContents; --- old/src/share/classes/com/sun/jndi/ldap/Ber.java 2011-07-27 17:19:07.089427300 -0700 +++ new/src/share/classes/com/sun/jndi/ldap/Ber.java 2011-07-27 17:19:06.474365800 -0700 @@ -94,12 +94,14 @@ public static final int ASN_ENUMERATED = 0x0a; final static class EncodeException extends IOException { + private static final long serialVersionUID = -5247359637775781768L; EncodeException(String msg) { super(msg); } } final static class DecodeException extends IOException { + private static final long serialVersionUID = 8735036969244425583L; DecodeException(String msg) { super(msg); } --- old/src/share/classes/com/sun/jndi/ldap/ClientId.java 2011-07-27 17:19:13.480066300 -0700 +++ new/src/share/classes/com/sun/jndi/ldap/ClientId.java 2011-07-27 17:19:12.824000700 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2002, 2005, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2002, 2011, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -74,7 +74,7 @@ this.hostname = hostname.toLowerCase(); // ignore case this.port = port; this.protocol = protocol; - this.bindCtls = (bindCtls != null ? (Control[]) bindCtls.clone() : null); + this.bindCtls = (bindCtls != null ? bindCtls.clone() : null); this.trace = trace; // // Needed for custom socket factory pooling @@ -83,12 +83,12 @@ if ((socketFactory != null) && !socketFactory.equals(LdapCtx.DEFAULT_SSL_FACTORY)) { try { - Class socketFactoryClass = Obj.helper.loadClass(socketFactory); - Class objClass = Class.forName("java.lang.Object"); + Class socketFactoryClass = Obj.helper.loadClass(socketFactory); + Class objClass = Class.forName("java.lang.Object"); this.sockComparator = socketFactoryClass.getMethod( - "compare", new Class[]{objClass, objClass}); + "compare", new Class[]{objClass, objClass}); Method getDefault = - socketFactoryClass.getMethod("getDefault", new Class[]{}); + socketFactoryClass.getMethod("getDefault", new Class[]{}); this.factory = (SocketFactory) getDefault.invoke(null, new Object[]{}); } catch (Exception e) { // Ignore it here, the same exceptions are/will be handled by --- old/src/share/classes/com/sun/jndi/ldap/Connection.java 2011-07-27 17:19:19.647683000 -0700 +++ new/src/share/classes/com/sun/jndi/ldap/Connection.java 2011-07-27 17:19:19.006618900 -0700 @@ -238,27 +238,22 @@ throws NoSuchMethodException { try { - Class inetSocketAddressClass = + Class inetSocketAddressClass = Class.forName("java.net.InetSocketAddress"); - Constructor inetSocketAddressCons = - inetSocketAddressClass.getConstructor(new Class[]{ + Constructor inetSocketAddressCons = + inetSocketAddressClass.getConstructor(new Class[]{ String.class, int.class}); return inetSocketAddressCons.newInstance(new Object[]{ host, new Integer(port)}); - } catch (ClassNotFoundException e) { + } catch (ClassNotFoundException | + InstantiationException | + InvocationTargetException | + IllegalAccessException e) { throw new NoSuchMethodException(); - } catch (InstantiationException e) { - throw new NoSuchMethodException(); - - } catch (InvocationTargetException e) { - throw new NoSuchMethodException(); - - } catch (IllegalAccessException e) { - throw new NoSuchMethodException(); } } @@ -280,9 +275,9 @@ // create the factory - Class socketFactoryClass = Obj.helper.loadClass(socketFactory); + Class socketFactoryClass = Obj.helper.loadClass(socketFactory); Method getDefault = - socketFactoryClass.getMethod("getDefault", new Class[]{}); + socketFactoryClass.getMethod("getDefault", new Class[]{}); Object factory = getDefault.invoke(null, new Object[]{}); // create the socket @@ -293,10 +288,10 @@ try { createSocket = socketFactoryClass.getMethod("createSocket", - new Class[]{}); + new Class[]{}); Method connect = Socket.class.getMethod("connect", - new Class[]{Class.forName("java.net.SocketAddress"), + new Class[]{Class.forName("java.net.SocketAddress"), int.class}); Object endpoint = createInetSocketAddress(host, port); @@ -320,7 +315,7 @@ if (socket == null) { createSocket = socketFactoryClass.getMethod("createSocket", - new Class[]{String.class, int.class}); + new Class[]{String.class, int.class}); if (debug) { System.err.println("Connection: creating socket using " + @@ -335,15 +330,15 @@ if (connectTimeout > 0) { try { - Constructor socketCons = - Socket.class.getConstructor(new Class[]{}); + Constructor socketCons = + Socket.class.getConstructor(new Class[]{}); Method connect = Socket.class.getMethod("connect", - new Class[]{Class.forName("java.net.SocketAddress"), + new Class[]{Class.forName("java.net.SocketAddress"), int.class}); Object endpoint = createInetSocketAddress(host, port); - socket = (Socket) socketCons.newInstance(new Object[]{}); + socket = socketCons.newInstance(new Object[]{}); if (debug) { System.err.println("Connection: creating socket with " + --- old/src/share/classes/com/sun/jndi/ldap/DigestClientId.java 2011-07-27 17:19:25.666284800 -0700 +++ new/src/share/classes/com/sun/jndi/ldap/DigestClientId.java 2011-07-27 17:19:25.014219600 -0700 @@ -65,7 +65,7 @@ DigestClientId(int version, String hostname, int port, String protocol, Control[] bindCtls, OutputStream trace, String socketFactory, String username, - Object passwd, Hashtable env) { + Object passwd, Hashtable env) { super(version, hostname, port, protocol, bindCtls, trace, socketFactory, username, passwd); --- old/src/share/classes/com/sun/jndi/ldap/EventQueue.java 2011-07-27 17:19:31.764894600 -0700 +++ new/src/share/classes/com/sun/jndi/ldap/EventQueue.java 2011-07-27 17:19:31.136831800 -0700 @@ -25,7 +25,6 @@ package com.sun.jndi.ldap; -import java.io.*; import java.util.Vector; import java.util.EventObject; @@ -52,9 +51,9 @@ QueueElement next = null; QueueElement prev = null; EventObject event = null; - Vector vector = null; + Vector vector = null; - QueueElement(EventObject event, Vector vector) { + QueueElement(EventObject event, Vector vector) { this.event = event; this.vector = vector; } @@ -87,7 +86,7 @@ * are notified. * @param vector List of NamingListeners that will be notified of event. */ - synchronized void enqueue(EventObject event, Vector vector) { + synchronized void enqueue(EventObject event, Vector vector) { QueueElement newElt = new QueueElement(event, vector); if (head == null) { @@ -133,7 +132,7 @@ try { while ((qe = dequeue()) != null) { EventObject e = qe.event; - Vector v = qe.vector; + Vector v = qe.vector; for (int i = 0; i < v.size(); i++) { @@ -145,12 +144,11 @@ // only enqueue events with listseners of the correct type. if (e instanceof NamingEvent) { - ((NamingEvent)e).dispatch((NamingListener)v.elementAt(i)); + ((NamingEvent)e).dispatch(v.elementAt(i)); // An exception occurred: if notify all naming listeners } else if (e instanceof NamingExceptionEvent) { - ((NamingExceptionEvent)e).dispatch( - (NamingListener)v.elementAt(i)); + ((NamingExceptionEvent)e).dispatch(v.elementAt(i)); } else if (e instanceof UnsolicitedNotificationEvent) { ((UnsolicitedNotificationEvent)e).dispatch( (UnsolicitedNotificationListener)v.elementAt(i)); --- old/src/share/classes/com/sun/jndi/ldap/EventSupport.java 2011-07-27 17:19:38.007518800 -0700 +++ new/src/share/classes/com/sun/jndi/ldap/EventSupport.java 2011-07-27 17:19:37.349453000 -0700 @@ -27,11 +27,9 @@ import java.util.Hashtable; import java.util.Vector; -import java.util.Enumeration; import java.util.EventObject; import javax.naming.*; -import javax.naming.directory.*; import javax.naming.event.*; import javax.naming.directory.SearchControls; import javax.naming.ldap.UnsolicitedNotificationListener; @@ -120,12 +118,13 @@ /** * NamingEventNotifiers; hashed by search arguments; */ - private Hashtable notifiers = new Hashtable(11); + private Hashtable notifiers = + new Hashtable<>(11); /** * List of unsolicited notification listeners. */ - private Vector unsolicited = null; + private Vector unsolicited = null; /** * Constructs EventSupport for ctx. @@ -155,8 +154,7 @@ l instanceof NamespaceChangeListener) { NotifierArgs args = new NotifierArgs(nm, scope, l); - NamingEventNotifier notifier = - (NamingEventNotifier) notifiers.get(args); + NamingEventNotifier notifier = notifiers.get(args); if (notifier == null) { notifier = new NamingEventNotifier(this, ctx, args, l); notifiers.put(args, notifier); @@ -167,10 +165,10 @@ if (l instanceof UnsolicitedNotificationListener) { // Add listener to this's list of unsolicited notifiers if (unsolicited == null) { - unsolicited = new Vector(3); + unsolicited = new Vector<>(3); } - unsolicited.addElement(l); + unsolicited.addElement((UnsolicitedNotificationListener)l); } } @@ -185,8 +183,7 @@ l instanceof NamespaceChangeListener) { NotifierArgs args = new NotifierArgs(nm, filter, ctls, l); - NamingEventNotifier notifier = - (NamingEventNotifier) notifiers.get(args); + NamingEventNotifier notifier = notifiers.get(args); if (notifier == null) { notifier = new NamingEventNotifier(this, ctx, args, l); notifiers.put(args, notifier); @@ -197,9 +194,9 @@ if (l instanceof UnsolicitedNotificationListener) { // Add listener to this's list of unsolicited notifiers if (unsolicited == null) { - unsolicited = new Vector(3); + unsolicited = new Vector<>(3); } - unsolicited.addElement(l); + unsolicited.addElement((UnsolicitedNotificationListener)l); } } @@ -207,15 +204,11 @@ * Removes l from all notifiers in this context. */ synchronized void removeNamingListener(NamingListener l) { - Enumeration allnotifiers = notifiers.elements(); - NamingEventNotifier notifier; - if (debug) System.err.println("EventSupport removing listener"); // Go through list of notifiers, remove 'l' from each. // If 'l' is notifier's only listener, remove notifier too. - while (allnotifiers.hasMoreElements()) { - notifier = (NamingEventNotifier)allnotifiers.nextElement(); + for (NamingEventNotifier notifier : notifiers.values()) { if (notifier != null) { if (debug) System.err.println("EventSupport removing listener from notifier"); @@ -305,8 +298,8 @@ synchronized void cleanup() { if (debug) System.err.println("EventSupport clean up"); if (notifiers != null) { - for (Enumeration ns = notifiers.elements(); ns.hasMoreElements(); ) { - ((NamingEventNotifier) ns.nextElement()).stop(); + for (NamingEventNotifier notifier : notifiers.values()) { + notifier.stop(); } notifiers = null; } @@ -328,7 +321,8 @@ * them to the registered listeners. * Package private; used by NamingEventNotifier to fire events */ - synchronized void queueEvent(EventObject event, Vector vector) { + synchronized void queueEvent(EventObject event, + Vector vector) { if (eventQueue == null) eventQueue = new EventQueue(); @@ -340,7 +334,9 @@ * of this event will not take effect until after the event is * delivered. */ - Vector v = (Vector)vector.clone(); + @SuppressWarnings("unchecked") + Vector v = + (Vector)vector.clone(); eventQueue.enqueue(event, v); } --- old/src/share/classes/com/sun/jndi/ldap/LdapAttribute.java 2011-07-27 17:19:44.176135600 -0700 +++ new/src/share/classes/com/sun/jndi/ldap/LdapAttribute.java 2011-07-27 17:19:43.523070300 -0700 @@ -26,8 +26,6 @@ package com.sun.jndi.ldap; import java.io.IOException; -import java.io.Serializable; -import java.util.Enumeration; import java.util.Hashtable; import java.util.Vector; import javax.naming.*; @@ -50,11 +48,12 @@ // these two are used to reconstruct the baseCtx if this attribute has // been serialized ( private String baseCtxURL; - private Hashtable baseCtxEnv; + private Hashtable baseCtxEnv; + @SuppressWarnings("unchecked") // clone() public Object clone() { LdapAttribute attr = new LdapAttribute(this.attrID, baseCtx, rdn); - attr.values = (Vector)values.clone(); + attr.values = (Vector)values.clone(); return attr; } @@ -112,7 +111,7 @@ private DirContext getBaseCtx() throws NamingException { if(baseCtx == null) { if (baseCtxEnv == null) { - baseCtxEnv = new Hashtable(3); + baseCtxEnv = new Hashtable(3); } baseCtxEnv.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory"); @@ -144,9 +143,10 @@ * we are serialized. This must be called _before_ the object is * serialized!!! */ + @SuppressWarnings("unchecked") // clone() private void setBaseCtxInfo() { - Hashtable realEnv = null; - Hashtable secureEnv = null; + Hashtable realEnv = null; + Hashtable secureEnv = null; if (baseCtx != null) { realEnv = ((LdapCtx)baseCtx).envprops; @@ -156,16 +156,14 @@ if(realEnv != null && realEnv.size() > 0 ) { // remove any security credentials - otherwise the serialized form // would store them in the clear - Enumeration keys = realEnv.keys(); - while(keys.hasMoreElements()) { - String key = (String)keys.nextElement(); + for (String key : realEnv.keySet()){ if (key.indexOf("security") != -1 ) { //if we need to remove props, we must do it to a clone //of the environment. cloning is expensive, so we only do //it if we have to. if(secureEnv == null) { - secureEnv = (Hashtable)realEnv.clone(); + secureEnv = (Hashtable)realEnv.clone(); } secureEnv.remove(key); } --- old/src/share/classes/com/sun/jndi/ldap/LdapBindingEnumeration.java 2011-07-27 17:19:50.302748200 -0700 +++ new/src/share/classes/com/sun/jndi/ldap/LdapBindingEnumeration.java 2011-07-27 17:19:49.658683800 -0700 @@ -28,6 +28,7 @@ import java.util.Vector; import javax.naming.*; import javax.naming.directory.*; +import javax.naming.ldap.Control; import javax.naming.spi.*; import com.sun.jndi.toolkit.ctx.Continuation; @@ -40,8 +41,8 @@ super(homeCtx, answer, remain, cont); } - protected NameClassPair - createItem(String dn, Attributes attrs, Vector respCtls) + protected Binding + createItem(String dn, Attributes attrs, Vector respCtls) throws NamingException { Object obj = null; @@ -85,9 +86,10 @@ return binding; } - protected LdapNamingEnumeration + protected LdapBindingEnumeration getReferredResults(LdapReferralContext refCtx) throws NamingException{ // repeat the original operation at the new context - return (LdapNamingEnumeration) refCtx.listBindings(listArg); + return (LdapBindingEnumeration)(NamingEnumeration) + refCtx.listBindings(listArg); } } --- 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, --- old/src/share/classes/com/sun/jndi/ldap/LdapCtx.java 2011-07-27 17:20:02.916009400 -0700 +++ new/src/share/classes/com/sun/jndi/ldap/LdapCtx.java 2011-07-27 17:20:02.247942600 -0700 @@ -223,7 +223,7 @@ String hostname = null; // host name of server (no brackets // for IPv6 literals) LdapClient clnt = null; // connection handle - Hashtable envprops = null; // environment properties of context + Hashtable envprops = null; // environment properties of context int handleReferrals = DEFAULT_REFERRAL_MODE; // how referral is handled boolean hasLdapsScheme = false; // true if the context was created // using an LDAPS URL. @@ -232,7 +232,7 @@ String currentDN; // DN of this context Name currentParsedDN; // DN of this context - Vector respCtls = null; // Response controls read + Vector respCtls = null; // Response controls read Control[] reqCtls = null; // Controls to be sent with each request @@ -244,14 +244,14 @@ private boolean netscapeSchemaBug = false; // workaround private Control[] bindCtls = null; // Controls to be sent with LDAP "bind" private int referralHopLimit = DEFAULT_REFERRAL_LIMIT; // max referral - private Hashtable schemaTrees = null; // schema root of this context + private Hashtable schemaTrees = null; // schema root of this context private int batchSize = DEFAULT_BATCH_SIZE; // batch size for search results private boolean deleteRDN = DEFAULT_DELETE_RDN; // delete the old RDN when modifying DN private boolean typesOnly = DEFAULT_TYPES_ONLY; // return attribute types (no values) private int derefAliases = DEFAULT_DEREF_ALIASES;// de-reference alias entries during searching private char addrEncodingSeparator = DEFAULT_REF_SEPARATOR; // encoding RefAddr - private Hashtable binaryAttrs = null; // attr values returned as byte[] + private Hashtable binaryAttrs = null; // attr values returned as byte[] private int connectTimeout = -1; // no timeout value private int readTimeout = -1; // no timeout value private boolean waitForReply = true; // wait for search response @@ -272,13 +272,15 @@ // -------------- Constructors ----------------------------------- - public LdapCtx(String dn, String host, int port_number, Hashtable props, + @SuppressWarnings("unchecked") + public LdapCtx(String dn, String host, int port_number, + Hashtable props, boolean useSsl) throws NamingException { this.useSsl = this.hasLdapsScheme = useSsl; if (props != null) { - envprops = (Hashtable) props.clone(); + envprops = (Hashtable) props.clone(); // SSL env prop overrides the useSsl argument if ("ssl".equals(envprops.get(Context.SECURITY_PROTOCOL))) { @@ -310,7 +312,7 @@ this.useDefaultPortNumber = true; } - schemaTrees = new Hashtable(11, 0.75f); + schemaTrees = new Hashtable<>(11, 0.75f); initEnv(); try { connect(false); @@ -918,19 +920,17 @@ } // Parse string name into list of RDNs - //List rdnList = (new LdapName(dn)).rdns(); - List rdnList = (new LdapName(dn)).getRdns(); + List rdnList = (new LdapName(dn)).getRdns(); // Get leaf RDN - //Rdn rdn = rdnList.get(rdnList.size() - 1); - Rdn rdn = (Rdn) rdnList.get(rdnList.size() - 1); + Rdn rdn = rdnList.get(rdnList.size() - 1); Attributes nameAttrs = rdn.toAttributes(); // Add attributes of RDN to attrs if not already there - NamingEnumeration enum_ = nameAttrs.getAll(); + NamingEnumeration enum_ = nameAttrs.getAll(); Attribute nameAttr; while (enum_.hasMore()) { - nameAttr = (Attribute) enum_.next(); + nameAttr = enum_.next(); // If attrs already has the attribute, don't change or add to it if (attrs.get(nameAttr.getID()) == null) { @@ -961,12 +961,12 @@ } - private static boolean containsIgnoreCase(NamingEnumeration enumStr, + private static boolean containsIgnoreCase(NamingEnumeration enumStr, String str) throws NamingException { String strEntry; while (enumStr.hasMore()) { - strEntry = (String) enumStr.next(); + strEntry = enumStr.next(); if (strEntry.equalsIgnoreCase(str)) { return true; } @@ -993,7 +993,7 @@ * Append the the second Vector onto the first Vector * (v2 must be non-null) */ - private static Vector appendVector(Vector v1, Vector v2) { + private static Vector appendVector(Vector v1, Vector v2) { if (v1 == null) { v1 = v2; } else { @@ -1038,10 +1038,10 @@ // found it but got no attributes attrs = new BasicAttributes(LdapClient.caseIgnore); } else { - LdapEntry entry = (LdapEntry)answer.entries.elementAt(0); + LdapEntry entry = answer.entries.elementAt(0); attrs = entry.attributes; - Vector entryCtls = entry.respCtls; // retrieve entry controls + Vector entryCtls = entry.respCtls; // retrieve entry controls if (entryCtls != null) { appendVector(respCtls, entryCtls); // concatenate controls } @@ -1097,7 +1097,7 @@ } } - protected NamingEnumeration c_list(Name name, Continuation cont) + protected NamingEnumeration c_list(Name name, Continuation cont) throws NamingException { SearchControls cons = new SearchControls(); String[] classAttrs = new String[2]; @@ -1170,7 +1170,8 @@ } } - protected NamingEnumeration c_listBindings(Name name, Continuation cont) + @SuppressWarnings("unchecked") + protected NamingEnumeration c_listBindings(Name name, Continuation cont) throws NamingException { SearchControls cons = new SearchControls(); @@ -1190,7 +1191,8 @@ processReturnCode(answer, name); } - return new LdapBindingEnumeration(this, answer, name, cont); + return (NamingEnumeration) + new LdapBindingEnumeration(this, answer, name, cont); } catch (LdapReferralException e) { if (handleReferrals == LdapClient.LDAP_REF_THROW) @@ -1222,7 +1224,7 @@ res.setNamingException( (LimitExceededException)cont.fillInException(e)); - return res; + return (NamingEnumeration)res; } catch (PartialResultException e) { LdapBindingEnumeration res = @@ -1230,7 +1232,7 @@ res.setNamingException( (PartialResultException)cont.fillInException(e)); - return res; + return (NamingEnumeration)res; } catch (NamingException e) { throw cont.fillInException(e); @@ -1337,9 +1339,9 @@ } // get attributes from result - LdapEntry entry = (LdapEntry) answer.entries.elementAt(0); + LdapEntry entry = answer.entries.elementAt(0); - Vector entryCtls = entry.respCtls; // retrieve entry controls + Vector entryCtls = entry.respCtls; // retrieve entry controls if (entryCtls != null) { appendVector(respCtls, entryCtls); // concatenate controls } @@ -1398,10 +1400,10 @@ int[] jmods = new int[attrs.size()]; Attribute[] jattrs = new Attribute[attrs.size()]; - NamingEnumeration ae = attrs.getAll(); + NamingEnumeration ae = attrs.getAll(); for(int i = 0; i < jmods.length && ae.hasMore(); i++) { jmods[i] = jmod_op; - jattrs[i] = (Attribute)ae.next(); + jattrs[i] = ae.next(); } LdapResult answer = clnt.modify(newDN, jmods, jattrs, reqCtls); @@ -1565,7 +1567,7 @@ HierMemDirCtx objectClassCtx = new HierMemDirCtx(); DirContext objectClassDef; String objectClassName; - for (Enumeration objectClasses = objectClassAttr.getAll(); + for (Enumeration objectClasses = objectClassAttr.getAll(); objectClasses.hasMoreElements(); ) { objectClassName = (String)objectClasses.nextElement(); // %%% Should we fail if not found, or just continue? @@ -1591,7 +1593,7 @@ private DirContext getSchemaTree(Name name) throws NamingException { String subschemasubentry = getSchemaEntry(name, true); - DirContext schemaTree = (DirContext)schemaTrees.get(subschemasubentry); + DirContext schemaTree = schemaTrees.get(subschemasubentry); if(schemaTree==null) { if(debug){System.err.println("LdapCtx: building new schema tree " + this);} @@ -1621,7 +1623,7 @@ false /*deref link */ ); Name sse = (new CompositeName()).add(subschemasubentry); - NamingEnumeration results = + NamingEnumeration results = searchAux(sse, "(objectClass=subschema)", constraints, false, true, new Continuation()); @@ -1629,7 +1631,7 @@ throw new OperationNotSupportedException( "Cannot get read subschemasubentry: " + subschemasubentry); } - SearchResult result = (SearchResult)results.next(); + SearchResult result = results.next(); results.close(); Object obj = result.getObject(); @@ -1674,7 +1676,7 @@ false /* returning obj */, false /* deref link */); - NamingEnumeration results; + NamingEnumeration results; try { results = searchAux(name, "objectclass=*", constraints, relative, true, new Continuation()); @@ -1695,7 +1697,7 @@ "Requesting schema of nonexistent entry: " + name); } - SearchResult result = (SearchResult) results.next(); + SearchResult result = results.next(); results.close(); Attribute schemaEntryAttr = @@ -1720,7 +1722,7 @@ // Set attributes to point to this context in case some one // asked for their schema void setParents(Attributes attrs, Name name) throws NamingException { - NamingEnumeration ae = attrs.getAll(); + NamingEnumeration ae = attrs.getAll(); while(ae.hasMore()) { ((LdapAttribute) ae.next()).setParent(this, name); } @@ -1740,14 +1742,14 @@ } // --------------------- Searches ----------------------------- - protected NamingEnumeration c_search(Name name, + protected NamingEnumeration c_search(Name name, Attributes matchingAttributes, Continuation cont) throws NamingException { return c_search(name, matchingAttributes, null, cont); } - protected NamingEnumeration c_search(Name name, + protected NamingEnumeration c_search(Name name, Attributes matchingAttributes, String[] attributesToReturn, Continuation cont) @@ -1764,7 +1766,7 @@ return c_search(name, filter, cons, cont); } - protected NamingEnumeration c_search(Name name, + protected NamingEnumeration c_search(Name name, String filter, SearchControls cons, Continuation cont) @@ -1773,7 +1775,7 @@ waitForReply, cont); } - protected NamingEnumeration c_search(Name name, + protected NamingEnumeration c_search(Name name, String filterExpr, Object[] filterArgs, SearchControls cons, @@ -1790,7 +1792,8 @@ } // Used by NamingNotifier - NamingEnumeration searchAux(Name name, + @SuppressWarnings("unchecked") + NamingEnumeration searchAux(Name name, String filter, SearchControls cons, boolean relative, @@ -1848,8 +1851,9 @@ // search result may contain referrals processReturnCode(answer, name); } - return new LdapSearchEnumeration(this, answer, - fullyQualifiedName(name), args, cont); + return (NamingEnumeration) + new LdapSearchEnumeration(this, answer, + fullyQualifiedName(name), args, cont); } catch (LdapReferralException e) { if (handleReferrals == LdapClient.LDAP_REF_THROW) @@ -1881,7 +1885,7 @@ new LdapSearchEnumeration(this, answer, fullyQualifiedName(name), args, cont); res.setNamingException(e); - return res; + return (NamingEnumeration)res; } catch (PartialResultException e) { LdapSearchEnumeration res = @@ -1889,7 +1893,7 @@ args, cont); res.setNamingException(e); - return res; + return (NamingEnumeration)res; } catch (IOException e) { NamingException e2 = new CommunicationException(e.getMessage()); @@ -2143,16 +2147,18 @@ /** * Override with noncloning version. */ - protected Hashtable p_getEnvironment() { + protected Hashtable p_getEnvironment() { return envprops; } - public Hashtable getEnvironment() throws NamingException { + @SuppressWarnings("unchecked") + public Hashtable getEnvironment() throws NamingException { return (envprops == null - ? new Hashtable(5, 0.75f) - : (Hashtable)envprops.clone()); + ? new Hashtable(5, 0.75f) + : (Hashtable)envprops.clone()); } + @SuppressWarnings("unchecked") public Object removeFromEnvironment(String propName) throws NamingException { @@ -2160,58 +2166,74 @@ if (envprops == null || envprops.get(propName) == null) { return null; } + switch (propName) { + case REF_SEPARATOR: + addrEncodingSeparator = DEFAULT_REF_SEPARATOR; + break; + case TYPES_ONLY: + typesOnly = DEFAULT_TYPES_ONLY; + break; + case DELETE_RDN: + deleteRDN = DEFAULT_DELETE_RDN; + break; + case DEREF_ALIASES: + derefAliases = DEFAULT_DEREF_ALIASES; + break; + case Context.BATCHSIZE: + batchSize = DEFAULT_BATCH_SIZE; + break; + case REFERRAL_LIMIT: + referralHopLimit = DEFAULT_REFERRAL_LIMIT; + break; + case Context.REFERRAL: + setReferralMode(null, true); + break; + case BINARY_ATTRIBUTES: + setBinaryAttributes(null); + break; + case CONNECT_TIMEOUT: + connectTimeout = -1; + break; + case READ_TIMEOUT: + readTimeout = -1; + break; + case WAIT_FOR_REPLY: + waitForReply = true; + break; + case REPLY_QUEUE_SIZE: + replyQueueSize = -1; + break; + + // The following properties affect the connection - if (propName.equals(REF_SEPARATOR)) { - addrEncodingSeparator = DEFAULT_REF_SEPARATOR; - } else if (propName.equals(TYPES_ONLY)) { - typesOnly = DEFAULT_TYPES_ONLY; - } else if (propName.equals(DELETE_RDN)) { - deleteRDN = DEFAULT_DELETE_RDN; - } else if (propName.equals(DEREF_ALIASES)) { - derefAliases = DEFAULT_DEREF_ALIASES; - } else if (propName.equals(Context.BATCHSIZE)) { - batchSize = DEFAULT_BATCH_SIZE; - } else if (propName.equals(REFERRAL_LIMIT)) { - referralHopLimit = DEFAULT_REFERRAL_LIMIT; - } else if (propName.equals(Context.REFERRAL)) { - setReferralMode(null, true); - } else if (propName.equals(BINARY_ATTRIBUTES)) { - setBinaryAttributes(null); - } else if (propName.equals(CONNECT_TIMEOUT)) { - connectTimeout = -1; - } else if (propName.equals(READ_TIMEOUT)) { - readTimeout = -1; - } else if (propName.equals(WAIT_FOR_REPLY)) { - waitForReply = true; - } else if (propName.equals(REPLY_QUEUE_SIZE)) { - replyQueueSize = -1; - -// The following properties affect the connection - - } else if (propName.equals(Context.SECURITY_PROTOCOL)) { - closeConnection(SOFT_CLOSE); - // De-activate SSL and reset the context's url and port number - if (useSsl && !hasLdapsScheme) { - useSsl = false; - url = null; - if (useDefaultPortNumber) { - port_number = DEFAULT_PORT; - } - } - } else if (propName.equals(VERSION) || - propName.equals(SOCKET_FACTORY)) { - closeConnection(SOFT_CLOSE); - } else if(propName.equals(Context.SECURITY_AUTHENTICATION) || - propName.equals(Context.SECURITY_PRINCIPAL) || - propName.equals(Context.SECURITY_CREDENTIALS)) { - sharable = false; + case Context.SECURITY_PROTOCOL: + closeConnection(SOFT_CLOSE); + // De-activate SSL and reset the context's url and port number + if (useSsl && !hasLdapsScheme) { + useSsl = false; + url = null; + if (useDefaultPortNumber) { + port_number = DEFAULT_PORT; + } + } + break; + case VERSION: + case SOCKET_FACTORY: + closeConnection(SOFT_CLOSE); + break; + case Context.SECURITY_AUTHENTICATION: + case Context.SECURITY_PRINCIPAL: + case Context.SECURITY_CREDENTIALS: + sharable = false; + break; } // Update environment; reconnection will use new props - envprops = (Hashtable)envprops.clone(); + envprops = (Hashtable)envprops.clone(); return envprops.remove(propName); } + @SuppressWarnings("unchecked") public Object addToEnvironment(String propName, Object propVal) throws NamingException { @@ -2219,35 +2241,47 @@ if (propVal == null) { return removeFromEnvironment(propName); } - - if (propName.equals(REF_SEPARATOR)) { + switch (propName) { + case REF_SEPARATOR: setRefSeparator((String)propVal); - } else if (propName.equals(TYPES_ONLY)) { + break; + case TYPES_ONLY: setTypesOnly((String)propVal); - } else if (propName.equals(DELETE_RDN)) { + break; + case DELETE_RDN: setDeleteRDN((String)propVal); - } else if (propName.equals(DEREF_ALIASES)) { + break; + case DEREF_ALIASES: setDerefAliases((String)propVal); - } else if (propName.equals(Context.BATCHSIZE)) { + break; + case Context.BATCHSIZE: setBatchSize((String)propVal); - } else if (propName.equals(REFERRAL_LIMIT)) { + break; + case REFERRAL_LIMIT: setReferralLimit((String)propVal); - } else if (propName.equals(Context.REFERRAL)) { + break; + case Context.REFERRAL: setReferralMode((String)propVal, true); - } else if (propName.equals(BINARY_ATTRIBUTES)) { + break; + case BINARY_ATTRIBUTES: setBinaryAttributes((String)propVal); - } else if (propName.equals(CONNECT_TIMEOUT)) { + break; + case CONNECT_TIMEOUT: setConnectTimeout((String)propVal); - } else if (propName.equals(READ_TIMEOUT)) { + break; + case READ_TIMEOUT: setReadTimeout((String)propVal); - } else if (propName.equals(WAIT_FOR_REPLY)) { + break; + case WAIT_FOR_REPLY: setWaitForReply((String)propVal); - } else if (propName.equals(REPLY_QUEUE_SIZE)) { + break; + case REPLY_QUEUE_SIZE: setReplyQueueSize((String)propVal); + break; // The following properties affect the connection - } else if (propName.equals(Context.SECURITY_PROTOCOL)) { + case Context.SECURITY_PROTOCOL: closeConnection(SOFT_CLOSE); // Activate SSL and reset the context's url and port number if ("ssl".equals(propVal)) { @@ -2257,19 +2291,22 @@ port_number = DEFAULT_SSL_PORT; } } - } else if (propName.equals(VERSION) || - propName.equals(SOCKET_FACTORY)) { + break; + case VERSION: + case SOCKET_FACTORY: closeConnection(SOFT_CLOSE); - } else if (propName.equals(Context.SECURITY_AUTHENTICATION) || - propName.equals(Context.SECURITY_PRINCIPAL) || - propName.equals(Context.SECURITY_CREDENTIALS)) { + break; + case Context.SECURITY_AUTHENTICATION: + case Context.SECURITY_PRINCIPAL: + case Context.SECURITY_CREDENTIALS: sharable = false; - } + break; + } // Update environment; reconnection will use new props envprops = (envprops == null - ? new Hashtable(5, 0.75f) - : (Hashtable)envprops.clone()); + ? new Hashtable(5, 0.75f) + : (Hashtable)envprops.clone()); return envprops.put(propName, propVal); } @@ -2380,15 +2417,19 @@ private void setReferralMode(String ref, boolean update) { // First determine the referral mode if (ref != null) { - if (ref.equals("follow")) { - handleReferrals = LdapClient.LDAP_REF_FOLLOW; - } else if (ref.equals("throw")) { - handleReferrals = LdapClient.LDAP_REF_THROW; - } else if (ref.equals("ignore")) { - handleReferrals = LdapClient.LDAP_REF_IGNORE; - } else { - throw new IllegalArgumentException( - "Illegal value for " + Context.REFERRAL + " property."); + switch (ref) { + case "follow": + handleReferrals = LdapClient.LDAP_REF_FOLLOW; + break; + case "throw": + handleReferrals = LdapClient.LDAP_REF_THROW; + break; + case "ignore": + handleReferrals = LdapClient.LDAP_REF_IGNORE; + break; + default: + throw new IllegalArgumentException( + "Illegal value for " + Context.REFERRAL + " property."); } } else { handleReferrals = DEFAULT_REFERRAL_MODE; @@ -2411,17 +2452,22 @@ */ private void setDerefAliases(String deref) { if (deref != null) { - if (deref.equals("never")) { - derefAliases = 0; // never de-reference aliases - } else if (deref.equals("searching")) { - derefAliases = 1; // de-reference aliases during searching - } else if (deref.equals("finding")) { - derefAliases = 2; // de-reference during name resolution - } else if (deref.equals("always")) { - derefAliases = 3; // always de-reference aliases - } else { - throw new IllegalArgumentException("Illegal value for " + - DEREF_ALIASES + " property."); + switch (deref) { + case "never": + derefAliases = 0; // never de-reference aliases + break; + case "searching": + derefAliases = 1; // de-reference aliases during searching + break; + case "finding": + derefAliases = 2; // de-reference during name resolution + break; + case "always": + derefAliases = 3; // always de-reference aliases + break; + default: + throw new IllegalArgumentException("Illegal value for " + + DEREF_ALIASES + " property."); } } else { derefAliases = DEFAULT_DEREF_ALIASES; @@ -2515,7 +2561,7 @@ * ::= ASCII linefeed character (0x0a) * ::= LDAP URL format (RFC 1959) */ - private static Vector extractURLs(String refString) { + private static Vector extractURLs(String refString) { int separator = 0; int urlCount = 0; @@ -2526,7 +2572,7 @@ urlCount++; } - Vector referrals = new Vector(urlCount); + Vector referrals = new Vector<>(urlCount); int iURL; int i = 0; @@ -2549,7 +2595,7 @@ if (attrIds == null) { binaryAttrs = null; } else { - binaryAttrs = new Hashtable(11, 0.75f); + binaryAttrs = new Hashtable<>(11, 0.75f); StringTokenizer tokens = new StringTokenizer(attrIds.toLowerCase(), " "); @@ -2601,11 +2647,12 @@ */ } + @SuppressWarnings("unchecked") public void reconnect(Control[] connCtls) throws NamingException { // Update environment envprops = (envprops == null - ? new Hashtable(5, 0.75f) - : (Hashtable)envprops.clone()); + ? new Hashtable(5, 0.75f) + : (Hashtable)envprops.clone()); if (connCtls == null) { envprops.remove(BIND_CONTROLS); @@ -2631,7 +2678,7 @@ } // reset the cache before a new connection is established - schemaTrees = new Hashtable(11, 0.75f); + schemaTrees = new Hashtable<>(11, 0.75f); connect(startTLS); } else if (!sharable || startTLS) { @@ -2644,7 +2691,7 @@ } } // reset the cache before a new connection is established - schemaTrees = new Hashtable(11, 0.75f); + schemaTrees = new Hashtable<>(11, 0.75f); connect(startTLS); } @@ -2846,7 +2893,7 @@ } protected void processReturnCode(LdapResult res, Name resolvedName, - Object resolvedObj, Name remainName, Hashtable envprops, String fullDN) + Object resolvedObj, Name remainName, Hashtable envprops, String fullDN) throws NamingException { String msg = LdapClient.getErrorMessage(res.status, res.errorMessage); @@ -2966,7 +3013,9 @@ // extract SLAPD-style referrals from errorMessage if ((res.errorMessage != null) && (!res.errorMessage.equals(""))) { - res.referrals = extractURLs(res.errorMessage); + @SuppressWarnings("unchecked") + Vector temp = (Vector)extractURLs(res.errorMessage); + res.referrals = temp; } else { e = new PartialResultException(msg); break; @@ -2998,7 +3047,7 @@ if (((res.entries == null) || (res.entries.size() == 0)) && (res.referrals.size() == 1)) { - r.setReferralInfo((Vector)res.referrals, false); + r.setReferralInfo(res.referrals, false); // check the hop limit if (hopCount > referralHopLimit) { @@ -3284,9 +3333,9 @@ /** * Narrow controls using own default factory and ControlFactory. - * @param ctls A non-null Vector + * @param ctls A non-null Vector */ - Control[] convertControls(Vector ctls) throws NamingException { + Control[] convertControls(Vector ctls) throws NamingException { int count = ctls.size(); if (count == 0) { @@ -3298,12 +3347,12 @@ for (int i = 0; i < count; i++) { // Try own factory first controls[i] = myResponseControlFactory.getControlInstance( - (Control)ctls.elementAt(i)); + ctls.elementAt(i)); // Try assigned factories if own produced null if (controls[i] == null) { controls[i] = ControlFactory.getControlInstance( - (Control)ctls.elementAt(i), this, envprops); + ctls.elementAt(i), this, envprops); } } return controls; --- old/src/share/classes/com/sun/jndi/ldap/LdapCtxFactory.java 2011-07-27 17:20:09.574675200 -0700 +++ new/src/share/classes/com/sun/jndi/ldap/LdapCtxFactory.java 2011-07-27 17:20:08.876605400 -0700 @@ -28,7 +28,6 @@ import java.util.Hashtable; import java.util.Vector; import java.util.Enumeration; -import java.net.MalformedURLException; import javax.naming.*; import javax.naming.directory.*; @@ -119,9 +118,9 @@ int size = 0; // number of URLs String[] urls = new String[ref.size()]; - Enumeration addrs = ref.getAll(); + Enumeration addrs = ref.getAll(); while (addrs.hasMoreElements()) { - RefAddr addr = (RefAddr)addrs.nextElement(); + RefAddr addr = addrs.nextElement(); if ((addr instanceof StringRefAddr) && addr.getType().equals(ADDRESS_TYPE)) { @@ -145,7 +144,7 @@ // ------------ Utilities used by other classes ---------------- - public static DirContext getLdapCtxInstance(Object urlInfo, Hashtable env) + public static DirContext getLdapCtxInstance(Object urlInfo, Hashtable env) throws NamingException { if (urlInfo instanceof String) { @@ -158,7 +157,7 @@ } } - private static DirContext getUsingURL(String url, Hashtable env) + private static DirContext getUsingURL(String url, Hashtable env) throws NamingException { DirContext ctx = null; LdapURL ldapUrl = new LdapURL(url); @@ -202,7 +201,7 @@ * If all URLs fail, throw one of the exceptions arbitrarily. * Not pretty, but potentially more informative than returning null. */ - private static DirContext getUsingURLs(String[] urls, Hashtable env) + private static DirContext getUsingURLs(String[] urls, Hashtable env) throws NamingException { NamingException ne = null; DirContext ctx = null; @@ -221,8 +220,8 @@ /** * Used by Obj and obj/RemoteToAttrs too so must be public */ - public static Attribute createTypeNameAttr(Class cl) { - Vector v = new Vector(10); + public static Attribute createTypeNameAttr(Class cl) { + Vector v = new Vector<>(10); String[] types = getTypeNames(cl, v); if (types.length > 0) { BasicAttribute tAttr = @@ -235,7 +234,7 @@ return null; } - private static String[] getTypeNames(Class currentClass, Vector v) { + private static String[] getTypeNames(Class currentClass, Vector v) { getClassesAux(currentClass, v); Class[] members = currentClass.getInterfaces(); @@ -244,13 +243,14 @@ } String[] ret = new String[v.size()]; int i = 0; - for (java.util.Enumeration e = v.elements(); e.hasMoreElements();) { - ret[i++] = (String)e.nextElement(); + + for (String name : v) { + ret[i++] = name; } return ret; } - private static void getClassesAux(Class currentClass, Vector v) { + private static void getClassesAux(Class currentClass, Vector v) { if (!v.contains(currentClass.getName())) { v.addElement(currentClass.getName()); } --- old/src/share/classes/com/sun/jndi/ldap/LdapEntry.java 2011-07-27 17:20:15.594277100 -0700 +++ new/src/share/classes/com/sun/jndi/ldap/LdapEntry.java 2011-07-27 17:20:14.984216100 -0700 @@ -27,7 +27,7 @@ import java.util.Vector; import javax.naming.directory.Attributes; -import javax.naming.directory.Attribute; +import javax.naming.ldap.Control; /** * A holder for an LDAP entry read from an LDAP server. @@ -38,14 +38,14 @@ final class LdapEntry { String DN; Attributes attributes; - Vector respCtls = null; + Vector respCtls = null; LdapEntry(String DN, Attributes attrs) { this.DN = DN; this.attributes = attrs; } - LdapEntry(String DN, Attributes attrs, Vector respCtls) { + LdapEntry(String DN, Attributes attrs, Vector respCtls) { this.DN = DN; this.attributes = attrs; this.respCtls = respCtls; --- old/src/share/classes/com/sun/jndi/ldap/LdapName.java 2011-07-27 17:20:21.838901500 -0700 +++ new/src/share/classes/com/sun/jndi/ldap/LdapName.java 2011-07-27 17:20:21.164834100 -0700 @@ -78,7 +78,7 @@ public final class LdapName implements Name { private transient String unparsed; // if non-null, the DN in unparsed form - private transient Vector rdns; // parsed name components + private transient Vector rdns; // parsed name components private transient boolean valuesCaseSensitive = false; /** @@ -97,9 +97,10 @@ * Constructs an LDAP name given its parsed components and, optionally * (if "name" is not null), the unparsed DN. */ - private LdapName(String name, Vector rdns) { + @SuppressWarnings("unchecked") + private LdapName(String name, Vector rdns) { unparsed = name; - this.rdns = (Vector)rdns.clone(); + this.rdns = (Vector)rdns.clone(); } /* @@ -107,9 +108,9 @@ * of "rdns" in the range [beg,end)) and, optionally * (if "name" is not null), the unparsed DN. */ - private LdapName(String name, Vector rdns, int beg, int end) { + private LdapName(String name, Vector rdns, int beg, int end) { unparsed = name; - this.rdns = new Vector(); + this.rdns = new Vector<>(); for (int i = beg; i < end; i++) { this.rdns.addElement(rdns.elementAt(i)); } @@ -130,7 +131,7 @@ if (i < rdns.size() - 1) { buf.append(','); } - Rdn rdn = (Rdn)rdns.elementAt(i); + Rdn rdn = rdns.elementAt(i); buf.append(rdn); } @@ -155,8 +156,8 @@ int minSize = Math.min(rdns.size(), that.rdns.size()); for (int i = 0 ; i < minSize; i++) { // Compare a single pair of RDNs. - Rdn rdn1 = (Rdn)rdns.elementAt(i); - Rdn rdn2 = (Rdn)that.rdns.elementAt(i); + Rdn rdn1 = rdns.elementAt(i); + Rdn rdn2 = that.rdns.elementAt(i); int diff = rdn1.compareTo(rdn2); if (diff != 0) { @@ -172,7 +173,7 @@ // For each RDN... for (int i = 0; i < rdns.size(); i++) { - Rdn rdn = (Rdn)rdns.elementAt(i); + Rdn rdn = rdns.elementAt(i); hash += rdn.hashCode(); } return hash; @@ -186,14 +187,14 @@ return rdns.isEmpty(); } - public Enumeration getAll() { - final Enumeration enum_ = rdns.elements(); + public Enumeration getAll() { + final Enumeration enum_ = rdns.elements(); - return new Enumeration () { + return new Enumeration() { public boolean hasMoreElements() { return enum_.hasMoreElements(); } - public Object nextElement() { + public String nextElement() { return enum_.nextElement().toString(); } }; @@ -254,7 +255,7 @@ Rdn rdn; if (n instanceof LdapName) { LdapName ln = (LdapName)n; - rdn = (Rdn)ln.rdns.elementAt(i - beg); + rdn = ln.rdns.elementAt(i - beg); } else { String rdnString = n.get(i - beg); try { @@ -286,9 +287,9 @@ rdns.insertElementAt(s.rdns.elementAt(i), pos++); } } else { - Enumeration comps = suffix.getAll(); + Enumeration comps = suffix.getAll(); while (comps.hasMoreElements()) { - DnParser p = new DnParser((String)comps.nextElement(), + DnParser p = new DnParser(comps.nextElement(), valuesCaseSensitive); rdns.insertElementAt(p.getRdn(), pos++); } @@ -406,9 +407,9 @@ /* * Parses the DN, returning a Vector of its RDNs. */ - Vector getDn() throws InvalidNameException { + Vector getDn() throws InvalidNameException { cur = 0; - Vector rdns = new Vector(len / 3 + 10); // leave room for growth + Vector rdns = new Vector<>(len / 3 + 10); // leave room for growth if (len == 0) { return rdns; @@ -595,7 +596,7 @@ * A vector of the TypeAndValue elements of this Rdn. * It is sorted to facilitate set operations. */ - private final Vector tvs = new Vector(); + private final Vector tvs = new Vector<>(); void add(TypeAndValue tv) { @@ -636,7 +637,7 @@ int minSize = Math.min(tvs.size(), that.tvs.size()); for (int i = 0; i < minSize; i++) { // Compare a single pair of type/value pairs. - TypeAndValue tv = (TypeAndValue)tvs.elementAt(i); + TypeAndValue tv = tvs.elementAt(i); int diff = tv.compareTo(that.tvs.elementAt(i)); if (diff != 0) { return diff; @@ -662,7 +663,7 @@ Attribute attr; for (int i = 0; i < tvs.size(); i++) { - tv = (TypeAndValue) tvs.elementAt(i); + tv = tvs.elementAt(i); if ((attr = attrs.get(tv.getType())) == null) { attrs.put(tv.getType(), tv.getUnescapedValue()); } else { --- old/src/share/classes/com/sun/jndi/ldap/LdapNamingEnumeration.java 2011-07-27 17:20:28.002517800 -0700 +++ new/src/share/classes/com/sun/jndi/ldap/LdapNamingEnumeration.java 2011-07-27 17:20:27.364454000 -0700 @@ -27,25 +27,26 @@ import javax.naming.*; import javax.naming.directory.*; -import javax.naming.spi.*; import com.sun.jndi.toolkit.ctx.Continuation; import java.util.NoSuchElementException; import java.util.Vector; +import javax.naming.ldap.Control; import javax.naming.ldap.LdapName; /** * Basic enumeration for NameClassPair, Binding, and SearchResults. */ -class LdapNamingEnumeration implements NamingEnumeration, ReferralEnumeration { +class LdapNamingEnumeration implements NamingEnumeration, + ReferralEnumeration { protected Name listArg; private boolean cleaned = false; private LdapResult res; private LdapClient enumClnt; private Continuation cont; // used to fill in exceptions - private Vector entries = null; + private Vector entries = null; private int limit = 0; private int posn = 0; protected LdapCtx homeCtx; @@ -101,7 +102,7 @@ enumClnt = homeCtx.clnt; // remember } - public Object nextElement() { + public NameClassPair nextElement() { try { return next(); } catch (NamingException e) { @@ -146,11 +147,9 @@ // convert referrals into a chain of LdapReferralException homeCtx.processReturnCode(res, listArg); - } catch (LimitExceededException e) { + } catch (LimitExceededException | PartialResultException e) { setNamingException(e); - } catch (PartialResultException e) { - setNamingException(e); } } @@ -193,7 +192,7 @@ /* * Retrieve the next entry. */ - public Object next() throws NamingException { + public NameClassPair next() throws NamingException { if (!hasMoreCalled) { hasMore(); @@ -225,15 +224,9 @@ // try to process another referral return hasMoreReferrals(); - } catch (LdapReferralException e) { - cleanup(); - throw e; - - } catch (LimitExceededException e) { - cleanup(); - throw e; - - } catch (PartialResultException e) { + } catch (LdapReferralException | + LimitExceededException | + PartialResultException e) { cleanup(); throw e; @@ -249,7 +242,7 @@ /* * Retrieve the next entry. */ - private Object nextImpl() throws NamingException { + private NameClassPair nextImpl() throws NamingException { try { return nextAux(); } catch (NamingException e) { @@ -258,7 +251,7 @@ } } - private Object nextAux() throws NamingException { + private NameClassPair nextAux() throws NamingException { if (posn == limit) { getNextBatch(); // updates posn and limit } @@ -268,7 +261,7 @@ throw new NoSuchElementException("invalid enumeration handle"); } - LdapEntry result = (LdapEntry)entries.elementAt(posn++); + LdapEntry result = entries.elementAt(posn++); // gets and outputs DN from the entry return createItem(result.DN, result.attributes, result.respCtls); @@ -287,7 +280,7 @@ } protected NameClassPair createItem(String dn, Attributes attrs, - Vector respCtls) throws NamingException { + Vector respCtls) throws NamingException { Attribute attr; String className = null; --- old/src/share/classes/com/sun/jndi/ldap/LdapPoolManager.java 2011-07-27 17:20:34.363153800 -0700 +++ new/src/share/classes/com/sun/jndi/ldap/LdapPoolManager.java 2011-07-27 17:20:33.664083900 -0700 @@ -214,7 +214,7 @@ * */ static boolean isPoolingAllowed(String socketFactory, OutputStream trace, - String authMech, String protocol, Hashtable env) + String authMech, String protocol, Hashtable env) throws NamingException { if (trace != null && !debug @@ -235,7 +235,7 @@ if ((socketFactory != null) && !socketFactory.equals(LdapCtx.DEFAULT_SSL_FACTORY)) { try { - Class socketFactoryClass = Obj.helper.loadClass(socketFactory); + Class socketFactoryClass = Obj.helper.loadClass(socketFactory); Class[] interfaces = socketFactoryClass.getInterfaces(); for (int i = 0; i < interfaces.length; i++) { if (interfaces[i].getCanonicalName().equals(COMPARATOR)) { @@ -294,7 +294,7 @@ static LdapClient getLdapClient(String host, int port, String socketFactory, int connTimeout, int readTimeout, OutputStream trace, int version, String authMech, Control[] ctls, String protocol, String user, - Object passwd, Hashtable env) throws NamingException { + Object passwd, Hashtable env) throws NamingException { // Create base identity for LdapClient ClientId id = null; @@ -385,9 +385,9 @@ private static final String getProperty(final String propName, final String defVal) { - return (String) AccessController.doPrivileged( - new PrivilegedAction() { - public Object run() { + return AccessController.doPrivileged( + new PrivilegedAction() { + public String run() { try { return System.getProperty(propName, defVal); } catch (SecurityException e) { @@ -399,9 +399,9 @@ private static final int getInteger(final String propName, final int defVal) { - Integer val = (Integer) AccessController.doPrivileged( - new PrivilegedAction() { - public Object run() { + Integer val = AccessController.doPrivileged( + new PrivilegedAction() { + public Integer run() { try { return Integer.getInteger(propName, defVal); } catch (SecurityException e) { @@ -414,9 +414,9 @@ private static final long getLong(final String propName, final long defVal) { - Long val = (Long) AccessController.doPrivileged( - new PrivilegedAction() { - public Object run() { + Long val = AccessController.doPrivileged( + new PrivilegedAction() { + public Long run() { try { return Long.getLong(propName, defVal); } catch (SecurityException e) { --- old/src/share/classes/com/sun/jndi/ldap/LdapReferralContext.java 2011-07-27 17:20:40.607778200 -0700 +++ new/src/share/classes/com/sun/jndi/ldap/LdapReferralContext.java 2011-07-27 17:20:39.943711800 -0700 @@ -52,7 +52,9 @@ private int hopCount = 1; private NamingException previousEx = null; - LdapReferralContext(LdapReferralException ex, Hashtable env, + @SuppressWarnings("unchecked") // clone() + LdapReferralContext(LdapReferralException ex, + Hashtable env, Control[] connCtls, Control[] reqCtls, String nextName, @@ -69,20 +71,21 @@ // Make copies of environment and connect controls for our own use. if (env != null) { - env = (Hashtable) env.clone(); + env = (Hashtable) env.clone(); // Remove old connect controls from environment, unless we have new // ones that will override them anyway. if (connCtls == null) { env.remove(LdapCtx.BIND_CONTROLS); } } else if (connCtls != null) { - env = new Hashtable(5); + env = new Hashtable(5); } if (connCtls != null) { Control[] copiedCtls = new Control[connCtls.length]; System.arraycopy(connCtls, 0, copiedCtls, 0, connCtls.length); // Add copied controls to environment, replacing any old ones. - env.put(LdapCtx.BIND_CONTROLS, copiedCtls); + ((Hashtable)env) + .put(LdapCtx.BIND_CONTROLS, copiedCtls); } while (true) { @@ -260,24 +263,26 @@ refCtx.rename(overrideName(oldName), toName(refEx.getNewRdn())); } - public NamingEnumeration list(String name) throws NamingException { + public NamingEnumeration list(String name) throws NamingException { return list(toName(name)); } - public NamingEnumeration list(Name name) throws NamingException { + @SuppressWarnings("unchecked") + public NamingEnumeration list(Name name) throws NamingException { if (skipThisReferral) { throw (NamingException) ((refEx.appendUnprocessedReferrals(null)).fillInStackTrace()); } try { - NamingEnumeration ne = null; + NamingEnumeration ne = null; if (urlScope != null && urlScope.equals("base")) { SearchControls cons = new SearchControls(); cons.setReturningObjFlag(true); cons.setSearchScope(SearchControls.OBJECT_SCOPE); - ne = refCtx.search(overrideName(name), "(objectclass=*)", cons); + ne = (NamingEnumeration) + refCtx.search(overrideName(name), "(objectclass=*)", cons); } else { ne = refCtx.list(overrideName(name)); @@ -318,25 +323,29 @@ } } - public NamingEnumeration listBindings(String name) throws NamingException { + public NamingEnumeration listBindings(String name) throws + NamingException { return listBindings(toName(name)); } - public NamingEnumeration listBindings(Name name) throws NamingException { + @SuppressWarnings("unchecked") + public NamingEnumeration listBindings(Name name) throws + NamingException { if (skipThisReferral) { throw (NamingException) ((refEx.appendUnprocessedReferrals(null)).fillInStackTrace()); } try { - NamingEnumeration be = null; + NamingEnumeration be = null; if (urlScope != null && urlScope.equals("base")) { SearchControls cons = new SearchControls(); cons.setReturningObjFlag(true); cons.setSearchScope(SearchControls.OBJECT_SCOPE); - be = refCtx.search(overrideName(name), "(objectclass=*)", cons); + be = (NamingEnumeration)refCtx.search(overrideName(name), + "(objectclass=*)", cons); } else { be = refCtx.listBindings(overrideName(name)); @@ -347,7 +356,7 @@ // append (referrals from) the exception that generated this // context to the new search results, so that referral processing // can continue - ((ReferralEnumeration)be).appendUnprocessedReferrals(refEx); + ((ReferralEnumeration)be).appendUnprocessedReferrals(refEx); return (be); @@ -462,7 +471,7 @@ return refCtx.removeFromEnvironment(propName); } - public Hashtable getEnvironment() throws NamingException { + public Hashtable getEnvironment() throws NamingException { if (skipThisReferral) { throw (NamingException) ((refEx.appendUnprocessedReferrals(null)).fillInStackTrace()); @@ -602,23 +611,23 @@ return refCtx.getSchemaClassDefinition(overrideName(name)); } - public NamingEnumeration search(String name, - Attributes matchingAttributes) + public NamingEnumeration search(String name, + Attributes matchingAttributes) throws NamingException { return search(toName(name), SearchFilter.format(matchingAttributes), new SearchControls()); } - public NamingEnumeration search(Name name, - Attributes matchingAttributes) + public NamingEnumeration search(Name name, + Attributes matchingAttributes) throws NamingException { return search(name, SearchFilter.format(matchingAttributes), new SearchControls()); } - public NamingEnumeration search(String name, - Attributes matchingAttributes, - String[] attributesToReturn) + public NamingEnumeration search(String name, + Attributes matchingAttributes, + String[] attributesToReturn) throws NamingException { SearchControls cons = new SearchControls(); cons.setReturningAttributes(attributesToReturn); @@ -627,9 +636,9 @@ cons); } - public NamingEnumeration search(Name name, - Attributes matchingAttributes, - String[] attributesToReturn) + public NamingEnumeration search(Name name, + Attributes matchingAttributes, + String[] attributesToReturn) throws NamingException { SearchControls cons = new SearchControls(); cons.setReturningAttributes(attributesToReturn); @@ -637,15 +646,15 @@ return search(name, SearchFilter.format(matchingAttributes), cons); } - public NamingEnumeration search(String name, - String filter, - SearchControls cons) + public NamingEnumeration search(String name, + String filter, + SearchControls cons) throws NamingException { return search(toName(name), filter, cons); } - public NamingEnumeration search(Name name, - String filter, + public NamingEnumeration search(Name name, + String filter, SearchControls cons) throws NamingException { if (skipThisReferral) { @@ -654,8 +663,10 @@ } try { - NamingEnumeration se = refCtx.search(overrideName(name), - overrideFilter(filter), overrideAttributesAndScope(cons)); + NamingEnumeration se = + refCtx.search(overrideName(name), + overrideFilter(filter), + overrideAttributesAndScope(cons)); refEx.setNameResolved(true); @@ -694,15 +705,15 @@ } } - public NamingEnumeration search(String name, - String filterExpr, - Object[] filterArgs, - SearchControls cons) + public NamingEnumeration search(String name, + String filterExpr, + Object[] filterArgs, + SearchControls cons) throws NamingException { return search(toName(name), filterExpr, filterArgs, cons); } - public NamingEnumeration search(Name name, + public NamingEnumeration search(Name name, String filterExpr, Object[] filterArgs, SearchControls cons) throws NamingException { @@ -713,7 +724,7 @@ } try { - NamingEnumeration se; + NamingEnumeration se; if (urlFilter != null) { se = refCtx.search(overrideName(name), urlFilter, --- old/src/share/classes/com/sun/jndi/ldap/LdapReferralException.java 2011-07-27 17:20:46.835400900 -0700 +++ new/src/share/classes/com/sun/jndi/ldap/LdapReferralException.java 2011-07-27 17:20:46.159333300 -0700 @@ -26,7 +26,6 @@ package com.sun.jndi.ldap; import javax.naming.*; -import javax.naming.spi.*; import javax.naming.ldap.Control; import java.util.Hashtable; @@ -67,15 +66,16 @@ */ final public class LdapReferralException extends javax.naming.ldap.LdapReferralException { + private static final long serialVersionUID = 627059076356906399L; // ----------- fields initialized in constructor --------------- private int handleReferrals; - private Hashtable envprops; + private Hashtable envprops; private String nextName; private Control[] reqCtls; // ----------- fields that have defaults ----------------------- - private Vector referrals = null; // alternatives,set by setReferralInfo() + private Vector referrals = null; // alternatives,set by setReferralInfo() private int referralIndex = 0; // index into referrals private int referralCount = 0; // count of referrals private boolean foundEntry = false; // will stop when entry is found @@ -98,7 +98,7 @@ Object resolvedObj, Name remainingName, String explanation, - Hashtable envprops, + Hashtable envprops, String nextName, int handleReferrals, Control[] reqCtls) { @@ -210,7 +210,7 @@ /** * Sets referral information. */ - void setReferralInfo(Vector referrals, boolean continuationRef) { + void setReferralInfo(Vector referrals, boolean continuationRef) { // %%% continuationRef is currently ignored if (debug) --- old/src/share/classes/com/sun/jndi/ldap/LdapResult.java 2011-07-27 17:20:53.017019000 -0700 +++ new/src/share/classes/com/sun/jndi/ldap/LdapResult.java 2011-07-27 17:20:52.344951800 -0700 @@ -28,6 +28,7 @@ import java.util.Vector; import javax.naming.directory.Attributes; import javax.naming.directory.BasicAttributes; +import javax.naming.ldap.Control; /** * %%% public for use by LdapSasl %%% @@ -37,10 +38,11 @@ public int status; // %%% public for use by LdapSasl String matchedDN; String errorMessage; - Vector referrals = null; + // Vector> + Vector referrals = null; LdapReferralException refEx = null; - Vector entries = null; - Vector resControls = null; + Vector entries = null; + Vector resControls = null; public byte[] serverCreds = null; // %%% public for use by LdapSasl String extensionId = null; // string OID byte[] extensionValue = null; // BER OCTET STRING @@ -57,7 +59,7 @@ switch (status) { case LdapClient.LDAP_COMPARE_TRUE: status = LdapClient.LDAP_SUCCESS; - entries = new Vector(1,1); + entries = new Vector<>(1,1); Attributes attrs = new BasicAttributes(LdapClient.caseIgnore); LdapEntry entry = new LdapEntry( name, attrs ); entries.addElement(entry); @@ -66,7 +68,7 @@ case LdapClient.LDAP_COMPARE_FALSE: status = LdapClient.LDAP_SUCCESS; - entries = new Vector(0); + entries = new Vector<>(0); successful = true; break; --- old/src/share/classes/com/sun/jndi/ldap/LdapSchemaCtx.java 2011-07-27 17:20:58.957613000 -0700 +++ new/src/share/classes/com/sun/jndi/ldap/LdapSchemaCtx.java 2011-07-27 17:20:58.297547000 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1999, 2003, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1999, 2011, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -61,8 +61,9 @@ private int objectType; - static DirContext createSchemaTree(Hashtable env, String subschemasubentry, - LdapCtx schemaEntry, Attributes schemaAttrs, boolean netscapeBug) + static DirContext createSchemaTree(Hashtable env, + String subschemasubentry, LdapCtx schemaEntry, + Attributes schemaAttrs, boolean netscapeBug) throws NamingException { try { LdapSchemaParser parser = new LdapSchemaParser(netscapeBug); @@ -71,7 +72,7 @@ schemaEntry, parser); LdapSchemaCtx root = new LdapSchemaCtx(SCHEMA_ROOT, env, allinfo); - parser.LDAP2JNDISchema(schemaAttrs, root); + LdapSchemaParser.LDAP2JNDISchema(schemaAttrs, root); return root; } catch (NamingException e) { schemaEntry.close(); // cleanup @@ -80,7 +81,8 @@ } // Called by createNewCtx - private LdapSchemaCtx(int objectType, Hashtable environment, SchemaInfo info) { + private LdapSchemaCtx(int objectType, Hashtable environment, + SchemaInfo info) { super(environment, LdapClient.caseIgnore); this.objectType = objectType; @@ -223,9 +225,9 @@ final private static Attributes deepClone(Attributes orig) throws NamingException { BasicAttributes copy = new BasicAttributes(true); - NamingEnumeration attrs = orig.getAll(); + NamingEnumeration attrs = orig.getAll(); while (attrs.hasMore()) { - copy.put((Attribute)((Attribute)attrs.next()).clone()); + copy.put((Attribute)attrs.next().clone()); } return copy; } @@ -409,13 +411,14 @@ } } - private LdapCtx reopenEntry(Hashtable env) throws NamingException { + private LdapCtx reopenEntry(Hashtable env) throws NamingException { // Use subschemasubentry name as DN return new LdapCtx(schemaEntryName, host, port, env, hasLdapsScheme); } - synchronized void modifyAttributes(Hashtable env, ModificationItem[] mods) + synchronized void modifyAttributes(Hashtable env, + ModificationItem[] mods) throws NamingException { if (schemaEntry == null) { schemaEntry = reopenEntry(env); @@ -423,7 +426,7 @@ schemaEntry.modifyAttributes("", mods); } - synchronized void modifyAttributes(Hashtable env, int mod, + synchronized void modifyAttributes(Hashtable env, int mod, Attributes attrs) throws NamingException { if (schemaEntry == null) { schemaEntry = reopenEntry(env); --- old/src/share/classes/com/sun/jndi/ldap/LdapSchemaParser.java 2011-07-27 17:21:05.207237900 -0700 +++ new/src/share/classes/com/sun/jndi/ldap/LdapSchemaParser.java 2011-07-27 17:21:04.530170200 -0700 @@ -27,7 +27,6 @@ import javax.naming.*; import javax.naming.directory.*; -import java.util.Hashtable; import java.util.Vector; /** @@ -141,9 +140,9 @@ LdapSchemaCtx schemaRoot) throws NamingException { - NamingEnumeration objDescs; - Attributes objDef; - LdapSchemaCtx classDefTree; + NamingEnumeration objDescs; + Attributes objDef; + LdapSchemaCtx classDefTree; // create the class def subtree Attributes attrs = new BasicAttributes(LdapClient.caseIgnore); @@ -173,9 +172,9 @@ LdapSchemaCtx schemaRoot) throws NamingException { - NamingEnumeration attrDescs; - Attributes attrDef; - LdapSchemaCtx attrDefTree; + NamingEnumeration attrDescs; + Attributes attrDef; + LdapSchemaCtx attrDefTree; // create the AttributeDef subtree Attributes attrs = new BasicAttributes(LdapClient.caseIgnore); @@ -206,9 +205,9 @@ LdapSchemaCtx schemaRoot) throws NamingException { - NamingEnumeration syntaxDescs; - Attributes syntaxDef; - LdapSchemaCtx syntaxDefTree; + NamingEnumeration syntaxDescs; + Attributes syntaxDef; + LdapSchemaCtx syntaxDefTree; // create the SyntaxDef subtree Attributes attrs = new BasicAttributes(LdapClient.caseIgnore); @@ -239,9 +238,9 @@ LdapSchemaCtx schemaRoot) throws NamingException { - NamingEnumeration matchRuleDescs; - Attributes matchRuleDef; - LdapSchemaCtx matchRuleDefTree; + NamingEnumeration matchRuleDescs; + Attributes matchRuleDef; + LdapSchemaCtx matchRuleDefTree; // create the MatchRuleDef subtree Attributes attrs = new BasicAttributes(LdapClient.caseIgnore); @@ -519,8 +518,8 @@ final private static String[] readQDescrList(String string, int[] pos) throws NamingException { - int begin, end; - Vector values = new Vector(5); + int begin, end; + Vector values = new Vector<>(5); if (debug) { System.err.println("ReadQDescrList: pos="+pos[0]); @@ -553,7 +552,7 @@ String[] answer = new String[values.size()]; for (int i = 0; i < answer.length; i++) { - answer[i] = (String)values.elementAt(i); + answer[i] = values.elementAt(i); } return answer; } @@ -614,7 +613,7 @@ int begin, cur, end; String oidName = null; - Vector values = new Vector(5); + Vector values = new Vector<>(5); if (debug) { System.err.println("ReadOIDList: pos="+pos[0]); @@ -663,7 +662,7 @@ String[] answer = new String[values.size()]; for (int i = 0; i < answer.length; i++) { - answer[i] = (String)values.elementAt(i); + answer[i] = values.elementAt(i); } return answer; } @@ -843,10 +842,10 @@ String attrId = null; // use enumeration because attribute ID is not known - for (NamingEnumeration ae = attrs.getAll(); + for (NamingEnumeration ae = attrs.getAll(); ae.hasMoreElements(); ) { - attr = (Attribute)ae.next(); + attr = ae.next(); attrId = attr.getID(); // skip those already processed @@ -973,10 +972,10 @@ String attrId = null; // use enumeration because attribute ID is not known - for (NamingEnumeration ae = attrs.getAll(); + for (NamingEnumeration ae = attrs.getAll(); ae.hasMoreElements(); ) { - attr = (Attribute)ae.next(); + attr = ae.next(); attrId = attr.getID(); // skip those already processed @@ -1040,10 +1039,10 @@ String attrId = null; // use enumeration because attribute ID is not known - for (NamingEnumeration ae = attrs.getAll(); + for (NamingEnumeration ae = attrs.getAll(); ae.hasMoreElements(); ) { - attr = (Attribute)ae.next(); + attr = ae.next(); attrId = attr.getID(); // skip those already processed @@ -1117,10 +1116,10 @@ String attrId = null; // use enumeration because attribute ID is not known - for (NamingEnumeration ae = attrs.getAll(); + for (NamingEnumeration ae = attrs.getAll(); ae.hasMoreElements(); ) { - attr = (Attribute)ae.next(); + attr = ae.next(); attrId = attr.getID(); // skip those already processed @@ -1201,7 +1200,7 @@ qdList.append(WHSP); qdList.append(OID_LIST_BEGIN); - NamingEnumeration values = attr.getAll(); + NamingEnumeration values = attr.getAll(); while(values.hasMore()) { qdList.append(WHSP); @@ -1238,7 +1237,7 @@ oidList.append(WHSP); oidList.append(OID_LIST_BEGIN); - NamingEnumeration values = oidsAttr.getAll(); + NamingEnumeration values = oidsAttr.getAll(); oidList.append(WHSP); oidList.append(values.next()); --- old/src/share/classes/com/sun/jndi/ldap/LdapSearchEnumeration.java 2011-07-27 17:21:11.324849600 -0700 +++ new/src/share/classes/com/sun/jndi/ldap/LdapSearchEnumeration.java 2011-07-27 17:21:10.671784300 -0700 @@ -53,7 +53,7 @@ } protected NameClassPair - createItem(String dn, Attributes attrs, Vector respCtls) + createItem(String dn, Attributes attrs, Vector respCtls) throws NamingException { Object obj = null; @@ -181,10 +181,10 @@ super.appendUnprocessedReferrals(ex); } - protected LdapNamingEnumeration + protected LdapSearchEnumeration getReferredResults(LdapReferralContext refCtx) throws NamingException { // repeat the original operation at the new context - return (LdapSearchEnumeration) + return (LdapSearchEnumeration)(NamingEnumeration) refCtx.search(searchArgs.name, searchArgs.filter, searchArgs.cons); } --- old/src/share/classes/com/sun/jndi/ldap/NamingEventNotifier.java 2011-07-27 17:21:17.512468300 -0700 +++ new/src/share/classes/com/sun/jndi/ldap/NamingEventNotifier.java 2011-07-27 17:21:16.846401700 -0700 @@ -50,12 +50,12 @@ final class NamingEventNotifier implements Runnable { private final static boolean debug = false; - private Vector namingListeners; + private Vector namingListeners; private Thread worker; private LdapCtx context; private EventContext eventSrc; private EventSupport support; - private NamingEnumeration results; + private NamingEnumeration results; // package private; used by EventSupport to remove it NotifierArgs info; @@ -83,7 +83,7 @@ context = (LdapCtx)ctx.newInstance(new Control[]{psearch}); eventSrc = ctx; - namingListeners = new Vector(); + namingListeners = new Vector<>(); namingListeners.addElement(firstListener); worker = Obj.helper.createThread(this); @@ -124,7 +124,8 @@ // Change root of search results so that it will generate // names relative to the event context instead of that // named by nm - ((LdapSearchEnumeration)results).setStartName(context.currentParsedDN); + ((LdapSearchEnumeration)(NamingEnumeration)results) + .setStartName(context.currentParsedDN); SearchResult si; Control[] respctls; @@ -132,7 +133,7 @@ long changeNum; while (results.hasMore()) { - si = (SearchResult)results.next(); + si = results.next(); respctls = (si instanceof HasControls) ? ((HasControls) si).getControls() : null; --- old/src/share/classes/com/sun/jndi/ldap/NotifierArgs.java 2011-07-27 17:21:23.586075600 -0700 +++ new/src/share/classes/com/sun/jndi/ldap/NotifierArgs.java 2011-07-27 17:21:22.922009200 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1999, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1999, 2011, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -133,7 +133,7 @@ private int controlsCode() { if (controls == null) return 0; - int total = (int)controls.getTimeLimit() + (int)controls.getCountLimit() + + int total = controls.getTimeLimit() + (int)controls.getCountLimit() + (controls.getDerefLinkFlag() ? 1 : 0) + (controls.getReturningObjFlag() ? 1 : 0); --- old/src/share/classes/com/sun/jndi/ldap/Obj.java 2011-07-27 17:21:29.717688700 -0700 +++ new/src/share/classes/com/sun/jndi/ldap/Obj.java 2011-07-27 17:21:29.090626000 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1999, 2005, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1999, 2011, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -84,6 +84,7 @@ /** * @deprecated */ + @Deprecated private static final int REMOTE_LOC = 7; // LDAP object classes to support Java objects @@ -206,13 +207,13 @@ } else { StringTokenizer parser = new StringTokenizer((String)codebaseAttr.get()); - Vector vec = new Vector(10); + Vector vec = new Vector<>(10); while (parser.hasMoreTokens()) { vec.addElement(parser.nextToken()); } String[] answer = new String[vec.size()]; for (int i = 0; i < answer.length; i++) { - answer[i] = (String)vec.elementAt(i); + answer[i] = vec.elementAt(i); } return answer; } @@ -410,10 +411,10 @@ * Temporary Vector for decoded RefAddr addresses - used to ensure * unordered addresses are correctly re-ordered. */ - Vector refAddrList = new Vector(); + Vector refAddrList = new Vector<>(); refAddrList.setSize(attr.size()); - for (NamingEnumeration vals = attr.getAll(); vals.hasMore(); ) { + for (NamingEnumeration vals = attr.getAll(); vals.hasMore(); ) { val = (String)vals.next(); @@ -488,7 +489,7 @@ // Copy to real reference for (int i = 0; i < refAddrList.size(); i++) { - ref.add((RefAddr)refAddrList.elementAt(i)); + ref.add(refAddrList.elementAt(i)); } } @@ -502,9 +503,9 @@ try { ByteArrayOutputStream bytes = new ByteArrayOutputStream(); - ObjectOutputStream serial = new ObjectOutputStream(bytes); - serial.writeObject(obj); - serial.close(); + try (ObjectOutputStream serial = new ObjectOutputStream(bytes)) { + serial.writeObject(obj); + } return (bytes.toByteArray()); @@ -524,18 +525,14 @@ try { // Create ObjectInputStream for deserialization ByteArrayInputStream bytes = new ByteArrayInputStream(obj); - ObjectInputStream deserial = (cl == null ? - new ObjectInputStream(bytes) : - new LoaderInputStream(bytes, cl)); - - try { + try (ObjectInputStream deserial = cl == null ? + new ObjectInputStream(bytes) : + new LoaderInputStream(bytes, cl)) { return deserial.readObject(); } catch (ClassNotFoundException e) { NamingException ne = new NamingException(); ne.setRootCause(e); throw ne; - } finally { - deserial.close(); } } catch (IOException e) { NamingException ne = new NamingException(); @@ -549,7 +546,7 @@ */ static Attributes determineBindAttrs( char separator, Object obj, Attributes attrs, boolean cloned, - Name name, Context ctx, Hashtable env) + Name name, Context ctx, Hashtable env) throws NamingException { // Call state factories to convert object and attrs @@ -582,10 +579,10 @@ } else { // Get existing objectclass attribute - objectClass = (Attribute)attrs.get("objectClass"); + objectClass = attrs.get("objectClass"); if (objectClass == null && !attrs.isCaseIgnored()) { // %%% workaround - objectClass = (Attribute)attrs.get("objectclass"); + objectClass = attrs.get("objectclass"); } // No objectclasses supplied, use "top" to start @@ -614,8 +611,8 @@ classLoader = cl; } - protected Class resolveClass(ObjectStreamClass desc) throws IOException, - ClassNotFoundException { + protected Class resolveClass(ObjectStreamClass desc) throws + IOException, ClassNotFoundException { try { // %%% Should use Class.forName(desc.getName(), false, classLoader); // except we can't because that is only available on JDK1.2 @@ -625,15 +622,15 @@ } } - protected Class resolveProxyClass(String[] interfaces) throws + protected Class resolveProxyClass(String[] interfaces) throws IOException, ClassNotFoundException { ClassLoader nonPublicLoader = null; boolean hasNonPublicInterface = false; // define proxy in class loader of non-public interface(s), if any - Class[] classObjs = new Class[interfaces.length]; + Class[] classObjs = new Class<>[interfaces.length]; for (int i = 0; i < interfaces.length; i++) { - Class cl = Class.forName(interfaces[i], false, classLoader); + Class cl = Class.forName(interfaces[i], false, classLoader); if ((cl.getModifiers() & Modifier.PUBLIC) == 0) { if (hasNonPublicInterface) { if (nonPublicLoader != cl.getClassLoader()) { --- old/src/share/classes/com/sun/jndi/ldap/ReferralEnumeration.java 2011-07-27 17:21:35.795296400 -0700 +++ new/src/share/classes/com/sun/jndi/ldap/ReferralEnumeration.java 2011-07-27 17:21:35.153232200 -0700 @@ -27,6 +27,6 @@ import javax.naming.NamingEnumeration; -interface ReferralEnumeration extends NamingEnumeration { +interface ReferralEnumeration extends NamingEnumeration { void appendUnprocessedReferrals(LdapReferralException ex); } --- old/src/share/classes/com/sun/jndi/ldap/ServiceLocator.java 2011-07-27 17:21:42.133930200 -0700 +++ new/src/share/classes/com/sun/jndi/ldap/ServiceLocator.java 2011-07-27 17:21:41.382855100 -0700 @@ -26,9 +26,7 @@ package com.sun.jndi.ldap; import java.util.Arrays; -import java.util.Enumeration; import java.util.Hashtable; -import java.util.NoSuchElementException; import java.util.Random; import java.util.StringTokenizer; import java.util.List; @@ -39,8 +37,6 @@ import javax.naming.ldap.LdapName; import javax.naming.ldap.Rdn; -import com.sun.jndi.ldap.LdapURL; - /** * This class discovers the location of LDAP services by querying DNS. * See http://www.ietf.org/internet-drafts/draft-ietf-ldapext-locate-07.txt @@ -78,10 +74,10 @@ // process RDNs left-to-right //List rdnList = ldapName.getRdns(); - List rdnList = ldapName.getRdns(); + List rdnList = ldapName.getRdns(); for (int i = rdnList.size() - 1; i >= 0; i--) { //Rdn rdn = rdnList.get(i); - Rdn rdn = (Rdn) rdnList.get(i); + Rdn rdn = rdnList.get(i); // single-valued RDN with a DC attribute if ((rdn.size() == 1) && @@ -117,7 +113,7 @@ * @return An ordered list of hostports for the LDAP service or null if * the service has not been located. */ - static String[] getLdapService(String domainName, Hashtable environment) { + static String[] getLdapService(String domainName, Hashtable environment) { if (domainName == null || domainName.length() == 0) { return null; @@ -252,7 +248,7 @@ * See http://www.ietf.org/rfc/rfc2782.txt */ -static class SrvRecord implements Comparable { +static class SrvRecord implements Comparable { int priority; int weight; @@ -284,8 +280,7 @@ * Sort records in ascending order of priority value. For records with * equal priority move those with weight 0 to the top of the list. */ - public int compareTo(Object o) { - SrvRecord that = (SrvRecord) o; + public int compareTo(SrvRecord that) { if (priority > that.priority) { return 1; // this > that } else if (priority < that.priority) { --- old/src/share/classes/com/sun/jndi/ldap/SimpleClientId.java 2011-07-27 17:21:48.984615200 -0700 +++ new/src/share/classes/com/sun/jndi/ldap/SimpleClientId.java 2011-07-27 17:21:48.190535800 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2002, 2005, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2002, 2011, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -54,9 +54,9 @@ } else if (passwd instanceof String) { this.passwd = passwd; } else if (passwd instanceof byte[]) { - this.passwd = (byte[]) ((byte[])passwd).clone(); + this.passwd = ((byte[])passwd).clone(); } else if (passwd instanceof char[]) { - this.passwd = (char[]) ((char[])passwd).clone(); + this.passwd = ((char[])passwd).clone(); } else { this.passwd = passwd; } --- old/src/share/classes/com/sun/jndi/ldap/UnsolicitedResponseImpl.java 2011-07-27 17:21:55.526269300 -0700 +++ new/src/share/classes/com/sun/jndi/ldap/UnsolicitedResponseImpl.java 2011-07-27 17:21:54.804197100 -0700 @@ -41,7 +41,7 @@ private NamingException exception; private Control[] controls; - UnsolicitedResponseImpl(String oid, byte[] berVal, Vector ref, + UnsolicitedResponseImpl(String oid, byte[] berVal, Vector ref, int status, String msg, String matchedDN, Control[] controls) { this.oid = oid; this.extensionValue = berVal; --- old/src/share/classes/com/sun/jndi/ldap/VersionHelper.java 2011-07-27 17:22:01.652881900 -0700 +++ new/src/share/classes/com/sun/jndi/ldap/VersionHelper.java 2011-07-27 17:22:01.006817300 -0700 @@ -72,7 +72,7 @@ return urlArray; } - abstract Class loadClass(String className) throws ClassNotFoundException; + abstract Class loadClass(String className) throws ClassNotFoundException; abstract Thread createThread(Runnable r); } --- old/src/share/classes/com/sun/jndi/ldap/VersionHelper12.java 2011-07-27 17:22:07.945511100 -0700 +++ new/src/share/classes/com/sun/jndi/ldap/VersionHelper12.java 2011-07-27 17:22:07.293445900 -0700 @@ -66,15 +66,15 @@ } } - Class loadClass(String className) throws ClassNotFoundException { + Class loadClass(String className) throws ClassNotFoundException { ClassLoader cl = getContextClassLoader(); return Class.forName(className, true, cl); } private ClassLoader getContextClassLoader() { - return (ClassLoader) AccessController.doPrivileged( - new PrivilegedAction() { - public Object run() { + return AccessController.doPrivileged( + new PrivilegedAction() { + public ClassLoader run() { return Thread.currentThread().getContextClassLoader(); } } @@ -82,9 +82,9 @@ } Thread createThread(final Runnable r) { - return (Thread) AccessController.doPrivileged( - new PrivilegedAction() { - public Object run() { + return AccessController.doPrivileged( + new PrivilegedAction() { + public Thread run() { return new Thread(r); } } --- old/src/share/classes/com/sun/jndi/ldap/ext/StartTlsResponseImpl.java 2011-07-27 17:22:14.193135800 -0700 +++ new/src/share/classes/com/sun/jndi/ldap/ext/StartTlsResponseImpl.java 2011-07-27 17:22:13.526069100 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2000, 2003, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -27,16 +27,8 @@ import java.io.InputStream; import java.io.OutputStream; -import java.io.BufferedInputStream; -import java.io.BufferedOutputStream; import java.io.IOException; -import java.net.Socket; - -import java.util.Collection; -import java.util.Iterator; -import java.util.List; - import java.security.Principal; import java.security.cert.X509Certificate; import java.security.cert.CertificateException; @@ -45,11 +37,9 @@ import javax.net.ssl.SSLSocket; import javax.net.ssl.SSLSocketFactory; import javax.net.ssl.SSLPeerUnverifiedException; -import javax.net.ssl.SSLContext; import javax.net.ssl.HostnameVerifier; import sun.security.util.HostnameChecker; -import javax.naming.*; import javax.naming.ldap.*; import com.sun.jndi.ldap.Connection; @@ -415,7 +405,7 @@ // Use ciphersuite to determine whether Kerberos is active. if (session.getCipherSuite().startsWith("TLS_KRB5")) { Principal principal = getPeerPrincipal(session); - if (!checker.match(hostname, principal)) { + if (!HostnameChecker.match(hostname, principal)) { throw new SSLPeerUnverifiedException( "hostname of the kerberos principal:" + principal + " does not match the hostname:" + hostname); --- old/src/share/classes/com/sun/jndi/ldap/pool/Connections.java 2011-07-27 17:22:20.240740500 -0700 +++ new/src/share/classes/com/sun/jndi/ldap/pool/Connections.java 2011-07-27 17:22:19.639680400 -0700 @@ -71,10 +71,10 @@ final private int maxSize; final private int prefSize; - final private List conns; + final private List conns; private boolean closed = false; // Closed for business - private Reference ref; // maintains reference to id to prevent premature GC + private Reference ref; // maintains reference to id to prevent premature GC /** * @param id the identity (connection request) of the connections in the list @@ -99,11 +99,11 @@ } else { this.prefSize = prefSize; } - conns = new ArrayList(maxSize > 0 ? maxSize : DEFAULT_SIZE); + conns = new ArrayList<>(maxSize > 0 ? maxSize : DEFAULT_SIZE); // Maintain soft ref to id so that this Connections' entry in // Pool doesn't get GC'ed prematurely - ref = new SoftReference(id); + ref = new SoftReference<>(id); d("init size=", initSize); d("max size=", maxSize); @@ -186,7 +186,7 @@ // exceeds prefSize, then first look for an idle connection ConnectionDesc entry; for (int i = 0; i < size; i++) { - entry = (ConnectionDesc) conns.get(i); + entry = conns.get(i); if ((conn = entry.tryUse()) != null) { d("get(): use ", conn); td("Use ", conn); @@ -239,7 +239,7 @@ td("Release ", conn); // Get ConnectionDesc from list to get correct state info - entry = (ConnectionDesc) conns.get(loc); + entry = conns.get(loc); // Return connection to list, ready for reuse entry.release(); } @@ -291,10 +291,10 @@ * @return true if no more connections in list */ synchronized boolean expire(long threshold) { - Iterator iter = conns.iterator(); + Iterator iter = conns.iterator(); ConnectionDesc entry; while (iter.hasNext()) { - entry = (ConnectionDesc) iter.next(); + entry = iter.next(); if (entry.expire(threshold)) { d("expire(): removing ", entry); td("Expired ", entry); @@ -333,7 +333,7 @@ ConnectionDesc entry; for (int i = 0; i < len; i++) { - entry = (ConnectionDesc) conns.get(i); + entry = conns.get(i); use += entry.getUseCount(); switch (entry.getState()) { case ConnectionDesc.BUSY: --- old/src/share/classes/com/sun/jndi/ldap/pool/ConnectionsWeakRef.java 2011-07-27 17:22:26.340350400 -0700 +++ new/src/share/classes/com/sun/jndi/ldap/pool/ConnectionsWeakRef.java 2011-07-27 17:22:25.693285700 -0700 @@ -55,11 +55,12 @@ * reference to Connections used for closing (which in turn terminates * the Connection thread) it by monitoring the ReferenceQueue. */ -class ConnectionsWeakRef extends WeakReference { +class ConnectionsWeakRef extends WeakReference { private final Connections conns; - ConnectionsWeakRef (ConnectionsRef connsRef, ReferenceQueue queue) { + ConnectionsWeakRef (ConnectionsRef connsRef, + ReferenceQueue queue) { super(connsRef, queue); this.conns = connsRef.getConnections(); } --- old/src/share/classes/com/sun/jndi/ldap/pool/Pool.java 2011-07-27 17:22:32.426959000 -0700 +++ new/src/share/classes/com/sun/jndi/ldap/pool/Pool.java 2011-07-27 17:22:31.744890800 -0700 @@ -30,7 +30,6 @@ import java.util.Collection; import java.util.Collections; import java.util.Iterator; -import java.util.Set; import java.util.LinkedList; import java.io.PrintStream; @@ -83,17 +82,18 @@ /* * Used for connections cleanup */ - private static final ReferenceQueue queue = new ReferenceQueue(); - private static final Collection weakRefs = - Collections.synchronizedList(new LinkedList()); + private static final ReferenceQueue queue = + new ReferenceQueue<>(); + private static final Collection> weakRefs = + Collections.synchronizedList(new LinkedList>()); final private int maxSize; // max num of identical conn per pool final private int prefSize; // preferred num of identical conn per pool final private int initSize; // initial number of identical conn to create - final private Map map; + final private Map map; public Pool(int initSize, int prefSize, int maxSize) { - map = new WeakHashMap(); + map = new WeakHashMap<>(); this.prefSize = prefSize; this.maxSize = maxSize; this.initSize = initSize; @@ -135,7 +135,8 @@ map.put(id, connsRef); // Create a weak reference to ConnectionsRef - Reference weakRef = new ConnectionsWeakRef(connsRef, queue); + Reference weakRef = + new ConnectionsWeakRef(connsRef, queue); // Keep the weak reference through the element of a linked list weakRefs.add(weakRef); @@ -148,7 +149,7 @@ } private Connections getConnections(Object id) { - ConnectionsRef ref = (ConnectionsRef) map.get(id); + ConnectionsRef ref = map.get(id); return (ref != null) ? ref.getConnections() : null; } @@ -163,11 +164,10 @@ */ public void expire(long threshold) { synchronized (map) { - Collection coll = map.values(); - Iterator iter = coll.iterator(); + Iterator iter = map.values().iterator(); Connections conns; while (iter.hasNext()) { - conns = ((ConnectionsRef) (iter.next())).getConnections(); + conns = iter.next().getConnections(); if (conns.expire(threshold)) { d("expire(): removing ", conns); iter.remove(); @@ -202,7 +202,6 @@ public void showStats(PrintStream out) { - Map.Entry entry; Object id; Connections conns; @@ -212,13 +211,9 @@ out.println("initial pool size: " + initSize); out.println("current pool size: " + map.size()); - Set entries = map.entrySet(); - Iterator iter = entries.iterator(); - - while (iter.hasNext()) { - entry = (Map.Entry) iter.next(); + for (Map.Entry entry : map.entrySet()) { id = entry.getKey(); - conns = ((ConnectionsRef) entry.getValue()).getConnections(); + conns = entry.getValue().getConnections(); out.println(" " + id + ":" + conns.getStats()); } --- old/src/share/classes/com/sun/jndi/ldap/pool/PoolCleaner.java 2011-07-27 17:22:38.509567200 -0700 +++ new/src/share/classes/com/sun/jndi/ldap/pool/PoolCleaner.java 2011-07-27 17:22:37.861502400 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2002, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2002, 2011, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -41,7 +41,7 @@ public PoolCleaner(long period, Pool[] pools) { super(); this.period = period; - this.pools = (Pool[]) pools.clone(); + this.pools = pools.clone(); setDaemon(true); } --- old/src/share/classes/com/sun/jndi/ldap/sasl/DefaultCallbackHandler.java 2011-07-27 17:22:44.647180900 -0700 +++ new/src/share/classes/com/sun/jndi/ldap/sasl/DefaultCallbackHandler.java 2011-07-27 17:22:43.990115200 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1999, 2003, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1999, 2011, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -57,7 +57,7 @@ if (cred instanceof String) { passwd = ((String)cred).toCharArray(); } else if (cred instanceof char[]) { - passwd = (char[])((char[])cred).clone(); + passwd = ((char[])cred).clone(); } else if (cred != null) { // assume UTF-8 encoding String orig = new String((byte[])cred, "UTF8"); --- old/src/share/classes/com/sun/jndi/ldap/sasl/LdapSasl.java 2011-07-27 17:22:50.797795900 -0700 +++ new/src/share/classes/com/sun/jndi/ldap/sasl/LdapSasl.java 2011-07-27 17:22:50.088725000 -0700 @@ -89,9 +89,10 @@ * @param bindCtls The possibly null controls to accompany the bind * @return LdapResult containing status of the bind */ + @SuppressWarnings("unchecked") public static LdapResult saslBind(LdapClient clnt, Connection conn, String server, String dn, Object pw, - String authMech, Hashtable env, Control[] bindCtls) + String authMech, Hashtable env, Control[] bindCtls) throws IOException, NamingException { SaslClient saslClnt = null; @@ -112,7 +113,7 @@ try { // Create SASL client to use using SASL package saslClnt = Sasl.createSaslClient( - mechs, authzId, "ldap", server, env, cbh); + mechs, authzId, "ldap", server, (Hashtable)env, cbh); if (saslClnt == null) { throw new AuthenticationNotSupportedException(authMech); @@ -185,13 +186,13 @@ */ private static String[] getSaslMechanismNames(String str) { StringTokenizer parser = new StringTokenizer(str); - Vector mechs = new Vector(10); + Vector mechs = new Vector<>(10); while (parser.hasMoreTokens()) { mechs.addElement(parser.nextToken()); } String[] mechNames = new String[mechs.size()]; for (int i = 0; i < mechs.size(); i++) { - mechNames[i] = (String)mechs.elementAt(i); + mechNames[i] = mechs.elementAt(i); } return mechNames; } --- old/src/share/classes/com/sun/jndi/rmi/registry/RegistryContext.java 2011-07-27 17:22:56.826398700 -0700 +++ new/src/share/classes/com/sun/jndi/rmi/registry/RegistryContext.java 2011-07-27 17:22:56.197335800 -0700 @@ -46,7 +46,7 @@ public class RegistryContext implements Context, Referenceable { - private Hashtable environment; + private Hashtable environment; private Registry registry; private String host; private int port; @@ -67,10 +67,13 @@ * Cloning of "env" is handled by caller; see comments within * RegistryContextFactory.getObjectInstance(), for example. */ - public RegistryContext(String host, int port, Hashtable env) + @SuppressWarnings("unchecked") + public RegistryContext(String host, int port, Hashtable env) throws NamingException { - environment = ((env == null) ? new Hashtable(5) : env); + environment = (env == null) + ? new Hashtable(5) + : (Hashtable) env; if (environment.get(SECURITY_MGR) != null) { installSecurityMgr(); } @@ -93,8 +96,9 @@ * won't close the other). */ // %%% Alternatively, this could be done with a clone() method. + @SuppressWarnings("unchecked") // clone() RegistryContext(RegistryContext ctx) { - environment = (Hashtable)ctx.environment.clone(); + environment = (Hashtable)ctx.environment.clone(); registry = ctx.registry; host = ctx.host; port = ctx.port; @@ -195,7 +199,8 @@ rename(new CompositeName(name), new CompositeName(newName)); } - public NamingEnumeration list(Name name) throws NamingException { + public NamingEnumeration list(Name name) throws + NamingException { if (!name.isEmpty()) { throw (new InvalidNameException( "RegistryContext: can only list \"\"")); @@ -208,11 +213,12 @@ } } - public NamingEnumeration list(String name) throws NamingException { + public NamingEnumeration list(String name) throws + NamingException { return list(new CompositeName(name)); } - public NamingEnumeration listBindings(Name name) + public NamingEnumeration listBindings(Name name) throws NamingException { if (!name.isEmpty()) { @@ -227,7 +233,8 @@ } } - public NamingEnumeration listBindings(String name) throws NamingException { + public NamingEnumeration listBindings(String name) throws + NamingException { return listBindings(new CompositeName(name)); } @@ -290,8 +297,9 @@ return environment.put(propName, propVal); } - public Hashtable getEnvironment() throws NamingException { - return (Hashtable)environment.clone(); + @SuppressWarnings("unchecked") // clone() + public Hashtable getEnvironment() throws NamingException { + return (Hashtable)environment.clone(); } public void close() { @@ -483,11 +491,9 @@ /** - * An enumeration of name / class-name pairs. Since we don't know anything - * about the classes, each class name is returned as the generic - * "java.lang.Object". + * An enumeration of name / class-name pairs. */ -class NameClassPairEnumeration implements NamingEnumeration { +class NameClassPairEnumeration implements NamingEnumeration { private final String[] names; private int nextName; // index into "names" @@ -500,7 +506,7 @@ return (nextName < names.length); } - public Object next() throws NamingException { + public NameClassPair next() throws NamingException { if (!hasMore()) { throw (new java.util.NoSuchElementException()); } @@ -518,7 +524,7 @@ return hasMore(); } - public Object nextElement() { + public NameClassPair nextElement() { try { return next(); } catch (NamingException e) { // should never happen @@ -541,7 +547,7 @@ * requested. The problem with that approach is that Binding.getObject() * cannot throw NamingException. */ -class BindingEnumeration implements NamingEnumeration { +class BindingEnumeration implements NamingEnumeration { private RegistryContext ctx; private final String[] names; private int nextName; // index into "names" @@ -564,7 +570,7 @@ return (nextName < names.length); } - public Object next() throws NamingException { + public Binding next() throws NamingException { if (!hasMore()) { throw (new java.util.NoSuchElementException()); } @@ -584,7 +590,7 @@ return hasMore(); } - public Object nextElement() { + public Binding nextElement() { try { return next(); } catch (NamingException e) { --- old/src/share/classes/com/sun/jndi/rmi/registry/RegistryContextFactory.java 2011-07-27 17:23:02.973013300 -0700 +++ new/src/share/classes/com/sun/jndi/rmi/registry/RegistryContextFactory.java 2011-07-27 17:23:02.333949400 -0700 @@ -95,7 +95,7 @@ return obj; } - private static Context URLToContext(String url, Hashtable env) + private static Context URLToContext(String url, Hashtable env) throws NamingException { rmiURLContextFactory factory = new rmiURLContextFactory(); @@ -108,7 +108,7 @@ } } - private static Object URLsToObject(String[] urls, Hashtable env) + private static Object URLsToObject(String[] urls, Hashtable env) throws NamingException { rmiURLContextFactory factory = new rmiURLContextFactory(); @@ -119,7 +119,7 @@ * Reads environment to find URL of initial context. * The default URL is "rmi:". */ - private static String getInitCtxURL(Hashtable env) { + private static String getInitCtxURL(Hashtable env) { final String defaultURL = "rmi:"; @@ -152,9 +152,9 @@ int size = 0; // number of URLs String[] urls = new String[ref.size()]; - Enumeration addrs = ref.getAll(); + Enumeration addrs = ref.getAll(); while (addrs.hasMoreElements()) { - RefAddr addr = (RefAddr)addrs.nextElement(); + RefAddr addr = addrs.nextElement(); if ((addr instanceof StringRefAddr) && addr.getType().equals(ADDRESS_TYPE)) { --- old/src/share/classes/com/sun/jndi/toolkit/corba/CorbaUtils.java 2011-07-27 17:23:09.185634500 -0700 +++ new/src/share/classes/com/sun/jndi/toolkit/corba/CorbaUtils.java 2011-07-27 17:23:08.553571300 -0700 @@ -158,7 +158,7 @@ * Use all String properties from env for initializing ORB * @return A non-null ORB. */ - public static ORB getOrb(String server, int port, Hashtable env) { + public static ORB getOrb(String server, int port, Hashtable env) { // See if we can get info from environment Properties orbProp; @@ -169,7 +169,7 @@ orbProp = (Properties) env.clone(); } else { // Get all String properties - Enumeration envProp; + Enumeration envProp; orbProp = new Properties(); for (envProp = env.keys(); envProp.hasMoreElements();) { String key = (String)envProp.nextElement(); @@ -239,7 +239,7 @@ // Fields used for reflection of RMI-IIOP private static Method toStubMethod = null; private static Method connectMethod = null; - private static Class corbaStubClass = null; + private static Class corbaStubClass = null; /** * Initializes reflection method handles for RMI-IIOP. * @exception ClassNotFoundException javax.rmi.CORBA.* not available @@ -252,19 +252,19 @@ try { connectMethod = corbaStubClass.getMethod("connect", - new Class[] {org.omg.CORBA.ORB.class}); + new Class<>[] {org.omg.CORBA.ORB.class}); } catch (NoSuchMethodException e) { throw new IllegalStateException( "No method definition for javax.rmi.CORBA.Stub.connect(org.omg.CORBA.ORB)"); } - // Get javax.rmi.PortableRemoteObject method - Class proClass = Class.forName("javax.rmi.PortableRemoteObject"); + // Get javax.rmi.PortableRemoteObject class + Class proClass = Class.forName("javax.rmi.PortableRemoteObject"); - // Get javax.rmi.PortableRemoteObject(java.rmi.Remote) method + // Get javax.rmi.PortableRemoteObject.toStub(java.rmi.Remote) method try { toStubMethod = proClass.getMethod("toStub", - new Class[] {java.rmi.Remote.class}); + new Class[] {java.rmi.Remote.class}); } catch (NoSuchMethodException e) { throw new IllegalStateException( --- old/src/share/classes/com/sun/jndi/toolkit/ctx/AtomicContext.java 2011-07-27 17:23:15.406256500 -0700 +++ new/src/share/classes/com/sun/jndi/toolkit/ctx/AtomicContext.java 2011-07-27 17:23:14.742190100 -0700 @@ -26,7 +26,6 @@ package com.sun.jndi.toolkit.ctx; import javax.naming.*; -import javax.naming.spi.ResolveResult; /** * Clients: deal only with names for its own naming service @@ -58,9 +57,9 @@ protected abstract Object a_lookupLink(String name, Continuation cont) throws NamingException; - protected abstract NamingEnumeration a_list( + protected abstract NamingEnumeration a_list( Continuation cont) throws NamingException; - protected abstract NamingEnumeration a_listBindings( + protected abstract NamingEnumeration a_listBindings( Continuation cont) throws NamingException; protected abstract void a_bind(String name, Object obj, Continuation cont) throws NamingException; @@ -193,12 +192,12 @@ return null; } - protected NamingEnumeration a_list_nns(Continuation cont) + protected NamingEnumeration a_list_nns(Continuation cont) throws NamingException { a_processJunction_nns(cont); return null; } - protected NamingEnumeration a_listBindings_nns(Continuation cont) + protected NamingEnumeration a_listBindings_nns(Continuation cont) throws NamingException { a_processJunction_nns(cont); return null; @@ -273,7 +272,7 @@ return null; } - protected NamingEnumeration c_list(Name name, + protected NamingEnumeration c_list(Name name, Continuation cont) throws NamingException { if (resolve_to_context(name, cont)) { return a_list(cont); @@ -281,7 +280,7 @@ return null; } - protected NamingEnumeration c_listBindings(Name name, + protected NamingEnumeration c_listBindings(Name name, Continuation cont) throws NamingException { if (resolve_to_context(name, cont)) { return a_listBindings(cont); @@ -392,7 +391,7 @@ } } - protected NamingEnumeration c_list_nns(Name name, + protected NamingEnumeration c_list_nns(Name name, Continuation cont) throws NamingException { if (_contextType == _ATOMIC) { resolve_to_nns_and_continue(name, cont); @@ -403,14 +402,14 @@ } } - protected NamingEnumeration c_listBindings_nns(Name name, + protected NamingEnumeration c_listBindings_nns(Name name, Continuation cont) throws NamingException { if (_contextType == _ATOMIC) { resolve_to_nns_and_continue(name, cont); return null; } else { // use ComponentContext - return super.c_list_nns(name, cont); + return super.c_listBindings_nns(name, cont); } } --- old/src/share/classes/com/sun/jndi/toolkit/ctx/AtomicDirContext.java 2011-07-27 17:23:21.519867800 -0700 +++ new/src/share/classes/com/sun/jndi/toolkit/ctx/AtomicDirContext.java 2011-07-27 17:23:20.861802000 -0700 @@ -27,7 +27,6 @@ import javax.naming.*; import javax.naming.directory.*; -import javax.naming.spi.ResolveResult; /** * Direct subclasses of AtomicDirContext must provide implementations for @@ -79,20 +78,25 @@ Continuation cont) throws NamingException; - protected abstract NamingEnumeration a_search(Attributes matchingAttributes, + protected abstract NamingEnumeration a_search( + Attributes matchingAttributes, String[] attributesToReturn, Continuation cont) throws NamingException; - protected abstract NamingEnumeration a_search(String name, + protected abstract NamingEnumeration a_search( + String name, String filterExpr, Object[] filterArgs, - SearchControls cons, Continuation cont) + SearchControls cons, + Continuation cont) throws NamingException; - protected abstract NamingEnumeration a_search(String name, + protected abstract NamingEnumeration a_search( + String name, String filter, - SearchControls cons, Continuation cont) + SearchControls cons, + Continuation cont) throws NamingException; protected abstract DirContext a_getSchema(Continuation cont) @@ -163,7 +167,8 @@ return null; } - protected NamingEnumeration a_search_nns(Attributes matchingAttributes, + protected NamingEnumeration a_search_nns( + Attributes matchingAttributes, String[] attributesToReturn, Continuation cont) throws NamingException { @@ -171,20 +176,20 @@ return null; } - protected NamingEnumeration a_search_nns(String name, - String filterExpr, - Object[] filterArgs, - SearchControls cons, - Continuation cont) + protected NamingEnumeration a_search_nns(String name, + String filterExpr, + Object[] filterArgs, + SearchControls cons, + Continuation cont) throws NamingException { a_processJunction_nns(name, cont); return null; } - protected NamingEnumeration a_search_nns(String name, - String filter, - SearchControls cons, - Continuation cont) + protected NamingEnumeration a_search_nns(String name, + String filter, + SearchControls cons, + Continuation cont) throws NamingException { a_processJunction_nns(name, cont); return null; @@ -250,7 +255,7 @@ return null; } - protected NamingEnumeration c_search(Name name, + protected NamingEnumeration c_search(Name name, Attributes matchingAttributes, String[] attributesToReturn, Continuation cont) @@ -260,19 +265,21 @@ return null; } - protected NamingEnumeration c_search(Name name, - String filter, - SearchControls cons, Continuation cont) + protected NamingEnumeration c_search(Name name, + String filter, + SearchControls cons, + Continuation cont) throws NamingException { if (resolve_to_penultimate_context(name, cont)) return a_search(name.toString(), filter, cons, cont); return null; } - protected NamingEnumeration c_search(Name name, - String filterExpr, - Object[] filterArgs, - SearchControls cons, Continuation cont) + protected NamingEnumeration c_search(Name name, + String filterExpr, + Object[] filterArgs, + SearchControls cons, + Continuation cont) throws NamingException { if (resolve_to_penultimate_context(name, cont)) return a_search(name.toString(), filterExpr, filterArgs, cons, cont); @@ -340,7 +347,8 @@ return null; } - protected NamingEnumeration c_search_nns(Name name, + protected NamingEnumeration c_search_nns( + Name name, Attributes matchingAttributes, String[] attributesToReturn, Continuation cont) @@ -349,20 +357,21 @@ return null; } - protected NamingEnumeration c_search_nns(Name name, - String filter, - SearchControls cons, Continuation cont) + protected NamingEnumeration c_search_nns(Name name, + String filter, + SearchControls cons, + Continuation cont) throws NamingException { if (resolve_to_penultimate_context_nns(name, cont)) return a_search_nns(name.toString(), filter, cons, cont); return null; } - protected NamingEnumeration c_search_nns(Name name, - String filterExpr, - Object[] filterArgs, - SearchControls cons, - Continuation cont) + protected NamingEnumeration c_search_nns(Name name, + String filterExpr, + Object[] filterArgs, + SearchControls cons, + Continuation cont) throws NamingException { if (resolve_to_penultimate_context_nns(name, cont)) return a_search_nns(name.toString(), filterExpr, filterArgs, --- old/src/share/classes/com/sun/jndi/toolkit/ctx/ComponentContext.java 2011-07-27 17:23:27.772493000 -0700 +++ new/src/share/classes/com/sun/jndi/toolkit/ctx/ComponentContext.java 2011-07-27 17:23:27.119427700 -0700 @@ -25,8 +25,6 @@ package com.sun.jndi.toolkit.ctx; -import java.util.Hashtable; - import javax.naming.*; import javax.naming.spi.ResolveResult; @@ -57,9 +55,9 @@ protected abstract Object c_lookupLink(Name name, Continuation cont) throws NamingException; - protected abstract NamingEnumeration c_list(Name name, + protected abstract NamingEnumeration c_list(Name name, Continuation cont) throws NamingException; - protected abstract NamingEnumeration c_listBindings(Name name, + protected abstract NamingEnumeration c_listBindings(Name name, Continuation cont) throws NamingException; protected abstract void c_bind(Name name, Object obj, Continuation cont) throws NamingException; @@ -237,13 +235,13 @@ return null; } - protected NamingEnumeration c_list_nns(Name name, + protected NamingEnumeration c_list_nns(Name name, Continuation cont) throws NamingException { c_processJunction_nns(name, cont); return null; } - protected NamingEnumeration c_listBindings_nns(Name name, + protected NamingEnumeration c_listBindings_nns(Name name, Continuation cont) throws NamingException { c_processJunction_nns(name, cont); return null; @@ -495,7 +493,7 @@ /* implementation for Resolver method */ protected ResolveResult p_resolveToClass(Name name, - Class contextType, + Class contextType, Continuation cont) throws NamingException { @@ -556,9 +554,9 @@ return ret; } - protected NamingEnumeration p_list(Name name, Continuation cont) + protected NamingEnumeration p_list(Name name, Continuation cont) throws NamingException { - NamingEnumeration ret = null; + NamingEnumeration ret = null; HeadTail res = p_resolveIntermediate(name, cont); switch (res.getStatus()) { case TERMINAL_NNS_COMPONENT: @@ -581,9 +579,9 @@ return ret; } - protected NamingEnumeration p_listBindings(Name name, Continuation cont) throws + protected NamingEnumeration p_listBindings(Name name, Continuation cont) throws NamingException { - NamingEnumeration ret = null; + NamingEnumeration ret = null; HeadTail res = p_resolveIntermediate(name, cont); switch (res.getStatus()) { case TERMINAL_NNS_COMPONENT: --- old/src/share/classes/com/sun/jndi/toolkit/ctx/ComponentDirContext.java 2011-07-27 17:23:34.264142100 -0700 +++ new/src/share/classes/com/sun/jndi/toolkit/ctx/ComponentDirContext.java 2011-07-27 17:23:33.551070800 -0700 @@ -28,8 +28,6 @@ import javax.naming.*; import javax.naming.directory.*; -import javax.naming.spi.ResolveResult; - /* Direct subclasses of ComponentDirContext must provide implementations for * the abstract c_ DirContext methods, and override the c_ Context methods * (which are no longer abstract because they have been overriden by @@ -81,23 +79,26 @@ Continuation cont) throws NamingException; - protected abstract NamingEnumeration c_search(Name name, - Attributes matchingAttributes, - String[] attributesToReturn, - Continuation cont) + protected abstract NamingEnumeration c_search( + Name name, + Attributes matchingAttributes, + String[] attributesToReturn, + Continuation cont) throws NamingException; - protected abstract NamingEnumeration c_search(Name name, - String filter, - SearchControls cons, - Continuation cont) + protected abstract NamingEnumeration c_search( + Name name, + String filter, + SearchControls cons, + Continuation cont) throws NamingException; - protected abstract NamingEnumeration c_search(Name name, - String filterExpr, - Object[] filterArgs, - SearchControls cons, - Continuation cont) + protected abstract NamingEnumeration c_search( + Name name, + String filterExpr, + Object[] filterArgs, + SearchControls cons, + Continuation cont) throws NamingException; protected abstract DirContext c_getSchema(Name name, Continuation cont) @@ -172,29 +173,32 @@ return null; } - protected NamingEnumeration c_search_nns(Name name, - Attributes matchingAttributes, - String[] attributesToReturn, - Continuation cont) + protected NamingEnumeration c_search_nns( + Name name, + Attributes matchingAttributes, + String[] attributesToReturn, + Continuation cont) throws NamingException { c_processJunction_nns(name, cont); return null; } - protected NamingEnumeration c_search_nns(Name name, - String filter, - SearchControls cons, - Continuation cont) + protected NamingEnumeration c_search_nns( + Name name, + String filter, + SearchControls cons, + Continuation cont) throws NamingException { c_processJunction_nns(name, cont); return null; } - protected NamingEnumeration c_search_nns(Name name, - String filterExpr, - Object[] filterArgs, - SearchControls cons, - Continuation cont) + protected NamingEnumeration c_search_nns( + Name name, + String filterExpr, + Object[] filterArgs, + SearchControls cons, + Continuation cont) throws NamingException { c_processJunction_nns(name, cont); return null; @@ -345,13 +349,14 @@ return answer; } - protected NamingEnumeration p_search(Name name, - Attributes matchingAttributes, - String[] attributesToReturn, - Continuation cont) + protected NamingEnumeration p_search( + Name name, + Attributes matchingAttributes, + String[] attributesToReturn, + Continuation cont) throws NamingException { HeadTail res = p_resolveIntermediate(name, cont); - NamingEnumeration answer = null; + NamingEnumeration answer = null; switch (res.getStatus()) { case TERMINAL_NNS_COMPONENT: answer = c_search_nns(res.getHead(), matchingAttributes, @@ -371,12 +376,13 @@ return answer; } - protected NamingEnumeration p_search(Name name, - String filter, - SearchControls cons, Continuation cont) + protected NamingEnumeration p_search(Name name, + String filter, + SearchControls cons, + Continuation cont) throws NamingException { HeadTail res = p_resolveIntermediate(name, cont); - NamingEnumeration answer = null; + NamingEnumeration answer = null; switch (res.getStatus()) { case TERMINAL_NNS_COMPONENT: answer = c_search_nns(res.getHead(), filter, cons, cont); @@ -394,14 +400,14 @@ return answer; } - protected NamingEnumeration p_search(Name name, - String filterExpr, - Object[] filterArgs, - SearchControls cons, - Continuation cont) + protected NamingEnumeration p_search(Name name, + String filterExpr, + Object[] filterArgs, + SearchControls cons, + Continuation cont) throws NamingException { HeadTail res = p_resolveIntermediate(name, cont); - NamingEnumeration answer = null; + NamingEnumeration answer = null; switch (res.getStatus()) { case TERMINAL_NNS_COMPONENT: answer = c_search_nns(res.getHead(), --- old/src/share/classes/com/sun/jndi/toolkit/ctx/Continuation.java 2011-07-27 17:23:41.423858000 -0700 +++ new/src/share/classes/com/sun/jndi/toolkit/ctx/Continuation.java 2011-07-27 17:23:40.725788200 -0700 @@ -57,7 +57,7 @@ * The environment used by the caller. Initialized by constructor and * used when filling out a CannotProceedException. */ - protected Hashtable environment = null; + protected Hashtable environment = null; /** * Indicates whether the Continuation instance indicates that the operation @@ -94,7 +94,7 @@ * @param environment The environment used by the caller. It is used * when setting the "environment" of a CannotProceedException. */ - public Continuation(Name top, Hashtable environment) { + public Continuation(Name top, Hashtable environment) { super(); starter = top; this.environment = environment; @@ -154,8 +154,8 @@ if ((e instanceof CannotProceedException)) { CannotProceedException cpe = (CannotProceedException)e; - Hashtable env = (environment == null ? - new Hashtable(11) : (Hashtable)environment.clone()); + Hashtable env = (environment == null ? + new Hashtable<>(11) : (Hashtable)environment.clone()); cpe.setEnvironment(env); cpe.setAltNameCtx(resolvedContext); cpe.setAltName(relativeResolvedName); --- old/src/share/classes/com/sun/jndi/toolkit/ctx/PartialCompositeContext.java 2011-07-27 17:23:48.026518200 -0700 +++ new/src/share/classes/com/sun/jndi/toolkit/ctx/PartialCompositeContext.java 2011-07-27 17:23:47.335449100 -0700 @@ -77,16 +77,16 @@ /* Equivalent to method in Resolver interface */ protected abstract ResolveResult p_resolveToClass(Name name, - Class contextType, Continuation cont) throws NamingException; + Class contextType, Continuation cont) throws NamingException; /* Equivalent to methods in Context interface */ protected abstract Object p_lookup(Name name, Continuation cont) throws NamingException; protected abstract Object p_lookupLink(Name name, Continuation cont) throws NamingException; - protected abstract NamingEnumeration p_list(Name name, + protected abstract NamingEnumeration p_list(Name name, Continuation cont) throws NamingException; - protected abstract NamingEnumeration p_listBindings(Name name, + protected abstract NamingEnumeration p_listBindings(Name name, Continuation cont) throws NamingException; protected abstract void p_bind(Name name, Object obj, Continuation cont) throws NamingException; @@ -115,7 +115,7 @@ * The toolkit knows to clone when necessary. * @return The possibly null environment of the context. */ - protected Hashtable p_getEnvironment() throws NamingException { + protected Hashtable p_getEnvironment() throws NamingException { return getEnvironment(); } @@ -137,7 +137,7 @@ throws NamingException { PartialCompositeContext ctx = this; - Hashtable env = p_getEnvironment(); + Hashtable env = p_getEnvironment(); Continuation cont = new Continuation(name, env); ResolveResult answer; Name nm = name; @@ -168,7 +168,7 @@ public Object lookup(Name name) throws NamingException { PartialCompositeContext ctx = this; - Hashtable env = p_getEnvironment(); + Hashtable env = p_getEnvironment(); Continuation cont = new Continuation(name, env); Object answer; Name nm = name; @@ -194,7 +194,7 @@ public void bind(Name name, Object newObj) throws NamingException { PartialCompositeContext ctx = this; Name nm = name; - Hashtable env = p_getEnvironment(); + Hashtable env = p_getEnvironment(); Continuation cont = new Continuation(name, env); try { @@ -216,7 +216,7 @@ public void rebind(Name name, Object newObj) throws NamingException { PartialCompositeContext ctx = this; Name nm = name; - Hashtable env = p_getEnvironment(); + Hashtable env = p_getEnvironment(); Continuation cont = new Continuation(name, env); try { @@ -238,7 +238,7 @@ public void unbind(Name name) throws NamingException { PartialCompositeContext ctx = this; Name nm = name; - Hashtable env = p_getEnvironment(); + Hashtable env = p_getEnvironment(); Continuation cont = new Continuation(name, env); try { @@ -262,7 +262,7 @@ { PartialCompositeContext ctx = this; Name nm = oldName; - Hashtable env = p_getEnvironment(); + Hashtable env = p_getEnvironment(); Continuation cont = new Continuation(oldName, env); try { @@ -293,8 +293,8 @@ { PartialCompositeContext ctx = this; Name nm = name; - NamingEnumeration answer; - Hashtable env = p_getEnvironment(); + NamingEnumeration answer; + Hashtable env = p_getEnvironment(); Continuation cont = new Continuation(name, env); try { @@ -322,8 +322,8 @@ { PartialCompositeContext ctx = this; Name nm = name; - NamingEnumeration answer; - Hashtable env = p_getEnvironment(); + NamingEnumeration answer; + Hashtable env = p_getEnvironment(); Continuation cont = new Continuation(name, env); try { @@ -347,7 +347,7 @@ public void destroySubcontext(Name name) throws NamingException { PartialCompositeContext ctx = this; Name nm = name; - Hashtable env = p_getEnvironment(); + Hashtable env = p_getEnvironment(); Continuation cont = new Continuation(name, env); try { @@ -371,7 +371,7 @@ PartialCompositeContext ctx = this; Name nm = name; Context answer; - Hashtable env = p_getEnvironment(); + Hashtable env = p_getEnvironment(); Continuation cont = new Continuation(name, env); try { @@ -394,7 +394,7 @@ public Object lookupLink(Name name) throws NamingException { PartialCompositeContext ctx = this; - Hashtable env = p_getEnvironment(); + Hashtable env = p_getEnvironment(); Continuation cont = new Continuation(name, env); Object answer; Name nm = name; @@ -421,7 +421,7 @@ PartialCompositeContext ctx = this; Name nm = name; NameParser answer; - Hashtable env = p_getEnvironment(); + Hashtable env = p_getEnvironment(); Continuation cont = new Continuation(name, env); try { --- old/src/share/classes/com/sun/jndi/toolkit/ctx/PartialCompositeDirContext.java 2011-07-27 17:23:54.327148200 -0700 +++ new/src/share/classes/com/sun/jndi/toolkit/ctx/PartialCompositeDirContext.java 2011-07-27 17:23:53.699085400 -0700 @@ -29,7 +29,6 @@ import javax.naming.*; import javax.naming.directory.*; -import javax.naming.spi.NamingManager; import javax.naming.spi.DirectoryManager; /* @@ -83,23 +82,26 @@ Continuation cont) throws NamingException; - protected abstract NamingEnumeration p_search(Name name, - Attributes matchingAttributes, - String[] attributesToReturn, - Continuation cont) - throws NamingException; - - protected abstract NamingEnumeration p_search(Name name, - String filter, - SearchControls cons, - Continuation cont) - throws NamingException; - - protected abstract NamingEnumeration p_search(Name name, - String filterExpr, - Object[] filterArgs, - SearchControls cons, - Continuation cont) + protected abstract NamingEnumeration p_search( + Name name, + Attributes matchingAttributes, + String[] attributesToReturn, + Continuation cont) + throws NamingException; + + protected abstract NamingEnumeration p_search( + Name name, + String filter, + SearchControls cons, + Continuation cont) + throws NamingException; + + protected abstract NamingEnumeration p_search( + Name name, + String filterExpr, + Object[] filterArgs, + SearchControls cons, + Continuation cont) throws NamingException; protected abstract DirContext p_getSchema(Name name, Continuation cont) @@ -130,7 +132,7 @@ public Attributes getAttributes(Name name, String[] attrIds) throws NamingException { PartialCompositeDirContext ctx = this; - Hashtable env = p_getEnvironment(); + Hashtable env = p_getEnvironment(); Continuation cont = new Continuation(name, env); Attributes answer; Name nm = name; @@ -157,7 +159,7 @@ public void modifyAttributes(Name name, int mod_op, Attributes attrs) throws NamingException { PartialCompositeDirContext ctx = this; - Hashtable env = p_getEnvironment(); + Hashtable env = p_getEnvironment(); Continuation cont = new Continuation(name, env); Name nm = name; @@ -182,7 +184,7 @@ public void modifyAttributes(Name name, ModificationItem[] mods) throws NamingException { PartialCompositeDirContext ctx = this; - Hashtable env = p_getEnvironment(); + Hashtable env = p_getEnvironment(); Continuation cont = new Continuation(name, env); Name nm = name; @@ -207,7 +209,7 @@ public void bind(Name name, Object obj, Attributes attrs) throws NamingException { PartialCompositeDirContext ctx = this; - Hashtable env = p_getEnvironment(); + Hashtable env = p_getEnvironment(); Continuation cont = new Continuation(name, env); Name nm = name; @@ -232,7 +234,7 @@ public void rebind(Name name, Object obj, Attributes attrs) throws NamingException { PartialCompositeDirContext ctx = this; - Hashtable env = p_getEnvironment(); + Hashtable env = p_getEnvironment(); Continuation cont = new Continuation(name, env); Name nm = name; @@ -257,7 +259,7 @@ public DirContext createSubcontext(Name name, Attributes attrs) throws NamingException { PartialCompositeDirContext ctx = this; - Hashtable env = p_getEnvironment(); + Hashtable env = p_getEnvironment(); Continuation cont = new Continuation(name, env); DirContext answer; Name nm = name; @@ -308,9 +310,9 @@ { PartialCompositeDirContext ctx = this; - Hashtable env = p_getEnvironment(); + Hashtable env = p_getEnvironment(); Continuation cont = new Continuation(name, env); - NamingEnumeration answer; + NamingEnumeration answer; Name nm = name; try { @@ -347,9 +349,9 @@ { PartialCompositeDirContext ctx = this; - Hashtable env = p_getEnvironment(); + Hashtable env = p_getEnvironment(); Continuation cont = new Continuation(name, env); - NamingEnumeration answer; + NamingEnumeration answer; Name nm = name; try { @@ -385,9 +387,9 @@ { PartialCompositeDirContext ctx = this; - Hashtable env = p_getEnvironment(); + Hashtable env = p_getEnvironment(); Continuation cont = new Continuation(name, env); - NamingEnumeration answer; + NamingEnumeration answer; Name nm = name; try { @@ -411,7 +413,7 @@ public DirContext getSchema(Name name) throws NamingException { PartialCompositeDirContext ctx = this; - Hashtable env = p_getEnvironment(); + Hashtable env = p_getEnvironment(); Continuation cont = new Continuation(name, env); DirContext answer; Name nm = name; @@ -438,7 +440,7 @@ public DirContext getSchemaClassDefinition(Name name) throws NamingException { PartialCompositeDirContext ctx = this; - Hashtable env = p_getEnvironment(); + Hashtable env = p_getEnvironment(); Continuation cont = new Continuation(name, env); DirContext answer; Name nm = name; @@ -509,14 +511,14 @@ throw cont.fillInException(e); } - protected NamingEnumeration a_list( + protected NamingEnumeration a_list( Continuation cont) throws NamingException { OperationNotSupportedException e = new OperationNotSupportedException(); throw cont.fillInException(e); } - protected NamingEnumeration a_listBindings( + protected NamingEnumeration a_listBindings( Continuation cont) throws NamingException { OperationNotSupportedException e = new OperationNotSupportedException(); --- old/src/share/classes/com/sun/jndi/toolkit/dir/ContainmentFilter.java 2011-07-27 17:24:00.467762200 -0700 +++ new/src/share/classes/com/sun/jndi/toolkit/dir/ContainmentFilter.java 2011-07-27 17:23:59.835699000 -0700 @@ -56,19 +56,19 @@ if (subset == null) return true; // an empty set is always a subset - NamingEnumeration m = subset.getAll(); + NamingEnumeration m = subset.getAll(); while (m.hasMore()) { if (superset == null) { return false; // contains nothing } - Attribute target = (Attribute) m.next(); + Attribute target = m.next(); Attribute fromSuper = superset.get(target.getID()); if (fromSuper == null) { return false; } else { // check whether attribute values match if (target.size() > 0) { - NamingEnumeration vals = target.getAll(); + NamingEnumeration vals = target.getAll(); while (vals.hasMore()) { if (!fromSuper.contains(vals.next())) { return false; --- old/src/share/classes/com/sun/jndi/toolkit/dir/ContextEnumerator.java 2011-07-27 17:24:06.646380000 -0700 +++ new/src/share/classes/com/sun/jndi/toolkit/dir/ContextEnumerator.java 2011-07-27 17:24:05.999315300 -0700 @@ -33,10 +33,10 @@ * * @author Jon Ruiz */ -public class ContextEnumerator implements NamingEnumeration { +public class ContextEnumerator implements NamingEnumeration { private static boolean debug = false; - private NamingEnumeration children = null; + private NamingEnumeration children = null; private Binding currentChild = null; private boolean currentReturned = false; private Context root; @@ -77,7 +77,7 @@ } // Subclass should override if it wants to avoid calling obj factory - protected NamingEnumeration getImmediateChildren(Context ctx) + protected NamingEnumeration getImmediateChildren(Context ctx) throws NamingException { return ctx.listBindings(""); } @@ -101,7 +101,7 @@ } } - public Object nextElement() { + public Binding nextElement() { try { return next(); } catch (NamingException e) { @@ -109,7 +109,7 @@ } } - public Object next() throws NamingException { + public Binding next() throws NamingException { if (!rootProcessed) { rootProcessed = true; return new Binding("", root.getClass().getName(), @@ -132,7 +132,7 @@ } private Binding getNextChild() throws NamingException { - Binding oldBinding = ((Binding)children.next()); + Binding oldBinding = children.next(); Binding newBinding = null; // if the name is relative, we need to add it to the name of this @@ -192,7 +192,7 @@ if(debug) {System.out.println("getNextDescedant: expanded case");} // if the current child is expanded, use it's enumerator - return (Binding)currentChildEnum.next(); + return currentChildEnum.next(); } else { --- old/src/share/classes/com/sun/jndi/toolkit/dir/DirSearch.java 2011-07-27 17:24:12.701985500 -0700 +++ new/src/share/classes/com/sun/jndi/toolkit/dir/DirSearch.java 2011-07-27 17:24:12.038919200 -0700 @@ -34,7 +34,7 @@ * @author Jon Ruiz */ public class DirSearch { - public static NamingEnumeration search(DirContext ctx, + public static NamingEnumeration search(DirContext ctx, Attributes matchingAttributes, String[] attributesToReturn) throws NamingException { SearchControls cons = new SearchControls( @@ -48,7 +48,7 @@ cons); } - public static NamingEnumeration search(DirContext ctx, + public static NamingEnumeration search(DirContext ctx, String filter, SearchControls cons) throws NamingException { if (cons == null) @@ -60,7 +60,7 @@ cons); } - public static NamingEnumeration search(DirContext ctx, + public static NamingEnumeration search(DirContext ctx, String filterExpr, Object[] filterArgs, SearchControls cons) throws NamingException { --- old/src/share/classes/com/sun/jndi/toolkit/dir/HierMemDirCtx.java 2011-07-27 17:24:18.718587100 -0700 +++ new/src/share/classes/com/sun/jndi/toolkit/dir/HierMemDirCtx.java 2011-07-27 17:24:18.048520100 -0700 @@ -42,8 +42,8 @@ static private final boolean debug = false; private static final NameParser defaultParser = new HierarchicalNameParser(); - protected Hashtable myEnv; - protected Hashtable bindings; + protected Hashtable myEnv; + protected Hashtable bindings; protected Attributes attrs; protected boolean ignoreCase = false; protected NamingException readOnlyEx = null; @@ -70,12 +70,12 @@ this(null, ignoreCase, false); } - public HierMemDirCtx(Hashtable environment, boolean ignoreCase) { + public HierMemDirCtx(Hashtable environment, boolean ignoreCase) { this(environment, ignoreCase, false); } - protected HierMemDirCtx(Hashtable environment, boolean ignoreCase, - boolean useFac) { + protected HierMemDirCtx(Hashtable environment, + boolean ignoreCase, boolean useFac) { myEnv = environment; this.ignoreCase = ignoreCase; init(); @@ -84,7 +84,7 @@ private void init() { attrs = new BasicAttributes(ignoreCase); - bindings = new Hashtable(11, 0.75f); + bindings = new Hashtable<>(11, 0.75f); } public Object lookup(String name) throws NamingException { @@ -326,30 +326,30 @@ bindings.put(newname, oldBinding); } - public NamingEnumeration list(String name) throws NamingException { + public NamingEnumeration list(String name) throws NamingException { return list(myParser.parse(name)); } - public NamingEnumeration list(Name name) throws NamingException { + public NamingEnumeration list(Name name) throws NamingException { HierMemDirCtx ctx = (HierMemDirCtx) doLookup(name, false); return ctx.doList(); } - protected NamingEnumeration doList () throws NamingException { + protected NamingEnumeration doList () throws NamingException { return new FlatNames(bindings.keys()); } - public NamingEnumeration listBindings(String name) throws NamingException { + public NamingEnumeration listBindings(String name) throws NamingException { return listBindings(myParser.parse(name)); } - public NamingEnumeration listBindings(Name name) throws NamingException { + public NamingEnumeration listBindings(Name name) throws NamingException { HierMemDirCtx ctx = (HierMemDirCtx)doLookup(name, false); return ctx.doListBindings(alwaysUseFactory); } - protected NamingEnumeration doListBindings(boolean useFactory) + protected NamingEnumeration doListBindings(boolean useFactory) throws NamingException { return new FlatBindings(bindings, myEnv, useFactory); } @@ -447,28 +447,32 @@ return result; } + @SuppressWarnings("unchecked") // clone() public Object addToEnvironment(String propName, Object propVal) throws NamingException { - myEnv = (myEnv == null) ? - new Hashtable(11, 0.75f) : (Hashtable)myEnv.clone(); + myEnv = (myEnv == null) + ? new Hashtable(11, 0.75f) + : (Hashtable)myEnv.clone(); return myEnv.put(propName, propVal); } + @SuppressWarnings("unchecked") // clone() public Object removeFromEnvironment(String propName) throws NamingException { if (myEnv == null) return null; - myEnv = (Hashtable)myEnv.clone(); + myEnv = (Hashtable)myEnv.clone(); return myEnv.remove(propName); } - public Hashtable getEnvironment() throws NamingException { + @SuppressWarnings("unchecked") // clone() + public Hashtable getEnvironment() throws NamingException { if (myEnv == null) { - return new Hashtable(5, 0.75f); + return new Hashtable<>(5, 0.75f); } else { - return (Hashtable)myEnv.clone(); + return (Hashtable)myEnv.clone(); } } @@ -529,10 +533,10 @@ } // turn it into a modification Enumeration and pass it on - NamingEnumeration attrEnum = attrs.getAll(); + NamingEnumeration attrEnum = attrs.getAll(); ModificationItem[] mods = new ModificationItem[attrs.size()]; for (int i = 0; i < mods.length && attrEnum.hasMoreElements(); i++) { - mods[i] = new ModificationItem(mod_op, (Attribute)attrEnum.next()); + mods[i] = new ModificationItem(mod_op, attrEnum.next()); } modifyAttributes(name, mods); @@ -564,7 +568,7 @@ ModificationItem mod; Attribute existingAttr, modAttr; - NamingEnumeration modVals; + NamingEnumeration modVals; for (int i = 0; i < mods.length; i++) { mod = mods[i]; @@ -619,29 +623,29 @@ return orig; } - public NamingEnumeration search(String name, - Attributes matchingAttributes) + public NamingEnumeration search(String name, + Attributes matchingAttributes) throws NamingException { return search(name, matchingAttributes, null); } - public NamingEnumeration search(Name name, - Attributes matchingAttributes) + public NamingEnumeration search(Name name, + Attributes matchingAttributes) throws NamingException { return search(name, matchingAttributes, null); } - public NamingEnumeration search(String name, - Attributes matchingAttributes, - String[] attributesToReturn) + public NamingEnumeration search(String name, + Attributes matchingAttributes, + String[] attributesToReturn) throws NamingException { return search(myParser.parse(name), matchingAttributes, attributesToReturn); } - public NamingEnumeration search(Name name, - Attributes matchingAttributes, - String[] attributesToReturn) + public NamingEnumeration search(Name name, + Attributes matchingAttributes, + String[] attributesToReturn) throws NamingException { HierMemDirCtx target = (HierMemDirCtx) doLookup(name, false); @@ -656,9 +660,9 @@ false); // alwaysUseFactory ignored because objReturnFlag == false } - public NamingEnumeration search(Name name, - String filter, - SearchControls cons) + public NamingEnumeration search(Name name, + String filter, + SearchControls cons) throws NamingException { DirContext target = (DirContext) doLookup(name, false); @@ -671,27 +675,27 @@ cons, this, myEnv, alwaysUseFactory); } - public NamingEnumeration search(Name name, - String filterExpr, - Object[] filterArgs, - SearchControls cons) + public NamingEnumeration search(Name name, + String filterExpr, + Object[] filterArgs, + SearchControls cons) throws NamingException { String strfilter = SearchFilter.format(filterExpr, filterArgs); return search(name, strfilter, cons); } - public NamingEnumeration search(String name, - String filter, - SearchControls cons) + public NamingEnumeration search(String name, + String filter, + SearchControls cons) throws NamingException { return search(myParser.parse(name), filter, cons); } - public NamingEnumeration search(String name, - String filterExpr, - Object[] filterArgs, - SearchControls cons) + public NamingEnumeration search(String name, + String filterExpr, + Object[] filterArgs, + SearchControls cons) throws NamingException { return search(myParser.parse(name), filterExpr, filterArgs, cons); } @@ -761,11 +765,14 @@ myParser = parser; } - // Class for enumerating name/class pairs - private class FlatNames implements NamingEnumeration { - Enumeration names; + /* + * Common base class for FlatNames and FlatBindings. + * Inheritors can implement different NamingEnumeration interfaces. + */ + private class BaseFlatNames { + Enumeration names; - FlatNames (Enumeration names) { + BaseFlatNames (Enumeration names) { this.names = names; } @@ -781,7 +788,7 @@ return names.hasMoreElements(); } - public Object nextElement() { + public NameClassPair nextElement() { try { return next(); } catch (NamingException e) { @@ -789,8 +796,8 @@ } } - public Object next() throws NamingException { - Name name = (Name)names.nextElement(); + public NameClassPair next() throws NamingException { + Name name = names.nextElement(); String className = bindings.get(name).getClass().getName(); return new NameClassPair(name.toString(), className); } @@ -799,22 +806,33 @@ names = null; } } + + // Class for enumerating name/class pairs + private class FlatNames extends BaseFlatNames + implements NamingEnumeration { + FlatNames (Enumeration names) { + super(names); + } + } - // Class for enumerating bindings - private final class FlatBindings extends FlatNames { - private Hashtable bds; - private Hashtable env; + // Class for enumerating bindings + private final class FlatBindings extends BaseFlatNames + implements NamingEnumeration { + private Hashtable bds; + private Hashtable env; private boolean useFactory; - FlatBindings(Hashtable bindings, Hashtable env, boolean useFactory) { + FlatBindings(Hashtable bindings, + Hashtable env, + boolean useFactory) { super(bindings.keys()); this.env = env; this.bds = bindings; this.useFactory = useFactory; } - public Object next() throws NamingException { - Name name = (Name)names.nextElement(); + public Binding next() throws NamingException { + Name name = names.nextElement(); HierMemDirCtx obj = (HierMemDirCtx)bds.get(name); @@ -836,6 +854,14 @@ return new Binding(name.toString(), answer); } + + public Binding nextElement() { + try { + return next(); + } catch (NamingException e) { + throw new NoSuchElementException(e.toString()); + } + } } public class HierContextEnumerator extends ContextEnumerator { @@ -849,7 +875,7 @@ super(context, scope, contextName, returnSelf); } - protected NamingEnumeration getImmediateChildren(Context ctx) + protected NamingEnumeration getImmediateChildren(Context ctx) throws NamingException { return ((HierMemDirCtx)ctx).doListBindings(false); } @@ -872,14 +898,14 @@ // Creates an empty name HierarchicalName() { - super(new Enumeration() { - public boolean hasMoreElements() {return false;} - public Object nextElement() {throw new NoSuchElementException();} - }, - HierarchicalNameParser.mySyntax); + super(new Enumeration() { + public boolean hasMoreElements() {return false;} + public String nextElement() {throw new NoSuchElementException();} + }, + HierarchicalNameParser.mySyntax); } - HierarchicalName(Enumeration comps, Properties syntax) { + HierarchicalName(Enumeration comps, Properties syntax) { super(comps, syntax); } @@ -907,12 +933,12 @@ } public Name getPrefix(int posn) { - Enumeration comps = super.getPrefix(posn).getAll(); + Enumeration comps = super.getPrefix(posn).getAll(); return (new HierarchicalName(comps, mySyntax)); } public Name getSuffix(int posn) { - Enumeration comps = super.getSuffix(posn).getAll(); + Enumeration comps = super.getSuffix(posn).getAll(); return (new HierarchicalName(comps, mySyntax)); } --- old/src/share/classes/com/sun/jndi/toolkit/dir/LazySearchEnumerationImpl.java 2011-07-27 17:24:25.285243700 -0700 +++ new/src/share/classes/com/sun/jndi/toolkit/dir/LazySearchEnumerationImpl.java 2011-07-27 17:24:24.619177100 -0700 @@ -47,16 +47,17 @@ import java.util.NoSuchElementException; import java.util.Hashtable; -final public class LazySearchEnumerationImpl implements NamingEnumeration { - private NamingEnumeration candidates; +final public class LazySearchEnumerationImpl + implements NamingEnumeration { + private NamingEnumeration candidates; private SearchResult nextMatch = null; private SearchControls cons; private AttrFilter filter; private Context context; - private Hashtable env; + private Hashtable env; private boolean useFactory = true; - public LazySearchEnumerationImpl(NamingEnumeration candidates, + public LazySearchEnumerationImpl(NamingEnumeration candidates, AttrFilter filter, SearchControls cons) throws NamingException { this.candidates = candidates; this.filter = filter; @@ -68,9 +69,10 @@ } } - public LazySearchEnumerationImpl(NamingEnumeration candidates, + public LazySearchEnumerationImpl(NamingEnumeration candidates, AttrFilter filter, SearchControls cons, - Context ctx, Hashtable env, boolean useFactory) throws NamingException { + Context ctx, Hashtable env, boolean useFactory) + throws NamingException { this.candidates = candidates; this.filter = filter; @@ -86,9 +88,9 @@ } - public LazySearchEnumerationImpl(NamingEnumeration candidates, + public LazySearchEnumerationImpl(NamingEnumeration candidates, AttrFilter filter, SearchControls cons, - Context ctx, Hashtable env) throws NamingException { + Context ctx, Hashtable env) throws NamingException { this(candidates, filter, cons, ctx, env, true); } @@ -105,7 +107,7 @@ } } - public Object nextElement() { + public SearchResult nextElement() { try { return findNextMatch(true); } catch (NamingException e) { @@ -113,7 +115,7 @@ } } - public Object next() throws NamingException { + public SearchResult next() throws NamingException { // find and remove from list return (findNextMatch(true)); } @@ -138,7 +140,7 @@ Object obj; Attributes targetAttrs; while (candidates.hasMore()) { - next = (Binding)candidates.next(); + next = candidates.next(); obj = next.getObject(); if (obj instanceof DirContext) { targetAttrs = ((DirContext)(obj)).getAttributes(""); --- old/src/share/classes/com/sun/jndi/toolkit/dir/SearchFilter.java 2011-07-27 17:24:31.850900200 -0700 +++ new/src/share/classes/com/sun/jndi/toolkit/dir/SearchFilter.java 2011-07-27 17:24:31.199835100 -0700 @@ -203,11 +203,11 @@ * A class for dealing with compound filters ("and" & "or" filters). */ final class CompoundFilter implements StringFilter { - private Vector subFilters; + private Vector subFilters; private boolean polarity; CompoundFilter(boolean polarity) { - subFilters = new Vector(); + subFilters = new Vector<>(); this.polarity = polarity; } @@ -223,7 +223,7 @@ public boolean check(Attributes targetAttrs) throws NamingException { for(int i = 0; i candidates; try { Attribute attr = targetAttrs.get(attrID); @@ -441,13 +441,14 @@ String answer; answer = "(& "; Attribute attr; - for (NamingEnumeration e = attrs.getAll(); e.hasMore(); ) { - attr = (Attribute)e.next(); + for (NamingEnumeration e = attrs.getAll(); + e.hasMore(); ) { + attr = e.next(); if (attr.size() == 0 || (attr.size() == 1 && attr.get() == null)) { // only checking presence of attribute answer += "(" + attr.getID() + "=" + "*)"; } else { - for (NamingEnumeration ve = attr.getAll(); + for (NamingEnumeration ve = attr.getAll(); ve.hasMore(); ) { String val = getEncodedStringRep(ve.next()); --- old/src/share/classes/com/sun/jndi/toolkit/url/GenericURLContext.java 2011-07-27 17:24:38.584573500 -0700 +++ new/src/share/classes/com/sun/jndi/toolkit/url/GenericURLContext.java 2011-07-27 17:24:37.805495600 -0700 @@ -48,11 +48,12 @@ * @author Rosanna Lee */ abstract public class GenericURLContext implements Context { - protected Hashtable myEnv = null; + protected Hashtable myEnv = null; - public GenericURLContext(Hashtable env) { + @SuppressWarnings("unchecked") // Expect Hashtable + public GenericURLContext(Hashtable env) { // context that is not tied to any specific URL - myEnv = env; // copied on write + myEnv = (Hashtable)env; // copied on write } public void close() throws NamingException { @@ -75,7 +76,7 @@ * must be in sync wrt how URLs are parsed and returned. */ abstract protected ResolveResult getRootURLContext(String url, - Hashtable env) throws NamingException; + Hashtable env) throws NamingException; /** * Returns the suffix of the url. The result should be identical to @@ -487,27 +488,31 @@ return result; } + @SuppressWarnings("unchecked") // clone() public Object removeFromEnvironment(String propName) throws NamingException { if (myEnv == null) { return null; } - myEnv = (Hashtable)myEnv.clone(); + myEnv = (Hashtable)myEnv.clone(); return myEnv.remove(propName); } + @SuppressWarnings("unchecked") // clone() public Object addToEnvironment(String propName, Object propVal) throws NamingException { - myEnv = (myEnv == null) ? - new Hashtable(11, 0.75f) : (Hashtable)myEnv.clone(); + myEnv = (myEnv == null) + ? new Hashtable(11, 0.75f) + : (Hashtable)myEnv.clone(); return myEnv.put(propName, propVal); } - public Hashtable getEnvironment() throws NamingException { + @SuppressWarnings("unchecked") // clone() + public Hashtable getEnvironment() throws NamingException { if (myEnv == null) { - return new Hashtable(5, 0.75f); + return new Hashtable<>(5, 0.75f); } else { - return (Hashtable)myEnv.clone(); + return (Hashtable)myEnv.clone(); } } --- old/src/share/classes/com/sun/jndi/toolkit/url/GenericURLDirContext.java 2011-07-27 17:24:45.023217300 -0700 +++ new/src/share/classes/com/sun/jndi/toolkit/url/GenericURLDirContext.java 2011-07-27 17:24:44.301145100 -0700 @@ -50,7 +50,7 @@ abstract public class GenericURLDirContext extends GenericURLContext implements DirContext { - protected GenericURLDirContext(Hashtable env) { + protected GenericURLDirContext(Hashtable env) { super(env); } --- old/src/share/classes/com/sun/jndi/url/dns/dnsURLContext.java 2011-07-27 17:24:51.512866200 -0700 +++ new/src/share/classes/com/sun/jndi/url/dns/dnsURLContext.java 2011-07-27 17:24:50.806795600 -0700 @@ -45,7 +45,7 @@ public class dnsURLContext extends GenericURLDirContext { - public dnsURLContext(Hashtable env) { + public dnsURLContext(Hashtable env) { super(env); } @@ -54,7 +54,7 @@ * to the named DNS server, and returns the domain name as the * remaining name. */ - protected ResolveResult getRootURLContext(String url, Hashtable env) + protected ResolveResult getRootURLContext(String url, Hashtable env) throws NamingException { DnsUrl dnsUrl; --- old/src/share/classes/com/sun/jndi/url/dns/dnsURLContextFactory.java 2011-07-27 17:24:58.194534300 -0700 +++ new/src/share/classes/com/sun/jndi/url/dns/dnsURLContextFactory.java 2011-07-27 17:24:57.477462600 -0700 @@ -62,7 +62,7 @@ } } - private static Object getUsingURL(String url, Hashtable env) + private static Object getUsingURL(String url, Hashtable env) throws NamingException { dnsURLContext urlCtx = new dnsURLContext(env); @@ -78,7 +78,7 @@ * If all URLs fail, throw one of the exceptions arbitrarily. * Not pretty, but potentially more informative than returning null. */ - private static Object getUsingURLs(String[] urls, Hashtable env) + private static Object getUsingURLs(String[] urls, Hashtable env) throws NamingException { if (urls.length == 0) { --- old/src/share/classes/com/sun/jndi/url/iiop/iiopURLContext.java 2011-07-27 17:25:04.653180100 -0700 +++ new/src/share/classes/com/sun/jndi/url/iiop/iiopURLContext.java 2011-07-27 17:25:03.984113200 -0700 @@ -42,7 +42,7 @@ public class iiopURLContext extends com.sun.jndi.toolkit.url.GenericURLContext { - iiopURLContext(Hashtable env) { + iiopURLContext(Hashtable env) { super(env); } @@ -56,7 +56,7 @@ * context on for the ORB at 'localhost' on port 900, * and returns as the remaining name "rest/of/name". */ - protected ResolveResult getRootURLContext(String name, Hashtable env) + protected ResolveResult getRootURLContext(String name, Hashtable env) throws NamingException { return iiopURLContextFactory.getUsingURLIgnoreRest(name, env); } --- old/src/share/classes/com/sun/jndi/url/iiop/iiopURLContextFactory.java 2011-07-27 17:25:11.611875900 -0700 +++ new/src/share/classes/com/sun/jndi/url/iiop/iiopURLContextFactory.java 2011-07-27 17:25:10.790793800 -0700 @@ -68,12 +68,12 @@ * context on for the ORB at 'localhost' on port 900, * and returns as the remaining name "rest/of/name". */ - static ResolveResult getUsingURLIgnoreRest(String url, Hashtable env) + static ResolveResult getUsingURLIgnoreRest(String url, Hashtable env) throws NamingException { return CNCtx.createUsingURL(url, env); } - private static Object getUsingURL(String url, Hashtable env) + private static Object getUsingURL(String url, Hashtable env) throws NamingException { ResolveResult res = getUsingURLIgnoreRest(url, env); @@ -85,7 +85,7 @@ } } - private static Object getUsingURLs(String[] urls, Hashtable env) { + private static Object getUsingURLs(String[] urls, Hashtable env) { for (int i = 0; i < urls.length; i++) { String url = urls[i]; try { --- old/src/share/classes/com/sun/jndi/url/ldap/ldapURLContext.java 2011-07-27 17:25:18.704585100 -0700 +++ new/src/share/classes/com/sun/jndi/url/ldap/ldapURLContext.java 2011-07-27 17:25:17.993514000 -0700 @@ -42,7 +42,7 @@ final public class ldapURLContext extends com.sun.jndi.toolkit.url.GenericURLDirContext { - ldapURLContext(Hashtable env) { + ldapURLContext(Hashtable env) { super(env); } @@ -56,7 +56,7 @@ * context on the server 'localhost' on port 389, * and returns as the remaining name "o=widget, c=us". */ - protected ResolveResult getRootURLContext(String name, Hashtable env) + protected ResolveResult getRootURLContext(String name, Hashtable env) throws NamingException { return ldapURLContextFactory.getUsingURLIgnoreRootDN(name, env); } @@ -171,7 +171,8 @@ } } - public NamingEnumeration list(String name) throws NamingException { + public NamingEnumeration list(String name) + throws NamingException { if (LdapURL.hasQueryComponents(name)) { throw new InvalidNameException(name); } else { @@ -179,7 +180,8 @@ } } - public NamingEnumeration list(Name name) throws NamingException { + public NamingEnumeration list(Name name) + throws NamingException { if (LdapURL.hasQueryComponents(name.get(0))) { throw new InvalidNameException(name.toString()); } else { @@ -187,7 +189,8 @@ } } - public NamingEnumeration listBindings(String name) throws NamingException { + public NamingEnumeration listBindings(String name) + throws NamingException { if (LdapURL.hasQueryComponents(name)) { throw new InvalidNameException(name); } else { @@ -195,7 +198,8 @@ } } - public NamingEnumeration listBindings(Name name) throws NamingException { + public NamingEnumeration listBindings(Name name) + throws NamingException { if (LdapURL.hasQueryComponents(name.get(0))) { throw new InvalidNameException(name.toString()); } else { @@ -447,7 +451,7 @@ } // divert the search operation when the LDAP URL has query components - public NamingEnumeration search(String name, + public NamingEnumeration search(String name, Attributes matchingAttributes) throws NamingException { @@ -459,7 +463,7 @@ } // divert the search operation when name has a single component - public NamingEnumeration search(Name name, + public NamingEnumeration search(Name name, Attributes matchingAttributes) throws NamingException { if (name.size() == 1) { @@ -472,7 +476,7 @@ } // divert the search operation when the LDAP URL has query components - public NamingEnumeration search(String name, + public NamingEnumeration search(String name, Attributes matchingAttributes, String[] attributesToReturn) throws NamingException { @@ -485,7 +489,7 @@ } // divert the search operation when name has a single component - public NamingEnumeration search(Name name, + public NamingEnumeration search(Name name, Attributes matchingAttributes, String[] attributesToReturn) throws NamingException { @@ -500,7 +504,7 @@ } // divert the search operation when the LDAP URL has query components - public NamingEnumeration search(String name, + public NamingEnumeration search(String name, String filter, SearchControls cons) throws NamingException { @@ -513,7 +517,7 @@ } // divert the search operation when name has a single component - public NamingEnumeration search(Name name, + public NamingEnumeration search(Name name, String filter, SearchControls cons) throws NamingException { @@ -528,7 +532,7 @@ } // divert the search operation when the LDAP URL has query components - public NamingEnumeration search(String name, + public NamingEnumeration search(String name, String filterExpr, Object[] filterArgs, SearchControls cons) @@ -542,7 +546,7 @@ } // divert the search operation when name has a single component - public NamingEnumeration search(Name name, + public NamingEnumeration search(Name name, String filterExpr, Object[] filterArgs, SearchControls cons) @@ -559,7 +563,7 @@ // Search using the LDAP URL in name. // LDAP URL query components override the search argments. - private NamingEnumeration searchUsingURL(String name) + private NamingEnumeration searchUsingURL(String name) throws NamingException { LdapURL url = new LdapURL(name); --- old/src/share/classes/com/sun/jndi/url/ldap/ldapURLContextFactory.java 2011-07-27 17:25:27.102424800 -0700 +++ new/src/share/classes/com/sun/jndi/url/ldap/ldapURLContextFactory.java 2011-07-27 17:25:26.062320800 -0700 @@ -53,7 +53,7 @@ } } - static ResolveResult getUsingURLIgnoreRootDN(String url, Hashtable env) + static ResolveResult getUsingURLIgnoreRootDN(String url, Hashtable env) throws NamingException { LdapURL ldapUrl = new LdapURL(url); DirContext ctx = new LdapCtx("", ldapUrl.getHost(), ldapUrl.getPort(), --- old/src/share/classes/com/sun/jndi/url/rmi/rmiURLContext.java 2011-07-27 17:25:35.186233100 -0700 +++ new/src/share/classes/com/sun/jndi/url/rmi/rmiURLContext.java 2011-07-27 17:25:34.321146600 -0700 @@ -26,7 +26,6 @@ package com.sun.jndi.url.rmi; import java.util.Hashtable; -import java.rmi.registry.LocateRegistry; import javax.naming.*; import javax.naming.spi.ResolveResult; @@ -48,7 +47,7 @@ */ public class rmiURLContext extends GenericURLContext { - public rmiURLContext(Hashtable env) { + public rmiURLContext(Hashtable env) { super(env); } @@ -57,7 +56,7 @@ * RMI registry, and returns the atomic object name as the * remaining name. */ - protected ResolveResult getRootURLContext(String url, Hashtable env) + protected ResolveResult getRootURLContext(String url, Hashtable env) throws NamingException { if (!url.startsWith("rmi:")) { --- old/src/share/classes/com/sun/jndi/url/rmi/rmiURLContextFactory.java 2011-07-27 17:25:42.266941100 -0700 +++ new/src/share/classes/com/sun/jndi/url/rmi/rmiURLContextFactory.java 2011-07-27 17:25:41.344848900 -0700 @@ -63,7 +63,7 @@ } } - private static Object getUsingURL(String url, Hashtable env) + private static Object getUsingURL(String url, Hashtable env) throws NamingException { rmiURLContext urlCtx = new rmiURLContext(env); @@ -79,7 +79,7 @@ * If all URLs fail, throw one of the exceptions arbitrarily. * Not pretty, but potentially more informative than returning null. */ - private static Object getUsingURLs(String[] urls, Hashtable env) + private static Object getUsingURLs(String[] urls, Hashtable env) throws NamingException { if (urls.length == 0) { --- old/src/share/classes/com/sun/naming/internal/FactoryEnumeration.java 2011-07-27 17:25:50.825796900 -0700 +++ new/src/share/classes/com/sun/naming/internal/FactoryEnumeration.java 2011-07-27 17:25:49.554669800 -0700 @@ -37,7 +37,8 @@ // no need to implement Enumeration since this is only for internal use public final class FactoryEnumeration { - private List factories; + // List> + private List> factories; private int posn = 0; private ClassLoader loader; @@ -59,7 +60,8 @@ * @param factories A non-null list * @param loader The class loader of the list's contents */ - FactoryEnumeration(List factories, ClassLoader loader) { + FactoryEnumeration(List> factories, + ClassLoader loader) { this.factories = factories; this.loader = loader; } @@ -67,7 +69,7 @@ public Object next() throws NamingException { synchronized (factories) { - NamedWeakReference ref = (NamedWeakReference) factories.get(posn++); + NamedWeakReference ref = factories.get(posn++); Object answer = ref.get(); if ((answer != null) && !(answer instanceof Class)) { return answer; @@ -81,7 +83,7 @@ } // Instantiate Class to get factory answer = ((Class) answer).newInstance(); - ref = new NamedWeakReference(answer, className); + ref = new NamedWeakReference<>(answer, className); factories.set(posn-1, ref); // replace Class object or null return answer; } catch (ClassNotFoundException e) { --- old/src/share/classes/com/sun/naming/internal/NamedWeakReference.java 2011-07-27 17:26:00.892803500 -0700 +++ new/src/share/classes/com/sun/naming/internal/NamedWeakReference.java 2011-07-27 17:25:59.944708700 -0700 @@ -33,11 +33,11 @@ */ -class NamedWeakReference extends java.lang.ref.WeakReference { +class NamedWeakReference extends java.lang.ref.WeakReference { private final String name; - NamedWeakReference(Object referent, String name) { + NamedWeakReference(T referent, String name) { super(referent); this.name = name; } --- old/src/share/classes/com/sun/naming/internal/ResourceManager.java 2011-07-27 17:26:09.154629600 -0700 +++ new/src/share/classes/com/sun/naming/internal/ResourceManager.java 2011-07-27 17:26:08.165530700 -0700 @@ -27,11 +27,9 @@ import java.io.InputStream; import java.io.IOException; -import java.net.URL; import java.lang.ref.WeakReference; import java.lang.reflect.Method; import java.lang.reflect.InvocationTargetException; -import java.util.Enumeration; import java.util.HashMap; import java.util.Hashtable; import java.util.Map; @@ -89,7 +87,9 @@ * One from application resource files is keyed on the thread's * context class loader. */ - private static final WeakHashMap propertiesCache = new WeakHashMap(11); + // WeakHashMap + private static final WeakHashMap> + propertiesCache = new WeakHashMap<>(11); /* * A cache of factory objects (ObjectFactory, StateFactory, ControlFactory). @@ -99,7 +99,9 @@ * weakly referenced so as not to prevent GC of the class loader. * Used in getFactories(). */ - private static final WeakHashMap factoryCache = new WeakHashMap(11); + private static final + WeakHashMap>>> + factoryCache = new WeakHashMap<>(11); /* * A cache of URL factory objects (ObjectFactory). @@ -110,8 +112,11 @@ * NO_FACTORY if a previous search revealed no factory. Used in * getFactory(). */ - private static final WeakHashMap urlFactoryCache = new WeakHashMap(11); - private static final WeakReference NO_FACTORY = new WeakReference(null); + private static final + WeakHashMap>> + urlFactoryCache = new WeakHashMap<>(11); + private static final WeakReference NO_FACTORY = + new WeakReference<>(null); /** * A class to allow JNDI properties be specified as applet parameters @@ -152,10 +157,9 @@ throw new ClassCastException(applet.getClass().getName()); try { return getMethod.invoke(applet, name); - } catch (InvocationTargetException e) { + } catch (InvocationTargetException | + IllegalAccessException e) { throw new AssertionError(e); - } catch (IllegalAccessException iae) { - throw new AssertionError(iae); } } } @@ -183,12 +187,14 @@ * @throws NamingException if an error occurs while reading a * resource file */ - public static Hashtable getInitialEnvironment(Hashtable env) + @SuppressWarnings("unchecked") + public static Hashtable getInitialEnvironment( + Hashtable env) throws NamingException { String[] props = VersionHelper.PROPS; // system/applet properties if (env == null) { - env = new Hashtable(11); + env = new Hashtable<>(11); } Object applet = env.get(Context.APPLET); @@ -213,14 +219,14 @@ : helper.getJndiProperty(i); } if (val != null) { - env.put(props[i], val); + ((Hashtable)env).put(props[i], val); } } } // Merge the above with the values read from all application // resource files. Colon-separated lists are concatenated. - mergeTables(env, getApplicationResources()); + mergeTables((Hashtable)env, getApplicationResources()); return env; } @@ -244,7 +250,7 @@ * @throws NamingException if an error occurs while reading the provider * resource file. */ - public static String getProperty(String propName, Hashtable env, + public static String getProperty(String propName, Hashtable env, Context ctx, boolean concat) throws NamingException { @@ -305,8 +311,8 @@ * @see javax.naming.spi.DirectoryManager#getStateToBind * @see javax.naming.ldap.ControlFactory#getControlInstance */ - public static FactoryEnumeration getFactories(String propName, Hashtable env, - Context ctx) throws NamingException { + public static FactoryEnumeration getFactories(String propName, + Hashtable env, Context ctx) throws NamingException { String facProp = getProperty(propName, env, ctx, true); if (facProp == null) @@ -315,17 +321,18 @@ // Cache is based on context class loader and property val ClassLoader loader = helper.getContextClassLoader(); - Map perLoaderCache = null; + Map>> perLoaderCache = null; synchronized (factoryCache) { - perLoaderCache = (Map) factoryCache.get(loader); + perLoaderCache = factoryCache.get(loader); if (perLoaderCache == null) { - perLoaderCache = new HashMap(11); + perLoaderCache = new HashMap<>(11); factoryCache.put(loader, perLoaderCache); } } synchronized (perLoaderCache) { - List factories = (List) perLoaderCache.get(facProp); + List> factories = + perLoaderCache.get(facProp); if (factories != null) { // Cached list return factories.size() == 0 ? null @@ -334,13 +341,13 @@ // Populate list with classes named in facProp; skipping // those that we cannot load StringTokenizer parser = new StringTokenizer(facProp, ":"); - factories = new ArrayList(5); + factories = new ArrayList<>(5); while (parser.hasMoreTokens()) { try { // System.out.println("loading"); String className = parser.nextToken(); - Class c = helper.loadClass(className, loader); - factories.add(new NamedWeakReference(c, className)); + Class c = helper.loadClass(className, loader); + factories.add(new NamedWeakReference(c, className)); } catch (Exception e) { // ignore ClassNotFoundException, IllegalArgumentException } @@ -388,8 +395,9 @@ * @see javax.naming.spi.NamingManager#getURLContext * @see javax.naming.spi.NamingManager#getURLObject */ - public static Object getFactory(String propName, Hashtable env, Context ctx, - String classSuffix, String defaultPkgPrefix) throws NamingException { + public static Object getFactory(String propName, Hashtable env, + Context ctx, String classSuffix, String defaultPkgPrefix) + throws NamingException { // Merge property with provider property and supplied default String facProp = getProperty(propName, env, ctx, true); @@ -403,11 +411,11 @@ ClassLoader loader = helper.getContextClassLoader(); String key = classSuffix + " " + facProp; - Map perLoaderCache = null; + Map> perLoaderCache = null; synchronized (urlFactoryCache) { - perLoaderCache = (Map) urlFactoryCache.get(loader); + perLoaderCache = urlFactoryCache.get(loader); if (perLoaderCache == null) { - perLoaderCache = new HashMap(11); + perLoaderCache = new HashMap<>(11); urlFactoryCache.put(loader, perLoaderCache); } } @@ -415,7 +423,7 @@ synchronized (perLoaderCache) { Object factory = null; - WeakReference factoryRef = (WeakReference) perLoaderCache.get(key); + WeakReference factoryRef = perLoaderCache.get(key); if (factoryRef == NO_FACTORY) { return null; } else if (factoryRef != null) { @@ -451,7 +459,7 @@ // Cache it. perLoaderCache.put(key, (factory != null) - ? new WeakReference(factory) + ? new WeakReference<>(factory) : NO_FACTORY); return factory; } @@ -468,16 +476,18 @@ * * @throws NamingException if an error occurs while reading the file. */ - private static Hashtable getProviderResource(Object obj) + private static Hashtable + getProviderResource(Object obj) throws NamingException { if (obj == null) { - return (new Hashtable(1)); + return (new Hashtable<>(1)); } synchronized (propertiesCache) { - Class c = obj.getClass(); + Class c = obj.getClass(); - Hashtable props = (Hashtable)propertiesCache.get(c); + Hashtable props = + propertiesCache.get(c); if (props != null) { return props; } @@ -518,22 +528,23 @@ * @throws NamingException if an error occurs while reading a resource * file. */ - private static Hashtable getApplicationResources() throws NamingException { + private static Hashtable getApplicationResources() + throws NamingException { ClassLoader cl = helper.getContextClassLoader(); synchronized (propertiesCache) { - Hashtable result = (Hashtable)propertiesCache.get(cl); + Hashtable result = propertiesCache.get(cl); if (result != null) { return result; } try { - NamingEnumeration resources = + NamingEnumeration resources = helper.getResources(cl, APP_RESOURCE_FILE_NAME); while (resources.hasMore()) { Properties props = new Properties(); - props.load((InputStream)resources.next()); + props.load(resources.next()); if (result == null) { result = props; @@ -563,7 +574,7 @@ throw ne; } if (result == null) { - result = new Hashtable(11); + result = new Hashtable<>(11); } propertiesCache.put(cl, result); return result; @@ -577,11 +588,10 @@ * standard JNDI properties that specify colon-separated lists, * the values are concatenated and stored in props1. */ - private static void mergeTables(Hashtable props1, Hashtable props2) { - Enumeration keys = props2.keys(); - - while (keys.hasMoreElements()) { - String prop = (String)keys.nextElement(); + private static void mergeTables(Hashtable props1, + Hashtable props2) { + for (Object key : props2.keySet()) { + String prop = (String)key; Object val1 = props1.get(prop); if (val1 == null) { props1.put(prop, props2.get(prop)); --- old/src/share/classes/com/sun/naming/internal/VersionHelper.java 2011-07-27 17:26:16.503364400 -0700 +++ new/src/share/classes/com/sun/naming/internal/VersionHelper.java 2011-07-27 17:26:15.693283400 -0700 @@ -29,7 +29,6 @@ import java.io.IOException; import java.net.MalformedURLException; import java.net.URL; -import java.util.Enumeration; import java.util.StringTokenizer; import java.util.Vector; @@ -78,13 +77,13 @@ return helper; } - public abstract Class loadClass(String className) + public abstract Class loadClass(String className) throws ClassNotFoundException; - abstract Class loadClass(String className, ClassLoader cl) + abstract Class loadClass(String className, ClassLoader cl) throws ClassNotFoundException; - public abstract Class loadClass(String className, String codebase) + public abstract Class loadClass(String className, String codebase) throws ClassNotFoundException, MalformedURLException; /* @@ -106,7 +105,7 @@ * Returns the resource of a given name associated with a particular * class (never null), or null if none can be found. */ - abstract InputStream getResourceAsStream(Class c, String name); + abstract InputStream getResourceAsStream(Class c, String name); /* * Returns an input stream for a file in /lib, @@ -122,7 +121,8 @@ * loader. Null represents the bootstrap class loader in some * Java implementations. */ - abstract NamingEnumeration getResources(ClassLoader cl, String name) + abstract NamingEnumeration getResources( + ClassLoader cl, String name) throws IOException; /* @@ -137,13 +137,13 @@ throws MalformedURLException { // Parse codebase into separate URLs StringTokenizer parser = new StringTokenizer(codebase); - Vector vec = new Vector(10); + Vector vec = new Vector<>(10); while (parser.hasMoreTokens()) { vec.addElement(parser.nextToken()); } String[] url = new String[vec.size()]; for (int i = 0; i < url.length; i++) { - url[i] = (String)vec.elementAt(i); + url[i] = vec.elementAt(i); } URL[] urlArray = new URL[url.length]; --- old/src/share/classes/com/sun/naming/internal/VersionHelper12.java 2011-07-27 17:26:22.611975200 -0700 +++ new/src/share/classes/com/sun/naming/internal/VersionHelper12.java 2011-07-27 17:26:21.953909400 -0700 @@ -35,7 +35,6 @@ import java.security.PrivilegedActionException; import java.security.PrivilegedExceptionAction; import java.util.Enumeration; -import java.util.Hashtable; import java.util.NoSuchElementException; import java.util.Properties; @@ -58,7 +57,7 @@ VersionHelper12() {} // Disallow external from creating one of these. - public Class loadClass(String className) throws ClassNotFoundException { + public Class loadClass(String className) throws ClassNotFoundException { ClassLoader cl = getContextClassLoader(); return Class.forName(className, true, cl); } @@ -66,7 +65,7 @@ /** * Package private. */ - Class loadClass(String className, ClassLoader cl) + Class loadClass(String className, ClassLoader cl) throws ClassNotFoundException { return Class.forName(className, true, cl); } @@ -75,7 +74,7 @@ * @param className A non-null fully qualified class name. * @param codebase A non-null, space-separated list of URL strings. */ - public Class loadClass(String className, String codebase) + public Class loadClass(String className, String codebase) throws ClassNotFoundException, MalformedURLException { ClassLoader cl; @@ -86,9 +85,9 @@ } String getJndiProperty(final int i) { - return (String) AccessController.doPrivileged( - new PrivilegedAction() { - public Object run() { + return AccessController.doPrivileged( + new PrivilegedAction() { + public String run() { try { return System.getProperty(PROPS[i]); } catch (SecurityException e) { @@ -103,9 +102,9 @@ if (getSystemPropsFailed) { return null; // after one failure, don't bother trying again } - Properties sysProps = (Properties) AccessController.doPrivileged( - new PrivilegedAction() { - public Object run() { + Properties sysProps = AccessController.doPrivileged( + new PrivilegedAction() { + public Properties run() { try { return System.getProperties(); } catch (SecurityException e) { @@ -125,10 +124,10 @@ return jProps; } - InputStream getResourceAsStream(final Class c, final String name) { - return (InputStream) AccessController.doPrivileged( - new PrivilegedAction() { - public Object run() { + InputStream getResourceAsStream(final Class c, final String name) { + return AccessController.doPrivileged( + new PrivilegedAction() { + public InputStream run() { return c.getResourceAsStream(name); } } @@ -136,9 +135,9 @@ } InputStream getJavaHomeLibStream(final String filename) { - return (InputStream) AccessController.doPrivileged( - new PrivilegedAction() { - public Object run() { + return AccessController.doPrivileged( + new PrivilegedAction() { + public InputStream run() { try { String javahome = System.getProperty("java.home"); if (javahome == null) { @@ -155,14 +154,13 @@ ); } - NamingEnumeration getResources(final ClassLoader cl, final String name) - throws IOException - { - Enumeration urls; + NamingEnumeration getResources(final ClassLoader cl, + final String name) throws IOException { + Enumeration urls; try { - urls = (Enumeration) AccessController.doPrivileged( - new PrivilegedExceptionAction() { - public Object run() throws IOException { + urls = AccessController.doPrivileged( + new PrivilegedExceptionAction>() { + public Enumeration run() throws IOException { return (cl == null) ? ClassLoader.getSystemResources(name) : cl.getResources(name); @@ -176,9 +174,9 @@ } ClassLoader getContextClassLoader() { - return (ClassLoader) AccessController.doPrivileged( - new PrivilegedAction() { - public Object run() { + return AccessController.doPrivileged( + new PrivilegedAction() { + public ClassLoader run() { return Thread.currentThread().getContextClassLoader(); } } @@ -193,13 +191,13 @@ * This is used to enumerate the resources under a foreign codebase. * This class is not MT-safe. */ - class InputStreamEnumeration implements NamingEnumeration { + class InputStreamEnumeration implements NamingEnumeration { - private final Enumeration urls; + private final Enumeration urls; - private Object nextElement = null; + private InputStream nextElement = null; - InputStreamEnumeration(Enumeration urls) { + InputStreamEnumeration(Enumeration urls) { this.urls = urls; } @@ -207,13 +205,13 @@ * Returns the next InputStream, or null if there are no more. * An InputStream that cannot be opened is skipped. */ - private Object getNextElement() { + private InputStream getNextElement() { return AccessController.doPrivileged( - new PrivilegedAction() { - public Object run() { + new PrivilegedAction() { + public InputStream run() { while (urls.hasMoreElements()) { try { - return ((URL)urls.nextElement()).openStream(); + return urls.nextElement().openStream(); } catch (IOException e) { // skip this URL } @@ -236,9 +234,9 @@ return hasMore(); } - public Object next() { + public InputStream next() { if (hasMore()) { - Object res = nextElement; + InputStream res = nextElement; nextElement = null; return res; } else { @@ -246,7 +244,7 @@ } } - public Object nextElement() { + public InputStream nextElement() { return next(); } --- old/src/share/classes/javax/naming/CompositeName.java 2011-07-27 17:26:29.257639700 -0700 +++ new/src/share/classes/javax/naming/CompositeName.java 2011-07-27 17:26:28.578571800 -0700 @@ -394,7 +394,7 @@ * If posn is outside the specified range. */ public Name getPrefix(int posn) { - Enumeration comps = impl.getPrefix(posn); + Enumeration comps = impl.getPrefix(posn); return (new CompositeName(comps)); } @@ -412,7 +412,7 @@ * If posn is outside the specified range. */ public Name getSuffix(int posn) { - Enumeration comps = impl.getSuffix(posn); + Enumeration comps = impl.getSuffix(posn); return (new CompositeName(comps)); } @@ -563,7 +563,7 @@ private void writeObject(java.io.ObjectOutputStream s) throws java.io.IOException { s.writeInt(size()); - Enumeration comps = getAll(); + Enumeration comps = getAll(); while (comps.hasMoreElements()) { s.writeObject(comps.nextElement()); } --- old/src/share/classes/javax/naming/CompoundName.java 2011-07-27 17:26:36.073321200 -0700 +++ new/src/share/classes/javax/naming/CompoundName.java 2011-07-27 17:26:35.418255700 -0700 @@ -376,7 +376,7 @@ * If posn is outside the specified range. */ public Name getPrefix(int posn) { - Enumeration comps = impl.getPrefix(posn); + Enumeration comps = impl.getPrefix(posn); return (new CompoundName(comps, mySyntax)); } @@ -396,7 +396,7 @@ * If posn is outside the specified range. */ public Name getSuffix(int posn) { - Enumeration comps = impl.getSuffix(posn); + Enumeration comps = impl.getSuffix(posn); return (new CompoundName(comps, mySyntax)); } @@ -557,7 +557,7 @@ throws java.io.IOException { s.writeObject(mySyntax); s.writeInt(size()); - Enumeration comps = getAll(); + Enumeration comps = getAll(); while (comps.hasMoreElements()) { s.writeObject(comps.nextElement()); } --- old/src/share/classes/javax/naming/InitialContext.java 2011-07-27 17:26:43.337047500 -0700 +++ new/src/share/classes/javax/naming/InitialContext.java 2011-07-27 17:26:42.532967100 -0700 @@ -232,10 +232,12 @@ * @see #InitialContext(boolean) * @since 1.3 */ + @SuppressWarnings("unchecked") protected void init(Hashtable environment) throws NamingException { - myProps = ResourceManager.getInitialEnvironment(environment); + myProps = (Hashtable) + ResourceManager.getInitialEnvironment(environment); if (myProps.get(Context.INITIAL_CONTEXT_FACTORY) != null) { // user has specified initial context factory; try to get it @@ -265,6 +267,7 @@ * @see #lookup(Name) * @since 1.6 */ + @SuppressWarnings("unchecked") public static T doLookup(Name name) throws NamingException { return (T) (new InitialContext()).lookup(name); @@ -279,6 +282,7 @@ * @throws NamingException if a naming exception is encountered * @since 1.6 */ + @SuppressWarnings("unchecked") public static T doLookup(String name) throws NamingException { return (T) (new InitialContext()).lookup(name); --- old/src/share/classes/javax/naming/NameImpl.java 2011-07-27 17:26:50.570770800 -0700 +++ new/src/share/classes/javax/naming/NameImpl.java 2011-07-27 17:26:49.771690900 -0700 @@ -45,7 +45,7 @@ private static final byte RIGHT_TO_LEFT = 2; private static final byte FLAT = 0; - private Vector components; + private Vector components; private byte syntaxDirection = LEFT_TO_RIGHT; private String syntaxSeparator = "/"; @@ -97,7 +97,7 @@ return (i); } - private final int extractComp(String name, int i, int len, Vector comps) + private final int extractComp(String name, int i, int len, Vector comps) throws InvalidNameException { String beginQuote; String endQuote; @@ -270,7 +270,7 @@ if (syntax != null) { recordNamingConvention(syntax); } - components = new Vector(); + components = new Vector<>(); } NameImpl(Properties syntax, String n) throws InvalidNameException { @@ -284,8 +284,8 @@ i = extractComp(n, i, len, components); String comp = rToL - ? (String)components.firstElement() - : (String)components.lastElement(); + ? components.firstElement() + : components.lastElement(); if (comp.length() >= 1) { compsAllEmpty = false; } @@ -304,7 +304,7 @@ } } - NameImpl(Properties syntax, Enumeration comps) { + NameImpl(Properties syntax, Enumeration comps) { this(syntax); // %% comps could shrink in the middle. @@ -455,9 +455,9 @@ for (int i = 0; i < size; i++) { if (syntaxDirection == RIGHT_TO_LEFT) { comp = - stringifyComp((String) components.elementAt(size - 1 - i)); + stringifyComp(components.elementAt(size - 1 - i)); } else { - comp = stringifyComp((String) components.elementAt(i)); + comp = stringifyComp(components.elementAt(i)); } if ((i != 0) && (syntaxSeparator != null)) answer.append(syntaxSeparator); @@ -474,12 +474,12 @@ if ((obj != null) && (obj instanceof NameImpl)) { NameImpl target = (NameImpl)obj; if (target.size() == this.size()) { - Enumeration mycomps = getAll(); - Enumeration comps = target.getAll(); + Enumeration mycomps = getAll(); + Enumeration comps = target.getAll(); while (mycomps.hasMoreElements()) { // %% comps could shrink in the middle. - String my = (String)mycomps.nextElement(); - String his = (String)comps.nextElement(); + String my = mycomps.nextElement(); + String his = comps.nextElement(); if (syntaxTrimBlanks) { my = my.trim(); his = his.trim(); @@ -543,22 +543,22 @@ return (components.size()); } - public Enumeration getAll() { + public Enumeration getAll() { return components.elements(); } public String get(int posn) { - return ((String) components.elementAt(posn)); + return components.elementAt(posn); } - public Enumeration getPrefix(int posn) { + public Enumeration getPrefix(int posn) { if (posn < 0 || posn > size()) { throw new ArrayIndexOutOfBoundsException(posn); } return new NameImplEnumerator(components, 0, posn); } - public Enumeration getSuffix(int posn) { + public Enumeration getSuffix(int posn) { int cnt = size(); if (posn < 0 || posn > cnt) { throw new ArrayIndexOutOfBoundsException(posn); @@ -570,15 +570,15 @@ return (components.isEmpty()); } - public boolean startsWith(int posn, Enumeration prefix) { + public boolean startsWith(int posn, Enumeration prefix) { if (posn < 0 || posn > size()) { return false; } try { - Enumeration mycomps = getPrefix(posn); + Enumeration mycomps = getPrefix(posn); while (mycomps.hasMoreElements()) { - String my = (String)mycomps.nextElement(); - String his = (String)prefix.nextElement(); + String my = mycomps.nextElement(); + String his = prefix.nextElement(); if (syntaxTrimBlanks) { my = my.trim(); his = his.trim(); @@ -597,7 +597,7 @@ return true; } - public boolean endsWith(int posn, Enumeration suffix) { + public boolean endsWith(int posn, Enumeration suffix) { // posn is number of elements in suffix // startIndex is the starting position in this name // at which to start the comparison. It is calculated by @@ -607,10 +607,10 @@ return false; } try { - Enumeration mycomps = getSuffix(startIndex); + Enumeration mycomps = getSuffix(startIndex); while (mycomps.hasMoreElements()) { - String my = (String)mycomps.nextElement(); - String his = (String)suffix.nextElement(); + String my = mycomps.nextElement(); + String his = suffix.nextElement(); if (syntaxTrimBlanks) { my = my.trim(); his = his.trim(); @@ -629,11 +629,11 @@ return true; } - public boolean addAll(Enumeration comps) throws InvalidNameException { + public boolean addAll(Enumeration comps) throws InvalidNameException { boolean added = false; while (comps.hasMoreElements()) { try { - Object comp = comps.nextElement(); + String comp = comps.nextElement(); if (size() > 0 && syntaxDirection == FLAT) { throw new InvalidNameException( "A flat name can only have a single component"); @@ -647,12 +647,12 @@ return added; } - public boolean addAll(int posn, Enumeration comps) + public boolean addAll(int posn, Enumeration comps) throws InvalidNameException { boolean added = false; for (int i = posn; comps.hasMoreElements(); i++) { try { - Object comp = comps.nextElement(); + String comp = comps.nextElement(); if (size() > 0 && syntaxDirection == FLAT) { throw new InvalidNameException( "A flat name can only have a single component"); @@ -690,8 +690,8 @@ public int hashCode() { int hash = 0; - for (Enumeration e = getAll(); e.hasMoreElements();) { - String comp = (String)e.nextElement(); + for (Enumeration e = getAll(); e.hasMoreElements();) { + String comp = e.nextElement(); if (syntaxTrimBlanks) { comp = comp.trim(); } @@ -706,12 +706,12 @@ } final -class NameImplEnumerator implements Enumeration { - Vector vector; +class NameImplEnumerator implements Enumeration { + Vector vector; int count; int limit; - NameImplEnumerator(Vector v, int start, int lim) { + NameImplEnumerator(Vector v, int start, int lim) { vector = v; count = start; limit = lim; @@ -721,7 +721,7 @@ return count < limit; } - public Object nextElement() { + public String nextElement() { if (count < limit) { return vector.elementAt(count++); } --- old/src/share/classes/javax/naming/Reference.java 2011-07-27 17:26:58.222535900 -0700 +++ new/src/share/classes/javax/naming/Reference.java 2011-07-27 17:26:57.461459800 -0700 @@ -120,7 +120,7 @@ */ public Reference(String className) { this.className = className; - addrs = new Vector(); + addrs = new Vector<>(); } /** @@ -134,7 +134,7 @@ */ public Reference(String className, RefAddr addr) { this.className = className; - addrs = new Vector(); + addrs = new Vector<>(); addrs.addElement(addr); } @@ -225,7 +225,7 @@ int len = addrs.size(); RefAddr addr; for (int i = 0; i < len; i++) { - addr = (RefAddr) addrs.elementAt(i); + addr = addrs.elementAt(i); if (addr.getType().compareTo(addrType) == 0) return addr; } @@ -241,7 +241,7 @@ * range. */ public RefAddr get(int posn) { - return ((RefAddr) addrs.elementAt(posn)); + return addrs.elementAt(posn); } /** @@ -331,8 +331,8 @@ // ignore factory information if (target.className.equals(this.className) && target.size() == this.size()) { - Enumeration mycomps = getAll(); - Enumeration comps = target.getAll(); + Enumeration mycomps = getAll(); + Enumeration comps = target.getAll(); while (mycomps.hasMoreElements()) if (!(mycomps.nextElement().equals(comps.nextElement()))) return false; @@ -350,7 +350,7 @@ */ public int hashCode() { int hash = className.hashCode(); - for (Enumeration e = getAll(); e.hasMoreElements();) + for (Enumeration e = getAll(); e.hasMoreElements();) hash += e.nextElement().hashCode(); return hash; } @@ -382,7 +382,7 @@ public Object clone() { Reference r = new Reference(className, classFactory, classFactoryLocation); Enumeration a = getAll(); - r.addrs = new Vector(); + r.addrs = new Vector<>(); while (a.hasMoreElements()) r.addrs.addElement(a.nextElement()); --- old/src/share/classes/javax/naming/directory/BasicAttribute.java 2011-07-27 17:27:05.332246800 -0700 +++ new/src/share/classes/javax/naming/directory/BasicAttribute.java 2011-07-27 17:27:04.587172300 -0700 @@ -91,6 +91,7 @@ */ protected boolean ordered = false; + @SuppressWarnings("unchecked") public Object clone() { BasicAttribute attr; try { @@ -98,7 +99,7 @@ } catch (CloneNotSupportedException e) { attr = new BasicAttribute(attrID, ordered); } - attr.values = (Vector)values.clone(); + attr.values = (Vector)values.clone(); return attr; } @@ -149,7 +150,7 @@ } } else { // order is not relevant; check for existence - Enumeration theirs = target.getAll(); + Enumeration theirs = target.getAll(); while (theirs.hasMoreElements()) { if (find(theirs.nextElement()) < 0) return false; @@ -215,7 +216,7 @@ answer.append("No values"); } else { boolean start = true; - for (Enumeration e = values.elements(); e.hasMoreElements(); ) { + for (Enumeration e = values.elements(); e.hasMoreElements(); ) { if (!start) answer.append(", "); answer.append(e.nextElement()); @@ -254,7 +255,7 @@ */ public BasicAttribute(String id, boolean ordered) { attrID = id; - values = new Vector(); + values = new Vector<>(); this.ordered = ordered; } @@ -327,7 +328,7 @@ // For finding first element that has a null in JDK1.1 Vector. // In the Java 2 platform, can just replace this with Vector.indexOf(target); private int find(Object target) { - Class cl; + Class cl; if (target == null) { int ct = values.size(); for (int i = 0 ; i < ct ; i++) { @@ -514,7 +515,7 @@ throws java.io.IOException, ClassNotFoundException { s.defaultReadObject(); // read in the attrID int n = s.readInt(); // number of values - values = new Vector(n); + values = new Vector<>(n); while (--n >= 0) { values.addElement(s.readObject()); } @@ -522,7 +523,7 @@ class ValuesEnumImpl implements NamingEnumeration { - Enumeration list; + Enumeration list; ValuesEnumImpl() { list = values.elements(); --- old/src/share/classes/javax/naming/directory/BasicAttributes.java 2011-07-27 17:27:12.354949000 -0700 +++ new/src/share/classes/javax/naming/directory/BasicAttributes.java 2011-07-27 17:27:11.605874100 -0700 @@ -78,7 +78,7 @@ // If ignoreCase is true, key is aways lowercase. // If ignoreCase is false, key is stored as supplied by put(). // %%% Not declared "private" due to bug 4064984. - transient Hashtable attrs = new Hashtable(11); + transient Hashtable attrs = new Hashtable<>(11); /** * Constructs a new instance of Attributes. @@ -138,6 +138,7 @@ this.put(new BasicAttribute(attrID, val)); } + @SuppressWarnings("unchecked") public Object clone() { BasicAttributes attrset; try { @@ -145,7 +146,7 @@ } catch (CloneNotSupportedException e) { attrset = new BasicAttributes(ignoreCase); } - attrset.attrs = (Hashtable)attrs.clone(); + attrset.attrs = (Hashtable)attrs.clone(); return attrset; } @@ -158,7 +159,7 @@ } public Attribute get(String attrID) { - Attribute attr = (Attribute) attrs.get( + Attribute attr = attrs.get( ignoreCase ? attrID.toLowerCase() : attrID); return (attr); } @@ -180,12 +181,12 @@ if (ignoreCase) { id = id.toLowerCase(); } - return (Attribute)attrs.put(id, attr); + return attrs.put(id, attr); } public Attribute remove(String attrID) { String id = (ignoreCase ? attrID.toLowerCase() : attrID); - return (Attribute)attrs.remove(id); + return attrs.remove(id); } /** @@ -234,7 +235,7 @@ if (size() == target.size()) { Attribute their, mine; try { - NamingEnumeration theirs = target.getAll(); + NamingEnumeration theirs = target.getAll(); while (theirs.hasMore()) { their = (Attribute)theirs.next(); mine = get(their.getID()); @@ -268,7 +269,7 @@ public int hashCode() { int hash = (ignoreCase ? 1 : 0); try { - NamingEnumeration all = getAll(); + NamingEnumeration all = getAll(); while (all.hasMore()) { hash += all.next().hashCode(); } @@ -286,7 +287,7 @@ throws java.io.IOException { s.defaultWriteObject(); // write out the ignoreCase flag s.writeInt(attrs.size()); - Enumeration attrEnum = attrs.elements(); + Enumeration attrEnum = attrs.elements(); while (attrEnum.hasMoreElements()) { s.writeObject(attrEnum.nextElement()); } @@ -300,8 +301,8 @@ s.defaultReadObject(); // read in the ignoreCase flag int n = s.readInt(); // number of attributes attrs = (n >= 1) - ? new Hashtable(n * 2) - : new Hashtable(2); // can't have initial size of 0 (grrr...) + ? new Hashtable(n * 2) + : new Hashtable(2); // can't have initial size of 0 (grrr...) while (--n >= 0) { put((Attribute)s.readObject()); } --- old/src/share/classes/javax/naming/ldap/InitialLdapContext.java 2011-07-27 17:27:19.570670500 -0700 +++ new/src/share/classes/javax/naming/ldap/InitialLdapContext.java 2011-07-27 17:27:18.880601500 -0700 @@ -129,15 +129,16 @@ * @see #reconnect * @see LdapContext#reconnect */ + @SuppressWarnings("unchecked") public InitialLdapContext(Hashtable environment, Control[] connCtls) throws NamingException { super(true); // don't initialize yet // Clone environment since caller owns it. - Hashtable env = (environment == null) - ? new Hashtable(11) - : (Hashtable)environment.clone(); + Hashtable env = (environment == null) + ? new Hashtable<>(11) + : (Hashtable)environment.clone(); // Put connect controls into environment. Copy them first since // caller owns the array. --- old/src/share/classes/javax/naming/ldap/LdapName.java 2011-07-27 17:27:26.801393500 -0700 +++ new/src/share/classes/javax/naming/ldap/LdapName.java 2011-07-27 17:27:26.214334800 -0700 @@ -104,9 +104,7 @@ public class LdapName implements Name { - // private transient ArrayList rdns; // parsed name components - - private transient ArrayList rdns; // parsed name components + private transient List rdns; // parsed name components private transient String unparsed; // if non-null, the DN in unparsed form private static final long serialVersionUID = -1595520034788997356L; @@ -144,14 +142,14 @@ // "Invalid entries, list entries must be of type Rdn"); // } - this.rdns = new ArrayList(rdns.size()); + this.rdns = new ArrayList<>(rdns.size()); for (int i = 0; i < rdns.size(); i++) { Object obj = rdns.get(i); if (!(obj instanceof Rdn)) { throw new IllegalArgumentException("Entry:" + obj + " not a valid type;list entries must be of type Rdn"); } - this.rdns.add(obj); + this.rdns.add((Rdn)obj); } } @@ -161,14 +159,12 @@ * (if "name" is not null), the unparsed DN. * */ - // private LdapName(String name, List rdns, int beg, int end) { - - private LdapName(String name, ArrayList rdns, int beg, int end) { + private LdapName(String name, List rdns, int beg, int end) { unparsed = name; // this.rdns = rdns.subList(beg, end); - List sList = rdns.subList(beg, end); - this.rdns = new ArrayList(sList); + List sList = rdns.subList(beg, end); + this.rdns = new ArrayList<>(sList); } /** @@ -201,7 +197,7 @@ * Each element of the enumeration is of class String. */ public Enumeration getAll() { - final Iterator iter = rdns.iterator(); + final Iterator iter = rdns.iterator(); return new Enumeration() { public boolean hasMoreElements() { @@ -234,7 +230,7 @@ * specified range. */ public Rdn getRdn(int posn) { - return (Rdn) rdns.get(posn); + return rdns.get(posn); } /** @@ -370,7 +366,7 @@ doesListMatch(len1 - len2, len1, rdns)); } - private boolean doesListMatch(int beg, int end, List rdns) { + private boolean doesListMatch(int beg, int end, List rdns) { for (int i = beg; i < end; i++) { if (!this.rdns.get(i).equals(rdns.get(i - beg))) { return false; @@ -457,10 +453,10 @@ LdapName s = (LdapName) suffix; rdns.addAll(posn, s.rdns); } else { - Enumeration comps = suffix.getAll(); + Enumeration comps = suffix.getAll(); while (comps.hasMoreElements()) { rdns.add(posn++, - (new Rfc2253Parser((String) comps.nextElement()). + (new Rfc2253Parser(comps.nextElement()). parseRdn())); } } @@ -489,7 +485,7 @@ throw new IllegalArgumentException("Entry:" + obj + " not a valid type;suffix list entries must be of type Rdn"); } - rdns.add(i + posn, obj); + rdns.add(i + posn, (Rdn)obj); } return this; } @@ -627,11 +623,11 @@ StringBuilder builder = new StringBuilder(); int size = rdns.size(); if ((size - 1) >= 0) { - builder.append((Rdn) rdns.get(size - 1)); + builder.append(rdns.get(size - 1)); } for (int next = size - 2; next >= 0; next--) { builder.append(','); - builder.append((Rdn) rdns.get(next)); + builder.append(rdns.get(next)); } unparsed = builder.toString(); return unparsed; @@ -672,8 +668,8 @@ // Compare RDNs one by one for equality for (int i = 0; i < rdns.size(); i++) { // Compare a single pair of RDNs. - Rdn rdn1 = (Rdn) rdns.get(i); - Rdn rdn2 = (Rdn) that.rdns.get(i); + Rdn rdn1 = rdns.get(i); + Rdn rdn2 = that.rdns.get(i); if (!rdn1.equals(rdn2)) { return false; } @@ -727,8 +723,8 @@ int minSize = Math.min(rdns.size(), that.rdns.size()); for (int i = 0; i < minSize; i++) { // Compare a single pair of RDNs. - Rdn rdn1 = (Rdn)rdns.get(i); - Rdn rdn2 = (Rdn)that.rdns.get(i); + Rdn rdn1 = rdns.get(i); + Rdn rdn2 = that.rdns.get(i); int diff = rdn1.compareTo(rdn2); if (diff != 0) { @@ -752,7 +748,7 @@ // For each RDN... for (int i = 0; i < rdns.size(); i++) { - Rdn rdn = (Rdn) rdns.get(i); + Rdn rdn = rdns.get(i); hash += rdn.hashCode(); } return hash; @@ -786,6 +782,6 @@ private void parse() throws InvalidNameException { // rdns = (ArrayList) (new RFC2253Parser(unparsed)).getDN(); - rdns = (ArrayList) (new Rfc2253Parser(unparsed)).parseDn(); + rdns = new Rfc2253Parser(unparsed).parseDn(); } } --- old/src/share/classes/javax/naming/ldap/Rdn.java 2011-07-27 17:27:33.879101200 -0700 +++ new/src/share/classes/javax/naming/ldap/Rdn.java 2011-07-27 17:27:33.157029000 -0700 @@ -104,8 +104,7 @@ public class Rdn implements Serializable, Comparable { - // private transient ArrayList entries; - private transient ArrayList entries; + private transient ArrayList entries; // The common case. private static final int DEFAULT_SIZE = 1; @@ -130,12 +129,12 @@ if (attrSet.size() == 0) { throw new InvalidNameException("Attributes cannot be empty"); } - entries = new ArrayList(attrSet.size()); - NamingEnumeration attrs = attrSet.getAll(); + entries = new ArrayList<>(attrSet.size()); + NamingEnumeration attrs = attrSet.getAll(); try { for (int nEntries = 0; attrs.hasMore(); nEntries++) { RdnEntry entry = new RdnEntry(); - Attribute attr = (Attribute) attrs.next(); + Attribute attr = attrs.next(); entry.type = attr.getID(); entry.value = attr.get(); entries.add(nEntries, entry); @@ -161,7 +160,7 @@ * parsing of the rdnString. */ public Rdn(String rdnString) throws InvalidNameException { - entries = new ArrayList(DEFAULT_SIZE); + entries = new ArrayList<>(DEFAULT_SIZE); (new Rfc2253Parser(rdnString)).parseRdn(this); } @@ -172,7 +171,7 @@ * @param rdn The non-null Rdn to be copied. */ public Rdn(Rdn rdn) { - entries = new ArrayList(rdn.entries.size()); + entries = new ArrayList<>(rdn.entries.size()); entries.addAll(rdn.entries); } @@ -199,7 +198,7 @@ "type or value cannot be empty, type:" + type + " value:" + value); } - entries = new ArrayList(DEFAULT_SIZE); + entries = new ArrayList<>(DEFAULT_SIZE); put(type, value); } @@ -210,7 +209,7 @@ // An empty constructor used by the parser Rdn() { - entries = new ArrayList(DEFAULT_SIZE); + entries = new ArrayList<>(DEFAULT_SIZE); } /* @@ -257,7 +256,7 @@ * @return The non-null attribute value. */ public Object getValue() { - return ((RdnEntry) entries.get(0)).getValue(); + return entries.get(0).getValue(); } /** @@ -275,7 +274,7 @@ * @return The non-null attribute type. */ public String getType() { - return ((RdnEntry) entries.get(0)).getType(); + return entries.get(0).getType(); } /** @@ -329,8 +328,7 @@ for (int i = 0; i < minSize; i++) { // Compare a single pair of type/value pairs. - int diff = ((RdnEntry) entries.get(i)).compareTo( - that.entries.get(i)); + int diff = entries.get(i).compareTo(that.entries.get(i)); if (diff != 0) { return diff; } @@ -408,7 +406,7 @@ public Attributes toAttributes() { Attributes attrs = new BasicAttributes(true); for (int i = 0; i < entries.size(); i++) { - RdnEntry entry = (RdnEntry) entries.get(i); + RdnEntry entry = entries.get(i); Attribute attr = attrs.put(entry.getType(), entry.getValue()); if (attr != null) { attr.add(entry.getValue()); @@ -419,7 +417,7 @@ } - private static class RdnEntry implements Comparable { + private static class RdnEntry implements Comparable { private String type; private Object value; @@ -435,12 +433,7 @@ return value; } - public int compareTo(Object obj) { - - // Any change here affecting equality must be - // reflected in hashCode(). - RdnEntry that = (RdnEntry) obj; - + public int compareTo(RdnEntry that) { int diff = type.toUpperCase().compareTo( that.type.toUpperCase()); if (diff != 0) { @@ -755,7 +748,7 @@ private void readObject(ObjectInputStream s) throws IOException, ClassNotFoundException { s.defaultReadObject(); - entries = new ArrayList(DEFAULT_SIZE); + entries = new ArrayList<>(DEFAULT_SIZE); String unparsed = (String) s.readObject(); try { (new Rfc2253Parser(unparsed)).parseRdn(this); --- old/src/share/classes/javax/naming/ldap/Rfc2253Parser.java 2011-07-27 17:27:57.925505600 -0700 +++ new/src/share/classes/javax/naming/ldap/Rfc2253Parser.java 2011-07-27 17:27:57.226435700 -0700 @@ -54,14 +54,14 @@ */ // public List getDN() throws InvalidNameException { - List parseDn() throws InvalidNameException { + List parseDn() throws InvalidNameException { cur = 0; // ArrayList rdns = // new ArrayList(len / 3 + 10); // leave room for growth - ArrayList rdns = - new ArrayList(len / 3 + 10); // leave room for growth + ArrayList rdns = + new ArrayList<>(len / 3 + 10); // leave room for growth if (len == 0) { return rdns; --- old/src/share/classes/javax/naming/ldap/StartTlsRequest.java 2011-07-27 17:28:05.670280000 -0700 +++ new/src/share/classes/javax/naming/ldap/StartTlsRequest.java 2011-07-27 17:28:04.935206500 -0700 @@ -192,7 +192,7 @@ } try { VersionHelper helper = VersionHelper.getVersionHelper(); - Class clas = helper.loadClass( + Class clas = helper.loadClass( "com.sun.jndi.ldap.ext.StartTlsResponseImpl"); resp = (StartTlsResponse) clas.newInstance(); @@ -226,19 +226,19 @@ * Acquire the class loader associated with this thread. */ private final ClassLoader getContextClassLoader() { - return (ClassLoader) AccessController.doPrivileged( - new PrivilegedAction() { - public Object run() { + return AccessController.doPrivileged( + new PrivilegedAction() { + public ClassLoader run() { return Thread.currentThread().getContextClassLoader(); } } ); } - private final static boolean privilegedHasNext(final Iterator iter) { - Boolean answer = (Boolean) AccessController.doPrivileged( - new PrivilegedAction() { - public Object run() { + private final static boolean privilegedHasNext(final Iterator iter) { + Boolean answer = AccessController.doPrivileged( + new PrivilegedAction() { + public Boolean run() { return Boolean.valueOf(iter.hasNext()); } }); --- old/src/share/classes/javax/naming/spi/ContinuationContext.java 2011-07-27 17:28:12.178930800 -0700 +++ new/src/share/classes/javax/naming/spi/ContinuationContext.java 2011-07-27 17:28:11.487861700 -0700 @@ -38,11 +38,11 @@ class ContinuationContext implements Context, Resolver { protected CannotProceedException cpe; - protected Hashtable env; + protected Hashtable env; protected Context contCtx = null; protected ContinuationContext(CannotProceedException cpe, - Hashtable env) { + Hashtable env) { this.cpe = cpe; this.env = env; } @@ -109,24 +109,24 @@ ctx.rename(name, newName); } - public NamingEnumeration list(Name name) throws NamingException { + public NamingEnumeration list(Name name) throws NamingException { Context ctx = getTargetContext(); return ctx.list(name); } - public NamingEnumeration list(String name) throws NamingException { + public NamingEnumeration list(String name) throws NamingException { Context ctx = getTargetContext(); return ctx.list(name); } - public NamingEnumeration listBindings(Name name) + public NamingEnumeration listBindings(Name name) throws NamingException { Context ctx = getTargetContext(); return ctx.listBindings(name); } - public NamingEnumeration listBindings(String name) throws NamingException { + public NamingEnumeration listBindings(String name) throws NamingException { Context ctx = getTargetContext(); return ctx.listBindings(name); } @@ -193,7 +193,7 @@ return ctx.removeFromEnvironment(propName); } - public Hashtable getEnvironment() throws NamingException { + public Hashtable getEnvironment() throws NamingException { Context ctx = getTargetContext(); return ctx.getEnvironment(); } --- old/src/share/classes/javax/naming/spi/ContinuationDirContext.java 2011-07-27 17:28:18.898602700 -0700 +++ new/src/share/classes/javax/naming/spi/ContinuationDirContext.java 2011-07-27 17:28:18.194532300 -0700 @@ -38,6 +38,7 @@ import javax.naming.directory.DirContext; import javax.naming.directory.Attributes; import javax.naming.directory.SearchControls; +import javax.naming.directory.SearchResult; import javax.naming.directory.ModificationItem; /** @@ -50,7 +51,7 @@ class ContinuationDirContext extends ContinuationContext implements DirContext { - ContinuationDirContext(CannotProceedException cpe, Hashtable env) { + ContinuationDirContext(CannotProceedException cpe, Hashtable env) { super(cpe, env); } @@ -204,7 +205,7 @@ res.getDirContext().createSubcontext(res.getString(), attrs); } - public NamingEnumeration search(Name name, + public NamingEnumeration search(Name name, Attributes matchingAttributes, String[] attributesToReturn) throws NamingException { @@ -213,7 +214,7 @@ attributesToReturn); } - public NamingEnumeration search(String name, + public NamingEnumeration search(String name, Attributes matchingAttributes, String[] attributesToReturn) throws NamingException { @@ -223,13 +224,13 @@ attributesToReturn); } - public NamingEnumeration search(Name name, + public NamingEnumeration search(Name name, Attributes matchingAttributes) throws NamingException { DirContextNamePair res = getTargetContext(name); return res.getDirContext().search(res.getName(), matchingAttributes); } - public NamingEnumeration search(String name, + public NamingEnumeration search(String name, Attributes matchingAttributes) throws NamingException { DirContextStringPair res = getTargetContext(name); @@ -237,7 +238,7 @@ matchingAttributes); } - public NamingEnumeration search(Name name, + public NamingEnumeration search(Name name, String filter, SearchControls cons) throws NamingException { @@ -245,7 +246,7 @@ return res.getDirContext().search(res.getName(), filter, cons); } - public NamingEnumeration search(String name, + public NamingEnumeration search(String name, String filter, SearchControls cons) throws NamingException { @@ -253,7 +254,7 @@ return res.getDirContext().search(res.getString(), filter, cons); } - public NamingEnumeration search(Name name, + public NamingEnumeration search(Name name, String filterExpr, Object[] args, SearchControls cons) @@ -263,7 +264,7 @@ cons); } - public NamingEnumeration search(String name, + public NamingEnumeration search(String name, String filterExpr, Object[] args, SearchControls cons) --- old/src/share/classes/javax/naming/spi/DirectoryManager.java 2011-07-27 17:28:26.150327800 -0700 +++ new/src/share/classes/javax/naming/spi/DirectoryManager.java 2011-07-27 17:28:25.477260500 -0700 @@ -84,15 +84,16 @@ * * @see NamingManager#getContinuationContext(CannotProceedException) */ + @SuppressWarnings("unchecked") public static DirContext getContinuationDirContext( CannotProceedException cpe) throws NamingException { - Hashtable env = cpe.getEnvironment(); + Hashtable env = (Hashtable)cpe.getEnvironment(); if (env == null) { - env = new Hashtable(7); + env = new Hashtable<>(7); } else { // Make a (shallow) copy of the environment. - env = (Hashtable) env.clone(); + env = (Hashtable) env.clone(); } env.put(CPE, cpe); @@ -217,7 +218,7 @@ } private static Object createObjectFromFactories(Object obj, Name name, - Context nameCtx, Hashtable environment, Attributes attrs) + Context nameCtx, Hashtable environment, Attributes attrs) throws Exception { FactoryEnumeration factories = ResourceManager.getFactories( --- old/src/share/classes/javax/naming/spi/NamingManager.java 2011-07-27 17:28:32.919004600 -0700 +++ new/src/share/classes/javax/naming/spi/NamingManager.java 2011-07-27 17:28:32.263939100 -0700 @@ -139,7 +139,7 @@ throws IllegalAccessException, InstantiationException, MalformedURLException { - Class clas = null; + Class clas = null; // Try to use current class loader try { @@ -172,7 +172,7 @@ * @return factory created; null if cannot create */ private static Object createObjectFromFactories(Object obj, Name name, - Context nameCtx, Hashtable environment) throws Exception { + Context nameCtx, Hashtable environment) throws Exception { FactoryEnumeration factories = ResourceManager.getFactories( Context.OBJECT_FACTORIES, environment, nameCtx); @@ -349,7 +349,7 @@ * invoking a factory. */ static Object processURLAddrs(Reference ref, Name name, Context nameCtx, - Hashtable environment) + Hashtable environment) throws NamingException { for (int i = 0; i < ref.size(); i++) { @@ -368,7 +368,7 @@ } private static Object processURL(Object refInfo, Name name, - Context nameCtx, Hashtable environment) + Context nameCtx, Hashtable environment) throws NamingException { Object answer; @@ -427,7 +427,7 @@ * @see #getObjectInstance */ static Context getContext(Object obj, Name name, Context nameCtx, - Hashtable environment) throws NamingException { + Hashtable environment) throws NamingException { Object answer; if (obj instanceof Context) { @@ -452,7 +452,7 @@ // Used by ContinuationContext static Resolver getResolver(Object obj, Name name, Context nameCtx, - Hashtable environment) throws NamingException { + Hashtable environment) throws NamingException { Object answer; if (obj instanceof Resolver) { @@ -585,7 +585,7 @@ */ private static Object getURLObject(String scheme, Object urlInfo, Name name, Context nameCtx, - Hashtable environment) + Hashtable environment) throws NamingException { // e.g. "ftpURLContextFactory" @@ -771,15 +771,16 @@ * @return A non-null Context object for continuing the operation. * @exception NamingException If a naming exception occurred. */ + @SuppressWarnings("unchecked") public static Context getContinuationContext(CannotProceedException cpe) throws NamingException { - Hashtable env = cpe.getEnvironment(); + Hashtable env = (Hashtable)cpe.getEnvironment(); if (env == null) { - env = new Hashtable(7); + env = new Hashtable<>(7); } else { // Make a (shallow) copy of the environment. - env = (Hashtable) env.clone(); + env = (Hashtable)env.clone(); } env.put(CPE, cpe);