Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-4493595

FileLock.release() behaves differently on Windows and Sparc plaftorms.

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P3 P3
    • 1.4.0
    • 1.4.0
    • core-libs
    • beta3
    • sparc
    • solaris_8
    • Verified

      specification for FileLock.release() says:
      "If this lock object is valid then invoking this method releases the lock and renders the object invalid. If this lock object is invalid then invoking this
      method has no effect." ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      ^^^^^^^^^^^^^^^^^^^^

      No effect takes place when release() is called twice, on sparc platform. But for Windows platform it results in IOException.

      import java.io.*;
      import java.nio.channels.*;
      import java.nio.*;

      public class Release {

           public static void main(String[] args) throws Exception {
              Release tests = new Release();
              tests.releaseTest01();
           }

          public void releaseTest01() throws Exception {
              RandomAccessFile raf = null;
              FileChannel c = null;
              File tempFile = new File("blahTemp");
              tempFile.deleteOnExit();
              initTestFile(tempFile);
              try {
                 raf = new RandomAccessFile(tempFile,"rw");
                 c = raf.getChannel();
                 FileLock fl1 = c.lock(0,c.size(),true);
                 try {
                   fl1.release();
                   String result = fl1.toString();
                   //Check : If this lock object is invalid then invoking this method has no effect.
                   fl1.release();
                   System.out.println("PASS. Calling release again does not result in anything ");
                   if(!(fl1.toString().equals(result))) {
                        System.out.println("FAIL. Calling release again should not result in anything ");
                   }
                 } catch(Exception e){
                    e.printStackTrace();
                    System.out.println("FAIL. Calling release again should not result in exception");
                 }
              } catch (Exception e) {
                 e.printStackTrace();
              }
          }
          private void initTestFile(File blah) throws Exception {
              FileOutputStream fos = new FileOutputStream(blah);
              BufferedWriter awriter
                  = new BufferedWriter(new OutputStreamWriter(fos, "8859_1"));
              for(int i=0; i<4000; i++) {
                  String number = new Integer(i).toString();
                  for (int h=0; h<4-number.length(); h++)
                      awriter.write("0");
                  awriter.write(""+i);
                  awriter.newLine();
              }
             awriter.flush();
             awriter.close();
          }
      } // Class Release

      For Sparc Machine:
      PASS. Calling release again does not result in anything

      For Windows NT :
      java.io.IOException: The segment is already unlocked
              at sun.nio.ch.FileChannelImpl.release0(Native Method)
              at sun.nio.ch.FileChannelImpl.release(FileChannelImpl.java:514)
              at sun.nio.ch.FileLockImpl.release(FileLockImpl.java:36)
              at Release.releaseTest01(Release.java:26)
              at Release.main(Release.java:9)
      FAIL. Calling release again should not result in exception

            mmcclosksunw Michael Mccloskey (Inactive)
            duke J. Duke
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: