src/share/classes/sun/rmi/log/ReliableLog.java

Print this page

        

@@ -116,11 +116,11 @@
      * sun.rmi.log.class is non-null and the class specified by this
      * property a) can be loaded, b) is a subclass of LogFile, and c) has a
      * public two-arg constructor (String, String), ReliableLog uses the
      * constructor to construct the LogFile.
      **/
-    private static final Constructor<? extends LogFile>
+    private static final Constructor<?>
         logClassConstructor = getLogClassConstructor();
 
     /**
      * Creates a ReliableLog to handle checkpoints and logging in a
      * stable storage directory.

@@ -342,14 +342,13 @@
                         new PrivilegedAction<ClassLoader>() {
                             public ClassLoader run() {
                                return ClassLoader.getSystemClassLoader();
                             }
                         });
-                Class cl = loader.loadClass(logClassName);
-                if (LogFile.class.isAssignableFrom(cl)) {
+                Class<? extends LogFile> cl = 
+                    loader.loadClass(logClassName).asSubclass(LogFile.class);
                     return cl.getConstructor(String.class, String.class);
-                }
             } catch (Exception e) {
                 System.err.println("Exception occurred:");
                 e.printStackTrace();
             }
         }

@@ -543,11 +542,11 @@
         logName = versionName(logfilePrefix);
 
         try {
             log = (logClassConstructor == null ?
                    new LogFile(logName, "rw") :
-                   logClassConstructor.newInstance(logName, "rw"));
+                   (LogFile)logClassConstructor.newInstance(logName, "rw"));
         } catch (Exception e) {
             throw (IOException) new IOException(
                 "unable to construct LogFile instance").initCause(e);
         }
 

@@ -593,15 +592,15 @@
         if (newVersion) {
             name = newVersionFile;
         } else {
             name = versionFile;
         }
-        DataOutputStream out =
-            new DataOutputStream(new FileOutputStream(fName(name)));
+        try (FileOutputStream fos = new FileOutputStream(fName(name));
+             DataOutputStream out = new DataOutputStream(fos)) {
         writeInt(out, version);
-        out.close();
     }
+    }
 
     /**
      * Creates the initial version file
      *
      * @exception IOException If an I/O error has occurred.

@@ -627,15 +626,13 @@
      * @param name the name of the version file
      * @return the version
      * @exception IOException If an I/O error has occurred.
      */
     private int readVersion(String name) throws IOException {
-        DataInputStream in = new DataInputStream(new FileInputStream(name));
-        try {
+        try (DataInputStream in = new DataInputStream
+                (new FileInputStream(name))) {
             return in.readInt();
-        } finally {
-            in.close();
         }
     }
 
     /**
      * Sets the version.  If version file does not exist, the initial