|
1 /* |
|
2 * Copyright (c) 2013, 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 */ |
|
31 |
|
32 import java.io.BufferedInputStream; |
|
33 import java.nio.file.Files; |
|
34 import java.nio.file.Path; |
|
35 import java.nio.file.Paths; |
|
36 |
|
37 import com.sun.tools.javac.util.Assert; |
|
38 import com.sun.tools.classfile.ClassFile; |
|
39 |
|
40 import static com.sun.tools.classfile.ConstantPool.CONSTANT_Utf8; |
|
41 import static com.sun.tools.classfile.ConstantPool.CONSTANT_Utf8_info; |
|
42 import static com.sun.tools.classfile.ConstantPool.CPInfo; |
|
43 |
|
44 public class EmptyUTF8ForInnerClassNameTest { |
|
45 |
|
46 public static void main(String[] args) throws Exception { |
|
47 new EmptyUTF8ForInnerClassNameTest().run(); |
|
48 } |
|
49 |
|
50 void run() throws Exception { |
|
51 checkClassFile(Paths.get(System.getProperty("test.classes"), |
|
52 this.getClass().getName() + "$1.class")); |
|
53 checkClassFile(Paths.get(System.getProperty("test.classes"), |
|
54 this.getClass().getName() + "$EnumPlusSwitch.class")); |
|
55 } |
|
56 |
|
57 void checkClassFile(final Path path) throws Exception { |
|
58 ClassFile classFile = ClassFile.read( |
|
59 new BufferedInputStream(Files.newInputStream(path))); |
|
60 for (CPInfo cpInfo : classFile.constant_pool.entries()) { |
|
61 if (cpInfo.getTag() == CONSTANT_Utf8) { |
|
62 CONSTANT_Utf8_info utf8Info = (CONSTANT_Utf8_info)cpInfo; |
|
63 Assert.check(utf8Info.value.length() > 0, |
|
64 "UTF8 with length 0 found at class " + classFile.getName()); |
|
65 } |
|
66 } |
|
67 } |
|
68 |
|
69 static class EnumPlusSwitch { |
|
70 enum E {E1} |
|
71 |
|
72 public int m (E e) { |
|
73 switch (e) { |
|
74 case E1: |
|
75 return 0; |
|
76 } |
|
77 return -1; |
|
78 } |
|
79 } |
|
80 |
|
81 } |