Path: blob/master/test/jdk/java/util/Properties/LoadAndStoreNPE.java
41149 views
/*1* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/22import java.io.InputStream;23import java.io.OutputStream;24import java.io.Reader;25import java.io.Writer;26import java.util.Properties;2728/*29* @test30* @bug 8073214 807536231* @summary Tests to verify that load() and store() throw NPEs as advertised.32*/33public class LoadAndStoreNPE34{35public static void main(String[] args) throws Exception36{37int failures = 0;3839Properties props = new Properties();4041try {42props.store((OutputStream)null, "comments");43failures++;44} catch (NullPointerException e) {45// do nothing46}4748try {49props.store((Writer)null, "comments");50failures++;51} catch (NullPointerException e) {52// do nothing53}5455try {56props.load((InputStream)null);57failures++;58} catch (NullPointerException e) {59// do nothing60}6162try {63props.load((Reader)null);64failures++;65} catch (NullPointerException e) {66// do nothing67}6869if (failures != 0) {70throw new RuntimeException("LoadAndStoreNPE failed with "71+ failures + " errors!");72}73}74}757677