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

(fs) Files.lines(path).collect() returns wrong value in JDK 9 with certain files

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P3 P3
    • 9
    • 9
    • core-libs
    • b78
    • linux
    • Verified

        This happens on Linux machines with the file /proc/sys/kernel/yama/ptrace_scope only, so far.

        We're reading the contents of the file using:

        String NEW_LINE = System.getProperty("line.separator");
        String s = Files.lines(path).collect(Collectors.joining(NEW_LINE));

        With JDK8 the contents are correctly returned. With JDK 9 an empty string returned instead.

        Following is the output:

        $ java -version
        java version "1.9.0-ea"
        Java(TM) SE Runtime Environment (build 1.9.0-ea-b74)
        Java HotSpot(TM) 64-Bit Server VM (build 1.9.0-ea-b74, mixed mode)

        $ cat /proc/sys/kernel/yama/ptrace_scope
        1

        $ java -jar "/home/akulyakh/NetBeansProjects/StreamTest/dist/StreamTest.jar" /proc/sys/kernel/yama/ptrace_scope
        Resulting line:

        $ java -version
        java version "1.8.0_65-ea"
        Java(TM) SE Runtime Environment (build 1.8.0_65-ea-b04)
        Java HotSpot(TM) 64-Bit Server VM (build 25.65-b01, mixed mode)


        java -jar "/home/akulyakh/NetBeansProjects/StreamTest/dist/StreamTest.jar" /proc/sys/kernel/yama/ptrace_scope
        Resulting line: 1

        The program to read is as follows:

        public class StreamTest {

            /**
             * @param args the command line arguments
             */
            public static void main(String[] args) throws IOException {
                
                if(args.length < 1) throw new IllegalArgumentException("Please specify path to file");
                
                Path path = Paths.get(args[0]);
                
                if(!Files.exists(path)) throw new IllegalArgumentException("File must exist");
                
                String NEW_LINE = System.getProperty("line.separator");
                String s = Files.lines(path).collect(Collectors.joining(NEW_LINE));
                System.out.println("Lines read from the file: " + s);
            }

        }

              bpb Brian Burkhalter
              akulyakh Alexander Kulyakhtin (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              5 Start watching this issue

                Created:
                Updated:
                Resolved: