ConstDebugTest.java revision 2942:08092deced3f
1260684Skaiw/*
2260684Skaiw * Copyright (c) 2013, 2015, Oracle and/or its affiliates. All rights reserved.
3260684Skaiw * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4260684Skaiw *
5260684Skaiw * This code is free software; you can redistribute it and/or modify it
6260684Skaiw * under the terms of the GNU General Public License version 2 only, as
7260684Skaiw * published by the Free Software Foundation.
8260684Skaiw *
9260684Skaiw * This code is distributed in the hope that it will be useful, but WITHOUT
10260684Skaiw * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11260684Skaiw * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
12260684Skaiw * version 2 for more details (a copy is included in the LICENSE file that
13260684Skaiw * accompanied this code).
14260684Skaiw *
15260684Skaiw * You should have received a copy of the GNU General Public License version
16260684Skaiw * 2 along with this work; if not, write to the Free Software Foundation,
17260684Skaiw * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18260684Skaiw *
19260684Skaiw * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20260684Skaiw * or visit www.oracle.com if you need additional information or have any
21260684Skaiw * questions.
22260684Skaiw */
23260684Skaiw
24260684Skaiw/*
25260684Skaiw * @test
26260684Skaiw * @bug 4645152 4785453
27260684Skaiw * @summary javac compiler incorrectly inserts <clinit> when -g is specified
28260684Skaiw * @modules jdk.jdeps/com.sun.tools.classfile
29260684Skaiw * @run compile -g ConstDebugTest.java
30260684Skaiw * @run main ConstDebugTest
31260684Skaiw */
32260684Skaiwimport java.nio.file.Paths;
33260684Skaiwimport com.sun.tools.classfile.ClassFile;
34260684Skaiwimport com.sun.tools.classfile.Method;
35260684Skaiw
36260684Skaiwpublic class ConstDebugTest {
37260684Skaiw
38260684Skaiw    public static final long l = 12;
39260684Skaiw
40260684Skaiw    public static void main(String args[]) throws Exception {
41260684Skaiw        ClassFile classFile = ClassFile.read(Paths.get(System.getProperty("test.classes"),
42260684Skaiw                ConstDebugTest.class.getSimpleName() + ".class"));
43260684Skaiw        for (Method method: classFile.methods) {
44260684Skaiw            if (method.getName(classFile.constant_pool).equals("<clinit>")) {
45260684Skaiw                throw new AssertionError(
46260684Skaiw                    "javac should not create a <clinit> method for ConstDebugTest class");
47260684Skaiw            }
48260684Skaiw        }
49260684Skaiw    }
50260684Skaiw
51260684Skaiw}
52260684Skaiw