|
1 | 1 | /*
|
2 |
| - * Copyright (c) 1998, Oracle and/or its affiliates. All rights reserved. |
| 2 | + * Copyright (c) 1998, 2024, Oracle and/or its affiliates. All rights reserved. |
3 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
4 | 4 | *
|
5 | 5 | * This code is free software; you can redistribute it and/or modify it
|
|
23 | 23 |
|
24 | 24 | /*
|
25 | 25 | * @test
|
26 |
| - * @bug 4129479 |
27 |
| - * @summary Test if available would throw an IOException |
28 |
| - * when the stream is closed. |
| 26 | + * @bug 4129479 8342086 |
| 27 | + * @summary Test that available throws an IOException if the stream is |
| 28 | + * closed, and that available works correctly with the NUL |
| 29 | + * device on Windows |
| 30 | + * @run junit Available |
29 | 31 | */
|
30 | 32 |
|
31 |
| -import java.io.*; |
| 33 | +import java.io.File; |
| 34 | +import java.io.FileInputStream; |
| 35 | +import java.io.IOException; |
| 36 | + |
| 37 | +import org.junit.jupiter.api.Test; |
| 38 | +import org.junit.jupiter.api.condition.EnabledOnOs; |
| 39 | +import org.junit.jupiter.api.condition.OS; |
| 40 | +import static org.junit.jupiter.api.Assertions.*; |
32 | 41 |
|
33 | 42 | public class Available {
|
34 |
| - public static void main(String args[]) throws Exception { |
| 43 | + @Test |
| 44 | + void throwAfterClose() throws IOException { |
35 | 45 | File file = new File(System.getProperty("test.src", "."),
|
36 | 46 | "Available.java");
|
37 | 47 | FileInputStream fis = new FileInputStream(file);
|
38 | 48 | fis.close();
|
39 |
| - try { |
40 |
| - fis.available(); |
41 |
| - throw new Exception |
42 |
| - ("available should throw an exception after stream is closed"); |
43 |
| - } |
44 |
| - catch (IOException e) { |
45 |
| - } |
| 49 | + assertThrows(IOException.class, () -> fis.available()); |
| 50 | + } |
| 51 | + |
| 52 | + @Test |
| 53 | + @EnabledOnOs(OS.WINDOWS) |
| 54 | + void nulDevice() throws IOException { |
| 55 | + File file = new File("nul"); |
| 56 | + FileInputStream fis = new FileInputStream(file); |
| 57 | + int n = fis.available(); |
| 58 | + assertEquals(0, n, "available() returned non-zero value"); |
46 | 59 | }
|
47 | 60 | }
|
1 commit comments
openjdk-notifier[bot] commentedon Dec 3, 2024
Review
Issues