1 /* 2 * Copyright (c) 2009, 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 */ 23 24 25 /* @test 26 @bug 6178148 27 @summary check if wrong exception gets thrown if one of the child 28 nodes is readonly on underlying filesystem when node is 29 being removed. 30 */ 31 32 import java.io.*; 33 import java.util.prefs.*; 34 35 public class RemoveReadOnlyNode { 36 public static void main(String[] args) throws Exception { 37 String osName = System.getProperty("os.name"); 38 if (osName.startsWith("Windows")) 39 return; 40 Preferences root = Preferences.userRoot(); 41 Preferences node1 = root.node("node1"); 42 Preferences node1A = node1.node("node1A"); 43 Preferences node1B = node1.node("node1B"); 44 node1B.put("mykey", "myvalue"); 45 node1.flush(); 46 String node1BDirName = System.getProperty("user.home") 47 + "/.java/.userPrefs" 48 + "/node1/node1B"; 49 File node1BDir = new File(node1BDirName); 50 node1BDir.setReadOnly(); 51 try { 52 node1.removeNode(); 53 } 54 catch (BackingStoreException ex) { 55 //expected exception 56 } finally { 57 Runtime.getRuntime().exec("chmod 755 " + node1BDirName).waitFor(); 58 try { 59 node1.removeNode(); 60 } catch (Exception e) {} 61 } 62 } 63 }