1 /* 2 * Copyright (c) 2018, 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 4218776 27 * @summary Test loading of properties files with blank lines 28 */ 29 30 package test.java.util.Properties; 31 32 import java.io.File; 33 import java.io.FileInputStream; 34 import java.io.FileOutputStream; 35 import java.io.IOException; 36 import java.io.InputStream; 37 import java.util.Properties; 38 39 /** 40 * This class tests to see if a properties object correctly handles blank 41 * lines in a properties file 42 */ 43 public class BlankLines { main(String []args)44 public static void main(String []args) 45 { 46 try { 47 // create test file 48 // Android-changed: create temp file. 49 // File file = new File("test.properties"); 50 File file = File.createTempFile("test", "properties"); 51 52 // write a single space to the test file 53 FileOutputStream fos = new FileOutputStream(file); 54 fos.write(' '); 55 fos.close(); 56 57 // test empty properties 58 Properties prop1 = new Properties(); 59 60 // now load the file we just created, into a 61 // properties object. 62 // the properties object should have no elements, 63 // but due to a bug, it has an empty key/value. 64 // key = "", value = "" 65 Properties prop2 = new Properties(); 66 InputStream is = new FileInputStream(file); 67 try { 68 prop2.load(is); 69 } finally { 70 is.close(); 71 } 72 if (!prop1.equals(prop2)) 73 throw new RuntimeException("Incorrect properties loading."); 74 75 // cleanup 76 file.delete(); 77 } 78 catch(IOException e) {} 79 } 80 } 81