test/tools/javac/api/T6483788.java

Mon, 06 Sep 2010 12:55:09 -0700

author
jjg
date
Mon, 06 Sep 2010 12:55:09 -0700
changeset 672
ea54372637a5
parent 554
9d9f26857129
child 2525
2eb010b6cb22
permissions
-rw-r--r--

6930507: Symbols for anonymous and local classes made too late for use by java tree API
Reviewed-by: mcimadamore

jjg@400 1 /*
ohair@554 2 * Copyright (c) 2009, Oracle and/or its affiliates. All rights reserved.
jjg@400 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
jjg@400 4 *
jjg@400 5 * This code is free software; you can redistribute it and/or modify it
jjg@400 6 * under the terms of the GNU General Public License version 2 only, as
jjg@400 7 * published by the Free Software Foundation.
jjg@400 8 *
jjg@400 9 * This code is distributed in the hope that it will be useful, but WITHOUT
jjg@400 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
jjg@400 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
jjg@400 12 * version 2 for more details (a copy is included in the LICENSE file that
jjg@400 13 * accompanied this code).
jjg@400 14 *
jjg@400 15 * You should have received a copy of the GNU General Public License version
jjg@400 16 * 2 along with this work; if not, write to the Free Software Foundation,
jjg@400 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
jjg@400 18 *
ohair@554 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
ohair@554 20 * or visit www.oracle.com if you need additional information or have any
ohair@554 21 * questions.
jjg@400 22 */
jjg@400 23
jjg@400 24 /*
jjg@400 25 * @test
jjg@400 26 * @bug 6483788
jjg@400 27 * @summary DefaultFileManager.ZipFileObject.toUri() fails to escape space characters
jjg@400 28 */
jjg@400 29
jjg@400 30 import java.io.*;
jjg@400 31 import java.net.*;
jjg@400 32 import java.util.Collections;
jjg@400 33 import java.util.jar.*;
jjg@400 34 import java.util.zip.*;
jjg@400 35 import javax.tools.*;
jjg@400 36
jjg@400 37 public class T6483788 {
jjg@400 38 public static void main(String[] args) throws Exception {
jjg@400 39 new T6483788().run();
jjg@400 40 }
jjg@400 41
jjg@400 42 void run() throws Exception {
jjg@400 43 File jar = createJar();
jjg@400 44 JavaCompiler c = ToolProvider.getSystemJavaCompiler();
jjg@400 45 StandardJavaFileManager fm = c.getStandardFileManager(null, null, null);
jjg@400 46 fm.setLocation(StandardLocation.CLASS_PATH, Collections.singleton(jar));
jjg@400 47 JavaFileObject fo = fm.getJavaFileForInput(StandardLocation.CLASS_PATH, "dummy", JavaFileObject.Kind.CLASS);
jjg@400 48 System.err.println("file: " + fo);
jjg@400 49 URI uri = fo.toUri();
jjg@400 50 System.err.println("uri: " + uri);
jjg@400 51 if (uri.toString().contains(" "))
jjg@400 52 throw new Exception("unexpected space character found");
jjg@400 53 }
jjg@400 54
jjg@400 55 File createJar() throws IOException {
jjg@400 56 byte[] dummy_data = new byte[10];
jjg@400 57 File f = new File("a b.jar");
jjg@400 58 OutputStream out = new FileOutputStream(f);
jjg@400 59 try {
jjg@400 60 JarOutputStream jar = new JarOutputStream(out);
jjg@400 61 jar.putNextEntry(new ZipEntry("dummy.class"));
jjg@400 62 jar.write(dummy_data);
jjg@400 63 jar.close();
jjg@400 64 } finally {
jjg@400 65 out.close();
jjg@400 66 }
jjg@400 67 return f;
jjg@400 68 }
jjg@400 69 }
jjg@400 70

mercurial