1 /* 2 * Copyright (c) 2017, 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 * @summary JVM should be able to handle full path (directory path plus 27 * class name) or directory path longer than MAX_PATH on windows. 28 * @library /test/lib 29 * @modules java.base/jdk.internal.misc 30 * java.management 31 * @run main LongPath 32 */ 33 34 import java.nio.file.Path; 35 import java.nio.file.Paths; 36 import java.util.Arrays; 37 import jdk.test.lib.compiler.CompilerUtils; 38 import jdk.test.lib.process.ProcessTools; 39 import jdk.test.lib.process.OutputAnalyzer; 40 41 public class LongPath { 42 43 private static final int MAX_PATH = 260; 44 45 public static void main(String args[]) throws Exception { 46 Path sourceDir = Paths.get(System.getProperty("test.src"), "test-classes"); 47 Path classDir = Paths.get(System.getProperty("test.classes")); 48 Path destDir = classDir; 49 50 // create a sub-path so that the destDir length is almost MAX_PATH 51 // so that the full path (with the class name) will exceed MAX_PATH 52 int subDirLen = MAX_PATH - classDir.toString().length() - 2; 53 if (subDirLen > 0) { 54 char[] chars = new char[subDirLen]; 55 Arrays.fill(chars, 'x'); 56 String subPath = new String(chars); 57 destDir = Paths.get(System.getProperty("test.classes"), subPath); 58 } 59 60 CompilerUtils.compile(sourceDir, destDir); 61 62 String bootCP = "-Xbootclasspath/a:" + destDir.toString(); 63 ProcessBuilder pb = ProcessTools.createJavaProcessBuilder( 64 bootCP, "Hello"); 65 66 OutputAnalyzer output = new OutputAnalyzer(pb.start()); 67 output.shouldContain("Hello World") 68 .shouldHaveExitValue(0); 69 70 // increase the length of destDir to slightly over MAX_PATH 71 destDir = Paths.get(destDir.toString(), "xxxxx"); 72 CompilerUtils.compile(sourceDir, destDir); 73 74 bootCP = "-Xbootclasspath/a:" + destDir.toString(); 75 pb = ProcessTools.createJavaProcessBuilder( 76 bootCP, "Hello"); 77 78 output = new OutputAnalyzer(pb.start()); 79 output.shouldContain("Hello World") 80 .shouldHaveExitValue(0); 81 } 82 }