- 
    Bug 
- 
    Resolution: Fixed
- 
     P4 P4
- 
    11
- 
        b22
- 
        x86_64
- 
        linux_ubuntu
- 
        Verified
                    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
            
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
- duplicates
- 
                    JDK-8150539 Test java/nio/channels/FileChannel/BlockDeviceSize.java fails on Linux -           
- Closed
 
-         
- relates to
- 
                    JDK-8266797 Fix for 8266610 breaks the build on macos -           
- Resolved
 
-         
 
        