author | phh |
Sat, 30 Nov 2019 14:33:05 -0800 (2019-11-30) | |
changeset 59330 | 5b96c12f909d |
parent 55741 | 880266b6e5b3 |
permissions | -rw-r--r-- |
2 | 1 |
/* |
55741
880266b6e5b3
8228392: Backout incorrect change done by JDK-8067801
bpb
parents:
55729
diff
changeset
|
2 |
* Copyright (c) 1998, Oracle and/or its affiliates. All rights reserved. |
2 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
7 |
* published by the Free Software Foundation. |
|
8 |
* |
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
13 |
* accompanied this code). |
|
14 |
* |
|
15 |
* You should have received a copy of the GNU General Public License version |
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
18 |
* |
|
5506 | 19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
20 |
* or visit www.oracle.com if you need additional information or have any |
|
21 |
* questions. |
|
2 | 22 |
*/ |
23 |
||
24 |
/* @test |
|
25 |
@bug 4015701 4127654 |
|
26 |
@summary Test if the constructor would detect |
|
27 |
illegal arguments. |
|
28 |
*/ |
|
29 |
||
30 |
import java.io.*; |
|
31 |
||
32 |
public class NegativeInitSize { |
|
33 |
public static void main(String[] args) throws Exception { |
|
34 |
try { |
|
35 |
ByteArrayOutputStream bos = new ByteArrayOutputStream(-1); |
|
36 |
} catch (IllegalArgumentException e) { |
|
37 |
} catch (Exception e){ |
|
38 |
System.out.println(e.getMessage()); |
|
39 |
throw new Exception |
|
40 |
("ByteArrayOutputStream failed to detect negative init size"); |
|
41 |
} |
|
42 |
CharArrayReader CAR = new CharArrayReader("test".toCharArray()); |
|
43 |
try { |
|
44 |
PushbackReader pbr = new PushbackReader(CAR, -1); |
|
45 |
} catch (IllegalArgumentException e) { |
|
46 |
} catch (Exception e) { |
|
47 |
System.out.println(e.getClass().getName()); |
|
48 |
throw new Exception |
|
49 |
("PushbackReader failed to detect negative init size"); |
|
50 |
} |
|
51 |
||
52 |
try { |
|
55741
880266b6e5b3
8228392: Backout incorrect change done by JDK-8067801
bpb
parents:
55729
diff
changeset
|
53 |
PushbackInputStream pbis = new PushbackInputStream(null, -1); |
2 | 54 |
} catch (IllegalArgumentException e) { |
55 |
} catch (Exception e) { |
|
56 |
throw new Exception |
|
57 |
("PushbackInputStream failed to detect negative init size"); |
|
58 |
} |
|
59 |
||
60 |
ByteArrayOutputStream goodbos = new ByteArrayOutputStream(); |
|
61 |
try { |
|
62 |
BufferedOutputStream bos = new BufferedOutputStream(goodbos, -1); |
|
63 |
} catch (IllegalArgumentException e) { |
|
64 |
} catch (Exception e) { |
|
65 |
throw new Exception |
|
66 |
("BufferedOutputStream failed to detect negative init size"); |
|
67 |
} |
|
68 |
||
55741
880266b6e5b3
8228392: Backout incorrect change done by JDK-8067801
bpb
parents:
55729
diff
changeset
|
69 |
byte[] ba = { 123 }; |
880266b6e5b3
8228392: Backout incorrect change done by JDK-8067801
bpb
parents:
55729
diff
changeset
|
70 |
ByteArrayInputStream goodbis = new ByteArrayInputStream(ba); |
2 | 71 |
try { |
72 |
BufferedInputStream bis = new BufferedInputStream(goodbis, -1); |
|
73 |
} catch (IllegalArgumentException e) { |
|
74 |
} catch (Exception e) { |
|
75 |
throw new Exception |
|
76 |
("BufferedInputStream failed to detect negative init size"); |
|
77 |
} |
|
78 |
||
79 |
try { |
|
80 |
CharArrayWriter caw = new CharArrayWriter(-1); |
|
81 |
} catch (IllegalArgumentException e) { |
|
82 |
} catch (Exception e) { |
|
83 |
throw new Exception |
|
84 |
("CharArrayWriter failed to detect negative init size"); |
|
85 |
} |
|
86 |
} |
|
87 |
} |