Path: blob/master/test/jdk/java/security/BasicPermission/SerialVersion.java
41149 views
/*1* Copyright (c) 2001, 2011, 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 4502729 705491826* @summary BasicPermissionCollection serial version UID incorrect27*/2829import java.security.*;30import java.io.*;3132public class SerialVersion {3334public static void main(String[] args) throws Exception {35String dir = System.getProperty("test.src");36File sFile = new File (dir,"SerialVersion.1.2.1");37// read in a 1.2.1 BasicPermissionCollection38try (FileInputStream fis = new FileInputStream(sFile);39ObjectInputStream ois = new ObjectInputStream(fis)) {40PermissionCollection pc = (PermissionCollection)ois.readObject();41System.out.println("1.2.1 collection = " + pc);42}4344// read in a 1.3.1 BasicPermissionCollection45sFile = new File (dir,"SerialVersion.1.3.1");4647try (FileInputStream fis = new FileInputStream(sFile);48ObjectInputStream ois = new ObjectInputStream(fis)) {49PermissionCollection pc = (PermissionCollection)ois.readObject();50System.out.println("1.3.1 collection = " + pc);51}5253// read in a 1.4 BasicPermissionCollection54sFile = new File (dir,"SerialVersion.1.4");55try (FileInputStream fis = new FileInputStream(sFile);56ObjectInputStream ois = new ObjectInputStream(fis)) {57PermissionCollection pc = (PermissionCollection)ois.readObject();58System.out.println("1.4 collection = " + pc);59}6061// write out current BasicPermissionCollection62MyPermission mp = new MyPermission("SerialVersionTest");63PermissionCollection bpc = mp.newPermissionCollection();64sFile = new File (dir,"SerialVersion.current");65try (FileOutputStream fos = new FileOutputStream("SerialVersion.current");66ObjectOutputStream oos = new ObjectOutputStream(fos)) {67oos.writeObject(bpc);68}6970// read in current BasicPermissionCollection71try (FileInputStream fis = new FileInputStream("SerialVersion.current");72ObjectInputStream ois = new ObjectInputStream(fis)) {73PermissionCollection pc = (PermissionCollection)ois.readObject();74System.out.println("current collection = " + pc);75}76}77}7879class MyPermission extends BasicPermission {80public MyPermission(String name) {81super(name);82}83}848586