# HG changeset patch # User igerasim # Date 1412594635 -14400 # Node ID 31d2c1b835c82d964de531ea94d592fa930c5ef6 # Parent bc74fab441beef9b5bebdc13fb487d5ce91fbe01 8059563: (proxy) sun.misc.ProxyGenerator.generateProxyClass should create intermediate directories diff --git a/src/share/classes/sun/misc/ProxyGenerator.java b/src/share/classes/sun/misc/ProxyGenerator.java --- a/src/share/classes/sun/misc/ProxyGenerator.java +++ b/src/share/classes/sun/misc/ProxyGenerator.java @@ -27,11 +27,15 @@ import java.io.ByteArrayOutputStream; import java.io.DataOutputStream; +import java.io.File; import java.io.FileOutputStream; import java.io.IOException; import java.io.OutputStream; import java.lang.reflect.Array; import java.lang.reflect.Method; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; import java.util.ArrayList; import java.util.HashMap; import java.util.LinkedList; @@ -327,10 +331,16 @@ new java.security.PrivilegedAction() { public Void run() { try { - FileOutputStream file = - new FileOutputStream(dotToSlash(name) + ".class"); - file.write(classFile); - file.close(); + int i = name.lastIndexOf('.'); + Path path; + if (i > 0) { + Path dir = Paths.get(name.substring(0, i).replace('.', File.separatorChar)); + Files.createDirectories(dir); + path = dir.resolve(name.substring(i+1, name.length()) + ".class"); + } else { + path = Paths.get(name + ".class"); + } + Files.write(path, classFile); return null; } catch (IOException e) { throw new InternalError( diff --git a/test/java/lang/reflect/Proxy/InPackage.java b/test/java/lang/reflect/Proxy/InPackage.java new file mode 100644 --- /dev/null +++ b/test/java/lang/reflect/Proxy/InPackage.java @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/* @test + * @bug 8059563 + * @summary ProxyGenerator should create intermidiate directories + * for the generated class file + * @build InPackage + * @run main/othervm -Dsun.misc.ProxyGenerator.saveGeneratedFiles=true InPackage + */ + +import sun.misc.ProxyGenerator; + +public class InPackage { + public static void main(String[] args) throws Throwable { + ProxyGenerator.generateProxyClass("a.b.c.d", + new Class[] {Inf.class}); + } + + static interface Inf { + } +}