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