test/jdk/java/io/File/MaxPath.java
author dholmes
Wed, 06 Nov 2019 21:18:42 -0500
changeset 58956 9a0a5e70eeb2
parent 47216 71c04702a3d5
permissions -rw-r--r--
8233454: Test fails with assert(!is_init_completed(), "should only happen during init") after JDK-8229516 Reviewed-by: jiefu, dcubed
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
785
36c29b2692f1 6481955: Uncanonicalized absolute filepath with length 248-260 no longer works (win)
sherman
parents:
diff changeset
     1
/*
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 785
diff changeset
     2
 * Copyright (c) 2008, Oracle and/or its affiliates. All rights reserved.
785
36c29b2692f1 6481955: Uncanonicalized absolute filepath with length 248-260 no longer works (win)
sherman
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
36c29b2692f1 6481955: Uncanonicalized absolute filepath with length 248-260 no longer works (win)
sherman
parents:
diff changeset
     4
 *
36c29b2692f1 6481955: Uncanonicalized absolute filepath with length 248-260 no longer works (win)
sherman
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
36c29b2692f1 6481955: Uncanonicalized absolute filepath with length 248-260 no longer works (win)
sherman
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
36c29b2692f1 6481955: Uncanonicalized absolute filepath with length 248-260 no longer works (win)
sherman
parents:
diff changeset
     7
 * published by the Free Software Foundation.
36c29b2692f1 6481955: Uncanonicalized absolute filepath with length 248-260 no longer works (win)
sherman
parents:
diff changeset
     8
 *
36c29b2692f1 6481955: Uncanonicalized absolute filepath with length 248-260 no longer works (win)
sherman
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
36c29b2692f1 6481955: Uncanonicalized absolute filepath with length 248-260 no longer works (win)
sherman
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
36c29b2692f1 6481955: Uncanonicalized absolute filepath with length 248-260 no longer works (win)
sherman
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
36c29b2692f1 6481955: Uncanonicalized absolute filepath with length 248-260 no longer works (win)
sherman
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
36c29b2692f1 6481955: Uncanonicalized absolute filepath with length 248-260 no longer works (win)
sherman
parents:
diff changeset
    13
 * accompanied this code).
36c29b2692f1 6481955: Uncanonicalized absolute filepath with length 248-260 no longer works (win)
sherman
parents:
diff changeset
    14
 *
36c29b2692f1 6481955: Uncanonicalized absolute filepath with length 248-260 no longer works (win)
sherman
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
36c29b2692f1 6481955: Uncanonicalized absolute filepath with length 248-260 no longer works (win)
sherman
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
36c29b2692f1 6481955: Uncanonicalized absolute filepath with length 248-260 no longer works (win)
sherman
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
36c29b2692f1 6481955: Uncanonicalized absolute filepath with length 248-260 no longer works (win)
sherman
parents:
diff changeset
    18
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 785
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 785
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 785
diff changeset
    21
 * questions.
785
36c29b2692f1 6481955: Uncanonicalized absolute filepath with length 248-260 no longer works (win)
sherman
parents:
diff changeset
    22
 */
36c29b2692f1 6481955: Uncanonicalized absolute filepath with length 248-260 no longer works (win)
sherman
parents:
diff changeset
    23
36c29b2692f1 6481955: Uncanonicalized absolute filepath with length 248-260 no longer works (win)
sherman
parents:
diff changeset
    24
/* @test
36c29b2692f1 6481955: Uncanonicalized absolute filepath with length 248-260 no longer works (win)
sherman
parents:
diff changeset
    25
   @bug 6481955
36c29b2692f1 6481955: Uncanonicalized absolute filepath with length 248-260 no longer works (win)
sherman
parents:
diff changeset
    26
   @summary Path length less than MAX_PATH (260) works on Windows
36c29b2692f1 6481955: Uncanonicalized absolute filepath with length 248-260 no longer works (win)
sherman
parents:
diff changeset
    27
 */
36c29b2692f1 6481955: Uncanonicalized absolute filepath with length 248-260 no longer works (win)
sherman
parents:
diff changeset
    28
36c29b2692f1 6481955: Uncanonicalized absolute filepath with length 248-260 no longer works (win)
sherman
parents:
diff changeset
    29
import java.io.*;
36c29b2692f1 6481955: Uncanonicalized absolute filepath with length 248-260 no longer works (win)
sherman
parents:
diff changeset
    30
36c29b2692f1 6481955: Uncanonicalized absolute filepath with length 248-260 no longer works (win)
sherman
parents:
diff changeset
    31
public class MaxPath {
36c29b2692f1 6481955: Uncanonicalized absolute filepath with length 248-260 no longer works (win)
sherman
parents:
diff changeset
    32
    public static void main(String[] args) throws Exception {
36c29b2692f1 6481955: Uncanonicalized absolute filepath with length 248-260 no longer works (win)
sherman
parents:
diff changeset
    33
        String osName = System.getProperty("os.name");
36c29b2692f1 6481955: Uncanonicalized absolute filepath with length 248-260 no longer works (win)
sherman
parents:
diff changeset
    34
        if (!osName.startsWith("Windows")) {
36c29b2692f1 6481955: Uncanonicalized absolute filepath with length 248-260 no longer works (win)
sherman
parents:
diff changeset
    35
            return;
36c29b2692f1 6481955: Uncanonicalized absolute filepath with length 248-260 no longer works (win)
sherman
parents:
diff changeset
    36
        }
36c29b2692f1 6481955: Uncanonicalized absolute filepath with length 248-260 no longer works (win)
sherman
parents:
diff changeset
    37
        int MAX_PATH = 260;
36c29b2692f1 6481955: Uncanonicalized absolute filepath with length 248-260 no longer works (win)
sherman
parents:
diff changeset
    38
        String dir = new File(".").getAbsolutePath() + "\\";
36c29b2692f1 6481955: Uncanonicalized absolute filepath with length 248-260 no longer works (win)
sherman
parents:
diff changeset
    39
        String padding = "1234567890123456789012345678901234567890012345678900123456789001234567890012345678900123456789001234567890012345678900123456789001234567890012345678900123456789001234567890012345678900123456789001234567890012345678900123456789001234567890012345678900123456789001234567890012345678900123456789001234567890012345678900123456789001234567890";
36c29b2692f1 6481955: Uncanonicalized absolute filepath with length 248-260 no longer works (win)
sherman
parents:
diff changeset
    40
        for (int i = 240 - dir.length(); i < MAX_PATH - dir.length(); i++) {
36c29b2692f1 6481955: Uncanonicalized absolute filepath with length 248-260 no longer works (win)
sherman
parents:
diff changeset
    41
            String longname = dir + padding.substring(0, i);
36c29b2692f1 6481955: Uncanonicalized absolute filepath with length 248-260 no longer works (win)
sherman
parents:
diff changeset
    42
            try {
36c29b2692f1 6481955: Uncanonicalized absolute filepath with length 248-260 no longer works (win)
sherman
parents:
diff changeset
    43
                File f = new File(longname);
36c29b2692f1 6481955: Uncanonicalized absolute filepath with length 248-260 no longer works (win)
sherman
parents:
diff changeset
    44
                if (f.createNewFile()) {
36c29b2692f1 6481955: Uncanonicalized absolute filepath with length 248-260 no longer works (win)
sherman
parents:
diff changeset
    45
                    if (!f.exists() || !f.canRead()) {
36c29b2692f1 6481955: Uncanonicalized absolute filepath with length 248-260 no longer works (win)
sherman
parents:
diff changeset
    46
                        throw new RuntimeException("Failed at length: " + longname.length());
36c29b2692f1 6481955: Uncanonicalized absolute filepath with length 248-260 no longer works (win)
sherman
parents:
diff changeset
    47
                    }
36c29b2692f1 6481955: Uncanonicalized absolute filepath with length 248-260 no longer works (win)
sherman
parents:
diff changeset
    48
                    f.delete();
36c29b2692f1 6481955: Uncanonicalized absolute filepath with length 248-260 no longer works (win)
sherman
parents:
diff changeset
    49
                }
36c29b2692f1 6481955: Uncanonicalized absolute filepath with length 248-260 no longer works (win)
sherman
parents:
diff changeset
    50
            } catch (IOException e) {
36c29b2692f1 6481955: Uncanonicalized absolute filepath with length 248-260 no longer works (win)
sherman
parents:
diff changeset
    51
                System.out.println("Failed at length: " + longname.length());
36c29b2692f1 6481955: Uncanonicalized absolute filepath with length 248-260 no longer works (win)
sherman
parents:
diff changeset
    52
                throw e;
36c29b2692f1 6481955: Uncanonicalized absolute filepath with length 248-260 no longer works (win)
sherman
parents:
diff changeset
    53
            }
36c29b2692f1 6481955: Uncanonicalized absolute filepath with length 248-260 no longer works (win)
sherman
parents:
diff changeset
    54
        }
36c29b2692f1 6481955: Uncanonicalized absolute filepath with length 248-260 no longer works (win)
sherman
parents:
diff changeset
    55
    }
36c29b2692f1 6481955: Uncanonicalized absolute filepath with length 248-260 no longer works (win)
sherman
parents:
diff changeset
    56
}