Print this page


Split Close
Expand all
Collapse all
          --- old/src/share/classes/sun/rmi/log/ReliableLog.java
          +++ new/src/share/classes/sun/rmi/log/ReliableLog.java
↓ open down ↓ 322 lines elided ↑ open up ↑
 323  323          lastLog = System.currentTimeMillis();
 324  324          logEntries++;
 325  325      }
 326  326  
 327  327      /**
 328  328       * Returns the constructor for the log file if the system property
 329  329       * sun.rmi.log.class is non-null and the class specified by the
 330  330       * property a) can be loaded, b) is a subclass of LogFile, and c) has a
 331  331       * public two-arg constructor (String, String); otherwise returns null.
 332  332       **/
      333 +    @SuppressWarnings("unchecked")
 333  334      private static Constructor<? extends LogFile>
 334  335          getLogClassConstructor() {
 335  336  
 336  337          String logClassName = AccessController.doPrivileged(
 337  338              new GetPropertyAction("sun.rmi.log.class"));
 338  339          if (logClassName != null) {
 339  340              try {
 340  341                  ClassLoader loader =
 341  342                      AccessController.doPrivileged(
 342  343                          new PrivilegedAction<ClassLoader>() {
 343  344                              public ClassLoader run() {
 344  345                                 return ClassLoader.getSystemClassLoader();
 345  346                              }
 346  347                          });
 347      -                Class cl = loader.loadClass(logClassName);
      348 +                Class<?> cl = loader.loadClass(logClassName);
 348  349                  if (LogFile.class.isAssignableFrom(cl)) {
 349      -                    return cl.getConstructor(String.class, String.class);
      350 +                    return (Constructor<? extends LogFile>)
      351 +                            cl.getConstructor(String.class, String.class);
 350  352                  }
 351  353              } catch (Exception e) {
 352  354                  System.err.println("Exception occurred:");
 353  355                  e.printStackTrace();
 354  356              }
 355  357          }
 356  358          return null;
 357  359      }
 358  360  
 359  361      /**
↓ open down ↓ 228 lines elided ↑ open up ↑
 588  590       * @param newVersion if true, writes to a new version file
 589  591       * @exception IOException If an I/O error has occurred.
 590  592       */
 591  593      private void writeVersionFile(boolean newVersion) throws IOException {
 592  594          String name;
 593  595          if (newVersion) {
 594  596              name = newVersionFile;
 595  597          } else {
 596  598              name = versionFile;
 597  599          }
 598      -        DataOutputStream out =
 599      -            new DataOutputStream(new FileOutputStream(fName(name)));
 600      -        writeInt(out, version);
 601      -        out.close();
      600 +        try (DataOutputStream out = new DataOutputStream
      601 +                (new FileOutputStream(fName(name)))) {
      602 +            writeInt(out, version);
      603 +        }
 602  604      }
 603  605  
 604  606      /**
 605  607       * Creates the initial version file
 606  608       *
 607  609       * @exception IOException If an I/O error has occurred.
 608  610       */
 609  611      private void createFirstVersion() throws IOException {
 610  612          version = 0;
 611  613          writeVersionFile(false);
↓ open down ↓ 10 lines elided ↑ open up ↑
 622  624      }
 623  625  
 624  626      /**
 625  627       * Reads version number from a file.
 626  628       *
 627  629       * @param name the name of the version file
 628  630       * @return the version
 629  631       * @exception IOException If an I/O error has occurred.
 630  632       */
 631  633      private int readVersion(String name) throws IOException {
 632      -        DataInputStream in = new DataInputStream(new FileInputStream(name));
 633      -        try {
      634 +        try (DataInputStream in = new DataInputStream
      635 +                (new FileInputStream(name))) {
 634  636              return in.readInt();
 635      -        } finally {
 636      -            in.close();
 637  637          }
 638  638      }
 639  639  
 640  640      /**
 641  641       * Sets the version.  If version file does not exist, the initial
 642  642       * version file is created.
 643  643       *
 644  644       * @exception IOException If an I/O error has occurred.
 645  645       */
 646  646      private void getVersion() throws IOException {
↓ open down ↓ 181 lines elided ↑ open up ↑
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX