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

FileInputStream doesn't support readAllBytes() or readNBytes(int) on pseudo devices

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P4 P4
    • 24
    • 8, 24
    • core-libs
    • b22
    • x86_64
    • linux_ubuntu, os_x
    • Verified

      ADDITIONAL SYSTEM INFORMATION :
      Linux VMware-Virtual-Platform 6.11.0-8-generic #8-Ubuntu SMP PREEMPT_DYNAMIC Mon Sep 16 13:41:20 UTC 2024 x86_64 x86_64 x86_64 GNU/Linux

      openjdk version "24-ea" 2025-03-18
      OpenJDK Runtime Environment (build 24-ea+16-Ubuntu-1)
      OpenJDK 64-Bit Server VM (build 24-ea+16-Ubuntu-1, mixed mode, sharing)

      openjdk version "1.8.0_422"
      OpenJDK Runtime Environment (build 1.8.0_422-8u422-b05-1ubuntu1-b05)
      OpenJDK 64-Bit Server VM (build 25.422-b05, mixed mode)

      A DESCRIPTION OF THE PROBLEM :
      Methods that invoke lseek on Linux will fail if file descriptor is stdin. This does not happen on a Windows system.
      Also fails on JDK 8, 11, 17, 21

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Execute the program.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      Program completes normally.
      ACTUAL -
      Exception in thread "main" java.io.IOException: Illegal seek

      ---------- BEGIN SOURCE ----------
      import java.io.FileDescriptor;
      import java.io.FileInputStream;
      import java.io.IOException;
      import java.nio.channels.Channels;

      public class NIOTest {

      public static void main(String[] args) throws IOException {
      new FileInputStream(FileDescriptor.in).available(); // OK
      new FileInputStream(FileDescriptor.in).readNBytes(4); // Fail
      Channels.newInputStream(new FileInputStream(FileDescriptor.in).getChannel()).available(); // Fail
      new FileInputStream(FileDescriptor.in).readAllBytes(); // Fail
      }
      }
      ---------- END SOURCE ----------

      FREQUENCY : always


            bpb Brian Burkhalter
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated:
              Resolved: