mirror of
https://github.com/openjdk/jdk.git
synced 2026-02-02 06:28:23 +00:00
8342086: FileInputStream.available() fails with "Incorrect function" for "nul" path (win)
Reviewed-by: alanb
This commit is contained in:
parent
60bd73a595
commit
3eaa7615cd
@ -342,16 +342,8 @@ handleNonSeekAvailable(FD fd, long *pbytes) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (! PeekNamedPipe(han, NULL, 0, NULL, pbytes, NULL)) {
|
||||
/* PeekNamedPipe fails when at EOF. In that case we
|
||||
* simply make *pbytes = 0 which is consistent with the
|
||||
* behavior we get on Solaris when an fd is at EOF.
|
||||
* The only alternative is to raise and Exception,
|
||||
* which isn't really warranted.
|
||||
*/
|
||||
if (GetLastError() != ERROR_BROKEN_PIPE) {
|
||||
return FALSE;
|
||||
}
|
||||
if (!PeekNamedPipe(han, NULL, 0, NULL, pbytes, NULL)) {
|
||||
// If PeekNamedPipe fails, set the number of available bytes to zero.
|
||||
*pbytes = 0;
|
||||
}
|
||||
return TRUE;
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 1998, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 1998, 2024, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -23,25 +23,38 @@
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @bug 4129479
|
||||
* @summary Test if available would throw an IOException
|
||||
* when the stream is closed.
|
||||
* @bug 4129479 8342086
|
||||
* @summary Test that available throws an IOException if the stream is
|
||||
* closed, and that available works correctly with the NUL
|
||||
* device on Windows
|
||||
* @run junit Available
|
||||
*/
|
||||
|
||||
import java.io.*;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.condition.EnabledOnOs;
|
||||
import org.junit.jupiter.api.condition.OS;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
public class Available {
|
||||
public static void main(String args[]) throws Exception {
|
||||
@Test
|
||||
void throwAfterClose() throws IOException {
|
||||
File file = new File(System.getProperty("test.src", "."),
|
||||
"Available.java");
|
||||
FileInputStream fis = new FileInputStream(file);
|
||||
fis.close();
|
||||
try {
|
||||
fis.available();
|
||||
throw new Exception
|
||||
("available should throw an exception after stream is closed");
|
||||
}
|
||||
catch (IOException e) {
|
||||
}
|
||||
assertThrows(IOException.class, () -> fis.available());
|
||||
}
|
||||
|
||||
@Test
|
||||
@EnabledOnOs(OS.WINDOWS)
|
||||
void nulDevice() throws IOException {
|
||||
File file = new File("nul");
|
||||
FileInputStream fis = new FileInputStream(file);
|
||||
int n = fis.available();
|
||||
assertEquals(0, n, "available() returned non-zero value");
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user