langtools/test/tools/javac/T8011181/EmptyUTF8ForInnerClassNameTest.java
author alundblad
Wed, 26 Aug 2015 09:02:02 +0200
changeset 32337 c9d3ab9f601c
parent 30846 2b3f379840f0
permissions -rw-r--r--
8133671: langtools tests have bad license Summary: Dropped classpath exception from copyright notice in tests. Reviewed-by: jjg
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
16976
aecde736ef83 8011181: javac, empty UTF8 entry generated for inner class
vromero
parents:
diff changeset
     1
/*
30730
d3ce7619db2c 8076543: Add @modules as needed to the langtools tests
akulyakh
parents: 16976
diff changeset
     2
 * Copyright (c) 2013, 2015, Oracle and/or its affiliates. All rights reserved.
16976
aecde736ef83 8011181: javac, empty UTF8 entry generated for inner class
vromero
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
aecde736ef83 8011181: javac, empty UTF8 entry generated for inner class
vromero
parents:
diff changeset
     4
 *
aecde736ef83 8011181: javac, empty UTF8 entry generated for inner class
vromero
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
aecde736ef83 8011181: javac, empty UTF8 entry generated for inner class
vromero
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
32337
c9d3ab9f601c 8133671: langtools tests have bad license
alundblad
parents: 30846
diff changeset
     7
 * published by the Free Software Foundation.
16976
aecde736ef83 8011181: javac, empty UTF8 entry generated for inner class
vromero
parents:
diff changeset
     8
 *
aecde736ef83 8011181: javac, empty UTF8 entry generated for inner class
vromero
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
aecde736ef83 8011181: javac, empty UTF8 entry generated for inner class
vromero
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
aecde736ef83 8011181: javac, empty UTF8 entry generated for inner class
vromero
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
aecde736ef83 8011181: javac, empty UTF8 entry generated for inner class
vromero
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
aecde736ef83 8011181: javac, empty UTF8 entry generated for inner class
vromero
parents:
diff changeset
    13
 * accompanied this code).
aecde736ef83 8011181: javac, empty UTF8 entry generated for inner class
vromero
parents:
diff changeset
    14
 *
aecde736ef83 8011181: javac, empty UTF8 entry generated for inner class
vromero
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
aecde736ef83 8011181: javac, empty UTF8 entry generated for inner class
vromero
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
aecde736ef83 8011181: javac, empty UTF8 entry generated for inner class
vromero
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
aecde736ef83 8011181: javac, empty UTF8 entry generated for inner class
vromero
parents:
diff changeset
    18
 *
aecde736ef83 8011181: javac, empty UTF8 entry generated for inner class
vromero
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
aecde736ef83 8011181: javac, empty UTF8 entry generated for inner class
vromero
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
aecde736ef83 8011181: javac, empty UTF8 entry generated for inner class
vromero
parents:
diff changeset
    21
 * questions.
aecde736ef83 8011181: javac, empty UTF8 entry generated for inner class
vromero
parents:
diff changeset
    22
 */
aecde736ef83 8011181: javac, empty UTF8 entry generated for inner class
vromero
parents:
diff changeset
    23
aecde736ef83 8011181: javac, empty UTF8 entry generated for inner class
vromero
parents:
diff changeset
    24
/*
aecde736ef83 8011181: javac, empty UTF8 entry generated for inner class
vromero
parents:
diff changeset
    25
 * @test
aecde736ef83 8011181: javac, empty UTF8 entry generated for inner class
vromero
parents:
diff changeset
    26
 * @bug 8011181
aecde736ef83 8011181: javac, empty UTF8 entry generated for inner class
vromero
parents:
diff changeset
    27
 * @summary javac, empty UTF8 entry generated for inner class
30846
2b3f379840f0 8074432: Move jdeps and javap to jdk.jdeps module
mchung
parents: 30730
diff changeset
    28
 * @modules jdk.jdeps/com.sun.tools.classfile
30730
d3ce7619db2c 8076543: Add @modules as needed to the langtools tests
akulyakh
parents: 16976
diff changeset
    29
 *          jdk.compiler/com.sun.tools.javac.util
16976
aecde736ef83 8011181: javac, empty UTF8 entry generated for inner class
vromero
parents:
diff changeset
    30
 */
aecde736ef83 8011181: javac, empty UTF8 entry generated for inner class
vromero
parents:
diff changeset
    31
aecde736ef83 8011181: javac, empty UTF8 entry generated for inner class
vromero
parents:
diff changeset
    32
import java.io.BufferedInputStream;
aecde736ef83 8011181: javac, empty UTF8 entry generated for inner class
vromero
parents:
diff changeset
    33
import java.nio.file.Files;
aecde736ef83 8011181: javac, empty UTF8 entry generated for inner class
vromero
parents:
diff changeset
    34
import java.nio.file.Path;
aecde736ef83 8011181: javac, empty UTF8 entry generated for inner class
vromero
parents:
diff changeset
    35
import java.nio.file.Paths;
aecde736ef83 8011181: javac, empty UTF8 entry generated for inner class
vromero
parents:
diff changeset
    36
aecde736ef83 8011181: javac, empty UTF8 entry generated for inner class
vromero
parents:
diff changeset
    37
import com.sun.tools.javac.util.Assert;
aecde736ef83 8011181: javac, empty UTF8 entry generated for inner class
vromero
parents:
diff changeset
    38
import com.sun.tools.classfile.ClassFile;
aecde736ef83 8011181: javac, empty UTF8 entry generated for inner class
vromero
parents:
diff changeset
    39
aecde736ef83 8011181: javac, empty UTF8 entry generated for inner class
vromero
parents:
diff changeset
    40
import static com.sun.tools.classfile.ConstantPool.CONSTANT_Utf8;
aecde736ef83 8011181: javac, empty UTF8 entry generated for inner class
vromero
parents:
diff changeset
    41
import static com.sun.tools.classfile.ConstantPool.CONSTANT_Utf8_info;
aecde736ef83 8011181: javac, empty UTF8 entry generated for inner class
vromero
parents:
diff changeset
    42
import static com.sun.tools.classfile.ConstantPool.CPInfo;
aecde736ef83 8011181: javac, empty UTF8 entry generated for inner class
vromero
parents:
diff changeset
    43
aecde736ef83 8011181: javac, empty UTF8 entry generated for inner class
vromero
parents:
diff changeset
    44
public class EmptyUTF8ForInnerClassNameTest {
aecde736ef83 8011181: javac, empty UTF8 entry generated for inner class
vromero
parents:
diff changeset
    45
aecde736ef83 8011181: javac, empty UTF8 entry generated for inner class
vromero
parents:
diff changeset
    46
    public static void main(String[] args) throws Exception {
aecde736ef83 8011181: javac, empty UTF8 entry generated for inner class
vromero
parents:
diff changeset
    47
        new EmptyUTF8ForInnerClassNameTest().run();
aecde736ef83 8011181: javac, empty UTF8 entry generated for inner class
vromero
parents:
diff changeset
    48
    }
aecde736ef83 8011181: javac, empty UTF8 entry generated for inner class
vromero
parents:
diff changeset
    49
aecde736ef83 8011181: javac, empty UTF8 entry generated for inner class
vromero
parents:
diff changeset
    50
    void run() throws Exception {
aecde736ef83 8011181: javac, empty UTF8 entry generated for inner class
vromero
parents:
diff changeset
    51
        checkClassFile(Paths.get(System.getProperty("test.classes"),
aecde736ef83 8011181: javac, empty UTF8 entry generated for inner class
vromero
parents:
diff changeset
    52
                this.getClass().getName() + "$1.class"));
aecde736ef83 8011181: javac, empty UTF8 entry generated for inner class
vromero
parents:
diff changeset
    53
        checkClassFile(Paths.get(System.getProperty("test.classes"),
aecde736ef83 8011181: javac, empty UTF8 entry generated for inner class
vromero
parents:
diff changeset
    54
                this.getClass().getName() + "$EnumPlusSwitch.class"));
aecde736ef83 8011181: javac, empty UTF8 entry generated for inner class
vromero
parents:
diff changeset
    55
    }
aecde736ef83 8011181: javac, empty UTF8 entry generated for inner class
vromero
parents:
diff changeset
    56
aecde736ef83 8011181: javac, empty UTF8 entry generated for inner class
vromero
parents:
diff changeset
    57
    void checkClassFile(final Path path) throws Exception {
aecde736ef83 8011181: javac, empty UTF8 entry generated for inner class
vromero
parents:
diff changeset
    58
        ClassFile classFile = ClassFile.read(
aecde736ef83 8011181: javac, empty UTF8 entry generated for inner class
vromero
parents:
diff changeset
    59
                new BufferedInputStream(Files.newInputStream(path)));
aecde736ef83 8011181: javac, empty UTF8 entry generated for inner class
vromero
parents:
diff changeset
    60
        for (CPInfo cpInfo : classFile.constant_pool.entries()) {
aecde736ef83 8011181: javac, empty UTF8 entry generated for inner class
vromero
parents:
diff changeset
    61
            if (cpInfo.getTag() == CONSTANT_Utf8) {
aecde736ef83 8011181: javac, empty UTF8 entry generated for inner class
vromero
parents:
diff changeset
    62
                CONSTANT_Utf8_info utf8Info = (CONSTANT_Utf8_info)cpInfo;
aecde736ef83 8011181: javac, empty UTF8 entry generated for inner class
vromero
parents:
diff changeset
    63
                Assert.check(utf8Info.value.length() > 0,
aecde736ef83 8011181: javac, empty UTF8 entry generated for inner class
vromero
parents:
diff changeset
    64
                        "UTF8 with length 0 found at class " + classFile.getName());
aecde736ef83 8011181: javac, empty UTF8 entry generated for inner class
vromero
parents:
diff changeset
    65
            }
aecde736ef83 8011181: javac, empty UTF8 entry generated for inner class
vromero
parents:
diff changeset
    66
        }
aecde736ef83 8011181: javac, empty UTF8 entry generated for inner class
vromero
parents:
diff changeset
    67
    }
aecde736ef83 8011181: javac, empty UTF8 entry generated for inner class
vromero
parents:
diff changeset
    68
aecde736ef83 8011181: javac, empty UTF8 entry generated for inner class
vromero
parents:
diff changeset
    69
    static class EnumPlusSwitch {
aecde736ef83 8011181: javac, empty UTF8 entry generated for inner class
vromero
parents:
diff changeset
    70
        enum E {E1}
aecde736ef83 8011181: javac, empty UTF8 entry generated for inner class
vromero
parents:
diff changeset
    71
aecde736ef83 8011181: javac, empty UTF8 entry generated for inner class
vromero
parents:
diff changeset
    72
        public int m (E e) {
aecde736ef83 8011181: javac, empty UTF8 entry generated for inner class
vromero
parents:
diff changeset
    73
            switch (e) {
aecde736ef83 8011181: javac, empty UTF8 entry generated for inner class
vromero
parents:
diff changeset
    74
                case E1:
aecde736ef83 8011181: javac, empty UTF8 entry generated for inner class
vromero
parents:
diff changeset
    75
                    return 0;
aecde736ef83 8011181: javac, empty UTF8 entry generated for inner class
vromero
parents:
diff changeset
    76
            }
aecde736ef83 8011181: javac, empty UTF8 entry generated for inner class
vromero
parents:
diff changeset
    77
            return -1;
aecde736ef83 8011181: javac, empty UTF8 entry generated for inner class
vromero
parents:
diff changeset
    78
        }
aecde736ef83 8011181: javac, empty UTF8 entry generated for inner class
vromero
parents:
diff changeset
    79
    }
aecde736ef83 8011181: javac, empty UTF8 entry generated for inner class
vromero
parents:
diff changeset
    80
aecde736ef83 8011181: javac, empty UTF8 entry generated for inner class
vromero
parents:
diff changeset
    81
}