Path: blob/master/test/jdk/javax/security/auth/callback/Mutability.java
41153 views
/*1* Copyright (c) 2020, 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 824233026* @library /test/lib27* @summary Arrays should be cloned in several JAAS Callback classes28*/2930import javax.security.auth.callback.ChoiceCallback;31import javax.security.auth.callback.ConfirmationCallback;3233import static jdk.test.lib.Asserts.assertEQ;3435public class Mutability {36public static void main(String[] args) {3738// #1. ConfirmationCallback.new(3)39String[] i11 = {"1", "2"};40ConfirmationCallback c1 = new ConfirmationCallback(41ConfirmationCallback.INFORMATION,42i11,430);4445// Modify argument of constructor46i11[0] = "x";47String[] o11 = c1.getOptions();48assertEQ(o11[0], "1");49// Modify output50o11[0] = "y";51String[] o12 = c1.getOptions();52assertEQ(o12[0], "1");5354// #2. ConfirmationCallback.new(4)55String[] i21 = {"1", "2"};56ConfirmationCallback c2 = new ConfirmationCallback(57"Hi",58ConfirmationCallback.INFORMATION,59i21,600);6162// Modify argument of constructor63i21[0] = "x";64assertEQ(c2.getOptions()[0], "1");6566// #3. ChoiceCallback.new67String[] i31 = {"1", "2"};68ChoiceCallback c3 = new ChoiceCallback(69"Hi",70i31,710,72true);7374// Modify argument of constructor75i31[0] = "x";76String[] o31 = c3.getChoices();77assertEQ(o31[0], "1");78// Modify output of getChoices79o31[0] = "y";80String[] o32 = c3.getChoices();81assertEQ(o32[0], "1");8283int[] s31 = {0, 1};84c3.setSelectedIndexes(s31);8586// Modify argument of setSelectedIndexes87s31[0] = 1;88int[] s32 = c3.getSelectedIndexes();89assertEQ(s32[0], 0);90// Modify output of getSelectedIndexes91s32[1] = 0;92int[] s33 = c3.getSelectedIndexes();93assertEQ(s33[1], 1);94}95}969798