1 /* 2 * Copyright (c) 2013, 2015, Oracle and/or its affiliates. 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. Oracle designates this 8 * particular file as subject to the "Classpath" exception as provided 9 * by Oracle in the LICENSE file that accompanied this code. 10 * 11 * This code is distributed in the hope that it will be useful, but WITHOUT 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 * version 2 for more details (a copy is included in the LICENSE file that 15 * accompanied this code). 16 * 17 * You should have received a copy of the GNU General Public License version 18 * 2 along with this work; if not, write to the Free Software Foundation, 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 * 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 * or visit www.oracle.com if you need additional information or have any 23 * questions. 24 */ 25 26 /* 27 * @test 28 * @bug 8011181 29 * @summary javac, empty UTF8 entry generated for inner class 30 * @modules jdk.compiler/com.sun.tools.classfile 31 * jdk.compiler/com.sun.tools.javac.util 32 */ 33 34 import java.io.BufferedInputStream; 35 import java.nio.file.Files; 36 import java.nio.file.Path; 37 import java.nio.file.Paths; 38 39 import com.sun.tools.javac.util.Assert; 40 import com.sun.tools.classfile.ClassFile; 41 42 import static com.sun.tools.classfile.ConstantPool.CONSTANT_Utf8; 43 import static com.sun.tools.classfile.ConstantPool.CONSTANT_Utf8_info; 44 import static com.sun.tools.classfile.ConstantPool.CPInfo; 45 46 public class EmptyUTF8ForInnerClassNameTest { 47 48 public static void main(String[] args) throws Exception { 49 new EmptyUTF8ForInnerClassNameTest().run(); 50 } 51 52 void run() throws Exception { 53 checkClassFile(Paths.get(System.getProperty("test.classes"), 54 this.getClass().getName() + "$1.class")); 55 checkClassFile(Paths.get(System.getProperty("test.classes"), 56 this.getClass().getName() + "$EnumPlusSwitch.class")); 57 } 58 59 void checkClassFile(final Path path) throws Exception { 60 ClassFile classFile = ClassFile.read( 61 new BufferedInputStream(Files.newInputStream(path))); 62 for (CPInfo cpInfo : classFile.constant_pool.entries()) { 63 if (cpInfo.getTag() == CONSTANT_Utf8) { 64 CONSTANT_Utf8_info utf8Info = (CONSTANT_Utf8_info)cpInfo; 65 Assert.check(utf8Info.value.length() > 0, 66 "UTF8 with length 0 found at class " + classFile.getName()); 67 } 68 } 69 } 70 71 static class EnumPlusSwitch { 72 enum E {E1} 73 74 public int m (E e) { 75 switch (e) { 76 case E1: 77 return 0; 78 } 79 return -1; 80 } 81 } 82 83 }