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

Method RandomAccessFile#length() returns 0 for block devices on linux.

    XMLWordPrintable

    Details

    • Subcomponent:
    • Resolved In Build:
      b22
    • CPU:
      x86_64
    • OS:
      linux_ubuntu
    • Verification:
      Verified

      Description

      ADDITIONAL SYSTEM INFORMATION :
      Ubuntu 20.04.1 LTS
      openjdk version "11.0.11" 2021-04-20
      OpenJDK Runtime Environment 18.9 (build 11.0.11+9)

      A DESCRIPTION OF THE PROBLEM :
      The problem with RandomAccessFile#length() have been found after using RandomAccessFile#skipBytes() for block device in linux. Method skipBytes always returns 0 skipped bytes for any block device in linux. I made research which showed that method length() was responsible for wrong results of skipBytes() method. I also found that implementation of method length() has changed since Java 9.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      1. Create a random access file stream to read from any device block in linux eg. /dev/sda
      2. Run length() method from RandomAccessFile object

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      Correct size of device block returned by length() method from RandomAccessFile object.
      ACTUAL -
      RandomAccessFile.length() method for block device return always 0

      ---------- BEGIN SOURCE ----------
      import java.io.IOException;
      import java.io.RandomAccessFile;

      public class Test {
        public static void main(String[] args) throws IOException {
            String blockDevicePath = "/dev/sda";
            RandomAccessFile file = new RandomAccessFile(blockDevicePath,"r");
            System.out.println(blockDevicePath);
            System.out.println("Channel size: "+file.getChannel().size());
            System.out.println("Length: "+file.length());
        }
      }
      ---------- END SOURCE ----------

      FREQUENCY : always


        Attachments

          Issue Links

            Activity

              People

              Assignee:
              vtewari Vyom Tewari
              Reporter:
              webbuggrp Webbug Group
              Votes:
              0 Vote for this issue
              Watchers:
              7 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved: