-
Bug
-
Resolution: Fixed
-
P3
-
9
-
b78
-
linux
-
Verified
Issue | Fix Version | Assignee | Priority | Status | Resolution | Resolved In Build |
---|---|---|---|---|---|---|
JDK-8135840 | emb-9 | Brian Burkhalter | P3 | Resolved | Fixed | team |
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);
}
}
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);
}
}
- backported by
-
JDK-8135840 (fs) Files.lines(path).collect() returns wrong value in JDK 9 with certain files
-
- Resolved
-
- relates to
-
JDK-8135091 (fs) java/nio/file/Files/StreamLinesTest.java should test empty files
-
- Closed
-
-
JDK-8072773 (fs) Files.lines needs a better splitting implementation for stream source
-
- Closed
-