< prev index next >

test/jdk/java/io/NegativeInitSize.java

Print this page


   1 /*
   2  * Copyright (c) 1998, 2019 Oracle and/or its affiliates. All rights reserved.
   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  *
  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.
  22  */


  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         byte[] ba = { 123 };
  53         ByteArrayInputStream goodbis = new ByteArrayInputStream(ba);
  54         try {
  55             PushbackInputStream pbis = new PushbackInputStream(goodbis, -1);
  56         } catch (IllegalArgumentException e) {
  57         } catch (Exception e) {
  58             throw new Exception
  59                 ("PushbackInputStream failed to detect negative init size");
  60         }
  61 
  62         ByteArrayOutputStream goodbos = new ByteArrayOutputStream();
  63         try {
  64             BufferedOutputStream bos = new BufferedOutputStream(goodbos, -1);
  65         } catch (IllegalArgumentException e) {
  66         } catch (Exception e) {
  67             throw new Exception
  68                 ("BufferedOutputStream failed to detect negative init size");
  69         }
  70 


  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 }
   1 /*
   2  * Copyright (c) 1998, Oracle and/or its affiliates. All rights reserved.
   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  *
  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.
  22  */


  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 {
  53             PushbackInputStream pbis = new PushbackInputStream(null, -1);
  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 
  69         byte[] ba = { 123 };
  70         ByteArrayInputStream goodbis = new ByteArrayInputStream(ba);
  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 }
< prev index next >