Wed, 17 Apr 2013 11:11:33 +0100
8011181: javac, empty UTF8 entry generated for inner class
Reviewed-by: jjg
1.1 --- a/src/share/classes/com/sun/tools/javac/jvm/ClassWriter.java Mon Apr 15 14:18:30 2013 +0100 1.2 +++ b/src/share/classes/com/sun/tools/javac/jvm/ClassWriter.java Wed Apr 17 11:11:33 2013 +0100 1.3 @@ -1016,7 +1016,8 @@ 1.4 // log.errWriter.println("enter inner " + c);//DEBUG 1.5 enterInner(c.owner.enclClass()); 1.6 pool.put(c); 1.7 - pool.put(c.name); 1.8 + if (c.name != names.empty) 1.9 + pool.put(c.name); 1.10 if (innerClasses == null) { 1.11 innerClasses = new HashSet<ClassSymbol>(); 1.12 innerClassesQueue = new ListBuffer<ClassSymbol>();
2.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 2.2 +++ b/test/tools/javac/T8011181/EmptyUTF8ForInnerClassNameTest.java Wed Apr 17 11:11:33 2013 +0100 2.3 @@ -0,0 +1,81 @@ 2.4 +/* 2.5 + * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. 2.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 2.7 + * 2.8 + * This code is free software; you can redistribute it and/or modify it 2.9 + * under the terms of the GNU General Public License version 2 only, as 2.10 + * published by the Free Software Foundation. Oracle designates this 2.11 + * particular file as subject to the "Classpath" exception as provided 2.12 + * by Oracle in the LICENSE file that accompanied this code. 2.13 + * 2.14 + * This code is distributed in the hope that it will be useful, but WITHOUT 2.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 2.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 2.17 + * version 2 for more details (a copy is included in the LICENSE file that 2.18 + * accompanied this code). 2.19 + * 2.20 + * You should have received a copy of the GNU General Public License version 2.21 + * 2 along with this work; if not, write to the Free Software Foundation, 2.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 2.23 + * 2.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 2.25 + * or visit www.oracle.com if you need additional information or have any 2.26 + * questions. 2.27 + */ 2.28 + 2.29 +/* 2.30 + * @test 2.31 + * @bug 8011181 2.32 + * @summary javac, empty UTF8 entry generated for inner class 2.33 + */ 2.34 + 2.35 +import java.io.BufferedInputStream; 2.36 +import java.nio.file.Files; 2.37 +import java.nio.file.Path; 2.38 +import java.nio.file.Paths; 2.39 + 2.40 +import com.sun.tools.javac.util.Assert; 2.41 +import com.sun.tools.classfile.ClassFile; 2.42 + 2.43 +import static com.sun.tools.classfile.ConstantPool.CONSTANT_Utf8; 2.44 +import static com.sun.tools.classfile.ConstantPool.CONSTANT_Utf8_info; 2.45 +import static com.sun.tools.classfile.ConstantPool.CPInfo; 2.46 + 2.47 +public class EmptyUTF8ForInnerClassNameTest { 2.48 + 2.49 + public static void main(String[] args) throws Exception { 2.50 + new EmptyUTF8ForInnerClassNameTest().run(); 2.51 + } 2.52 + 2.53 + void run() throws Exception { 2.54 + checkClassFile(Paths.get(System.getProperty("test.classes"), 2.55 + this.getClass().getName() + "$1.class")); 2.56 + checkClassFile(Paths.get(System.getProperty("test.classes"), 2.57 + this.getClass().getName() + "$EnumPlusSwitch.class")); 2.58 + } 2.59 + 2.60 + void checkClassFile(final Path path) throws Exception { 2.61 + ClassFile classFile = ClassFile.read( 2.62 + new BufferedInputStream(Files.newInputStream(path))); 2.63 + for (CPInfo cpInfo : classFile.constant_pool.entries()) { 2.64 + if (cpInfo.getTag() == CONSTANT_Utf8) { 2.65 + CONSTANT_Utf8_info utf8Info = (CONSTANT_Utf8_info)cpInfo; 2.66 + Assert.check(utf8Info.value.length() > 0, 2.67 + "UTF8 with length 0 found at class " + classFile.getName()); 2.68 + } 2.69 + } 2.70 + } 2.71 + 2.72 + static class EnumPlusSwitch { 2.73 + enum E {E1} 2.74 + 2.75 + public int m (E e) { 2.76 + switch (e) { 2.77 + case E1: 2.78 + return 0; 2.79 + } 2.80 + return -1; 2.81 + } 2.82 + } 2.83 + 2.84 +}