src/share/classes/com/sun/jndi/ldap/Obj.java

Print this page

        

@@ -1,7 +1,7 @@
 /*
- * 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
  * under the terms of the GNU General Public License version 2 only, as
  * published by the Free Software Foundation.  Oracle designates this

@@ -82,10 +82,11 @@
     static final int REF_ADDR = 5;
     static final int TYPENAME = 6;
     /**
      * @deprecated
      */
+    @Deprecated
     private static final int REMOTE_LOC = 7;
 
     // LDAP object classes to support Java objects
     static final String[] JAVA_OBJECT_CLASSES = {
         "javaContainer",

@@ -204,17 +205,17 @@
         if (codebaseAttr == null) {
             return null;
         } else {
             StringTokenizer parser =
                 new StringTokenizer((String)codebaseAttr.get());
-            Vector vec = new Vector(10);
+            Vector<String> 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;
         }
     }
 

@@ -408,14 +409,14 @@
 
             /*
              * Temporary Vector for decoded RefAddr addresses - used to ensure
              * unordered addresses are correctly re-ordered.
              */
-            Vector refAddrList = new Vector();
+            Vector<RefAddr> 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();
 
                 if (val.length() == 0) {
                     throw new InvalidAttributeValueException(

@@ -486,11 +487,11 @@
                 }
             }
 
             // Copy to real reference
             for (int i = 0; i < refAddrList.size(); i++) {
-                ref.add((RefAddr)refAddrList.elementAt(i));
+                ref.add(refAddrList.elementAt(i));
             }
         }
 
         return (ref);
     }

@@ -500,13 +501,13 @@
      */
     private static byte[] serializeObject(Object obj) throws NamingException {
 
         try {
             ByteArrayOutputStream bytes = new ByteArrayOutputStream();
-            ObjectOutputStream serial = new ObjectOutputStream(bytes);
+            try (ObjectOutputStream serial = new ObjectOutputStream(bytes)) {
             serial.writeObject(obj);
-            serial.close();
+            }
 
             return (bytes.toByteArray());
 
         } catch (IOException e) {
             NamingException ne = new NamingException();

@@ -522,22 +523,18 @@
         throws NamingException {
 
         try {
             // Create ObjectInputStream for deserialization
             ByteArrayInputStream bytes = new ByteArrayInputStream(obj);
-            ObjectInputStream deserial = (cl == null ?
+            try (ObjectInputStream deserial = cl == null ?
                 new ObjectInputStream(bytes) :
-                new LoaderInputStream(bytes, cl));
-
-            try {
+                    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();
             ne.setRootCause(e);
             throw ne;

@@ -547,11 +544,11 @@
     /**
       * Returns the attributes to bind given an object and its attributes.
       */
     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
         DirStateFactory.Result res =
             DirectoryManager.getStateToBind(obj, name, ctx, env, attrs);

@@ -580,14 +577,14 @@
             // No objectclasses supplied, use "top" to start
             objectClass = new BasicAttribute("objectClass", "top");
 
         } 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
             if (objectClass == null) {
                 objectClass =  new BasicAttribute("objectClass", "top");

@@ -612,30 +609,30 @@
         LoaderInputStream(InputStream in, ClassLoader cl) throws IOException {
             super(in);
             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
                 return classLoader.loadClass(desc.getName());
             } catch (ClassNotFoundException e) {
                 return super.resolveClass(desc);
             }
         }
 
-         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()) {
                              throw new IllegalAccessError(
                                 "conflicting non-public interface class loaders");