blob: 485832c2a43f64fe635a8f2888b87b304ea67485 [file] [log] [blame]
J. Duke319a3b92007-12-01 00:00:00 +00001/*
2 * Copyright 2000 Sun Microsystems, Inc. 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
20 * CA 95054 USA or visit www.sun.com if you need additional information or
21 * have any questions.
22 */
23
24/*
25/* @test
26 * @bug 4359123
27 * @summary Test loading of classes with # in the path
28 */
29import java.io.*;
30
31public class EscapePath {
32
33 private static String testPath;
34
35 static {
36 testPath = System.getProperty("test.src");
37 if (testPath == null)
38 testPath = "";
39 else
40 testPath = testPath + File.separator;
41 }
42
43 public static void main(String[] args) throws Exception {
44 createTestDir();
45 copyClassFile();
46 invokeJava();
47 eraseTestDir();
48 }
49
50 private static void createTestDir() throws Exception {
51 File testDir = new File("a#b");
52 boolean result = testDir.mkdir();
53 }
54
55 private static void eraseTestDir() throws Exception {
56 File classFile = new File("a#b/Hello.class");
57 classFile.delete();
58 File testDir = new File("a#b");
59 testDir.delete();
60 }
61
62 private static void copyClassFile() throws Exception {
63 FileInputStream fis = new FileInputStream(testPath + "Hello.class");
64 FileOutputStream fos = new FileOutputStream("a#b/Hello.class");
65
66 int bytesRead;
67 byte buf[] = new byte[410];
68 do {
69 bytesRead = fis.read(buf);
70 if (bytesRead > 0)
71 fos.write(buf, 0, bytesRead);
72 } while (bytesRead != -1);
73 fis.close();
74 fos.flush();
75 fos.close();
76 }
77
78 private static void invokeJava() throws Exception {
79 String command = System.getProperty("java.home") +
80 File.separator + "bin" + File.separator +
81 "java -classpath " + "a#b/ Hello";
82 Process p = Runtime.getRuntime().exec(command);
83 p.waitFor();
84 int result = p.exitValue();
85 if (result != 0)
86 throw new RuntimeException("Path encoding failure.");
87 }
88}