jjg@400: /* ohair@554: * Copyright (c) 2009, Oracle and/or its affiliates. All rights reserved. jjg@400: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. jjg@400: * jjg@400: * This code is free software; you can redistribute it and/or modify it jjg@400: * under the terms of the GNU General Public License version 2 only, as jjg@400: * published by the Free Software Foundation. jjg@400: * jjg@400: * This code is distributed in the hope that it will be useful, but WITHOUT jjg@400: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or jjg@400: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License jjg@400: * version 2 for more details (a copy is included in the LICENSE file that jjg@400: * accompanied this code). jjg@400: * jjg@400: * You should have received a copy of the GNU General Public License version jjg@400: * 2 along with this work; if not, write to the Free Software Foundation, jjg@400: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. jjg@400: * ohair@554: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA ohair@554: * or visit www.oracle.com if you need additional information or have any ohair@554: * questions. jjg@400: */ jjg@400: jjg@400: /* jjg@400: * @test jjg@400: * @bug 6483788 jjg@400: * @summary DefaultFileManager.ZipFileObject.toUri() fails to escape space characters jjg@400: */ jjg@400: jjg@400: import java.io.*; jjg@400: import java.net.*; jjg@400: import java.util.Collections; jjg@400: import java.util.jar.*; jjg@400: import java.util.zip.*; jjg@400: import javax.tools.*; jjg@400: jjg@400: public class T6483788 { jjg@400: public static void main(String[] args) throws Exception { jjg@400: new T6483788().run(); jjg@400: } jjg@400: jjg@400: void run() throws Exception { jjg@400: File jar = createJar(); jjg@400: JavaCompiler c = ToolProvider.getSystemJavaCompiler(); jjg@400: StandardJavaFileManager fm = c.getStandardFileManager(null, null, null); jjg@400: fm.setLocation(StandardLocation.CLASS_PATH, Collections.singleton(jar)); jjg@400: JavaFileObject fo = fm.getJavaFileForInput(StandardLocation.CLASS_PATH, "dummy", JavaFileObject.Kind.CLASS); jjg@400: System.err.println("file: " + fo); jjg@400: URI uri = fo.toUri(); jjg@400: System.err.println("uri: " + uri); jjg@400: if (uri.toString().contains(" ")) jjg@400: throw new Exception("unexpected space character found"); jjg@400: } jjg@400: jjg@400: File createJar() throws IOException { jjg@400: byte[] dummy_data = new byte[10]; jjg@400: File f = new File("a b.jar"); jjg@400: OutputStream out = new FileOutputStream(f); jjg@400: try { jjg@400: JarOutputStream jar = new JarOutputStream(out); jjg@400: jar.putNextEntry(new ZipEntry("dummy.class")); jjg@400: jar.write(dummy_data); jjg@400: jar.close(); jjg@400: } finally { jjg@400: out.close(); jjg@400: } jjg@400: return f; jjg@400: } jjg@400: } jjg@400: