|
| 1 | +/* |
| 2 | + * Copyright (c) 2025, 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 | +import java.io.File; |
| 25 | +import java.io.IOException; |
| 26 | + |
| 27 | +import org.junit.jupiter.api.Test; |
| 28 | +import static org.junit.jupiter.api.Assertions.assertFalse; |
| 29 | +import static org.junit.jupiter.api.Assertions.assertTrue; |
| 30 | + |
| 31 | +/* @test |
| 32 | + * @bug 8354450 |
| 33 | + * @requires os.family == "windows" |
| 34 | + * @summary Verify behavior for file names with a trailing space |
| 35 | + * @run junit WinTrailingSpace |
| 36 | + */ |
| 37 | +public class WinTrailingSpace { |
| 38 | + private static final String FILENAME_NO_TRAILING_SPACE = "foobargus"; |
| 39 | + private static final String FILENAME_TRAILING_SPACE = "foobargus "; |
| 40 | + private static final String DIRNAME_TRAILING_SPACE = "foo \\bar\\gus"; |
| 41 | + |
| 42 | + @Test |
| 43 | + public void noTrailingSpace() throws IOException { |
| 44 | + File f = null; |
| 45 | + try { |
| 46 | + f = new File(".", FILENAME_NO_TRAILING_SPACE); |
| 47 | + f.delete(); |
| 48 | + f.createNewFile(); |
| 49 | + assertTrue(f.exists()); |
| 50 | + } finally { |
| 51 | + if (f != null) |
| 52 | + f.delete(); |
| 53 | + } |
| 54 | + } |
| 55 | + |
| 56 | + @Test |
| 57 | + public void trailingSpace() throws IOException { |
| 58 | + File f = null; |
| 59 | + try { |
| 60 | + f = new File(".", FILENAME_TRAILING_SPACE); |
| 61 | + f.delete(); |
| 62 | + f.createNewFile(); |
| 63 | + assertFalse(f.exists(), "Creation of " + f + " should have failed"); |
| 64 | + } catch (IOException expected) { |
| 65 | + } finally { |
| 66 | + if (f != null) |
| 67 | + f.delete(); |
| 68 | + } |
| 69 | + } |
| 70 | + |
| 71 | + @Test |
| 72 | + public void dirTrailingSpace() throws IOException { |
| 73 | + File f = null; |
| 74 | + try { |
| 75 | + f = new File(".", DIRNAME_TRAILING_SPACE); |
| 76 | + f.delete(); |
| 77 | + assertFalse(f.mkdirs(), "Creation of " + f + " should have failed"); |
| 78 | + } finally { |
| 79 | + if (f != null) |
| 80 | + f.delete(); |
| 81 | + } |
| 82 | + } |
| 83 | +} |
0 commit comments