Path: blob/master/test/jdk/java/security/Security/Nulls.java
41149 views
/*1* Copyright (c) 2003, 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*/2223/**24* @test25* @bug 496020826* @summary verify behavior passing null to various java.security.Security methods27* @author Andreas Sterbenz28*/2930import java.util.*;3132import java.security.*;3334public class Nulls {3536public static void main(String[] args) throws Exception {37try {38Security.addProvider(null);39throw new Exception();40} catch (NullPointerException e) {41System.out.println("addProvider(null): " + e);42}43if (Security.getAlgorithms(null).isEmpty() == false) {44throw new Exception();45}46try {47Security.getProperty(null);48throw new Exception();49} catch (NullPointerException e) {50System.out.println("getProperty(null): " + e);51}52if (Security.getProvider(null) != null) {53throw new Exception();54}55try {56Security.getProviders((Map)null);57throw new Exception();58} catch (NullPointerException e) {59System.out.println("getProviders((Map)null): " + e);60}61try {62Security.getProviders((String)null);63throw new Exception();64} catch (NullPointerException e) {65System.out.println("getProviders((String)null): " + e);66}67try {68Security.insertProviderAt(null, 1);69throw new Exception();70} catch (NullPointerException e) {71System.out.println("insertProviderAt(null): " + e);72}73Security.removeProvider(null);74try {75Security.setProperty("foo", null);76throw new Exception();77} catch (NullPointerException e) {78System.out.println("setProperty(\"foo\", null): " + e);79}80try {81Security.setProperty(null, "foo");82throw new Exception();83} catch (NullPointerException e) {84System.out.println("setProperty(null, \"foo\"): " + e);85}86try {87Security.setProperty(null, null);88throw new Exception();89} catch (NullPointerException e) {90System.out.println("setProperty(null, null): " + e);91}92if (Security.getAlgorithmProperty(null, null) != null) {93throw new Exception();94}95}9697}9899100