384N/A/*
2362N/A * Copyright (c) 2008, Oracle and/or its affiliates. All rights reserved.
384N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
384N/A *
384N/A * This code is free software; you can redistribute it and/or modify it
384N/A * under the terms of the GNU General Public License version 2 only, as
384N/A * published by the Free Software Foundation.
384N/A *
384N/A * This code is distributed in the hope that it will be useful, but WITHOUT
384N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
384N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
384N/A * version 2 for more details (a copy is included in the LICENSE file that
384N/A * accompanied this code).
384N/A *
384N/A * You should have received a copy of the GNU General Public License version
384N/A * 2 along with this work; if not, write to the Free Software Foundation,
384N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
384N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
384N/A */
384N/A
384N/A/* @test
384N/A @bug 6481955
384N/A @summary Path length less than MAX_PATH (260) works on Windows
384N/A */
384N/A
384N/Aimport java.io.*;
384N/A
384N/Apublic class MaxPath {
384N/A public static void main(String[] args) throws Exception {
384N/A String osName = System.getProperty("os.name");
384N/A if (!osName.startsWith("Windows")) {
384N/A return;
384N/A }
384N/A int MAX_PATH = 260;
384N/A String dir = new File(".").getAbsolutePath() + "\\";
384N/A String padding = "1234567890123456789012345678901234567890012345678900123456789001234567890012345678900123456789001234567890012345678900123456789001234567890012345678900123456789001234567890012345678900123456789001234567890012345678900123456789001234567890012345678900123456789001234567890012345678900123456789001234567890012345678900123456789001234567890";
384N/A for (int i = 240 - dir.length(); i < MAX_PATH - dir.length(); i++) {
384N/A String longname = dir + padding.substring(0, i);
384N/A try {
384N/A File f = new File(longname);
384N/A if (f.createNewFile()) {
384N/A if (!f.exists() || !f.canRead()) {
384N/A throw new RuntimeException("Failed at length: " + longname.length());
384N/A }
384N/A f.delete();
384N/A }
384N/A } catch (IOException e) {
384N/A System.out.println("Failed at length: " + longname.length());
384N/A throw e;
384N/A }
384N/A }
384N/A }
384N/A}