langtools/test/tools/javac/T8034044.java
author katleman
Thu, 21 Aug 2014 14:16:14 -0700
changeset 25878 6d561031123e
parent 23803 98c4ebaddefc
permissions -rw-r--r--
Added tag jdk9-b27 for changeset 98ce0879ab4c
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
23803
98c4ebaddefc 8034044: Class.getModifiers() returns "static" for anonymous classes
igerasim
parents:
diff changeset
     1
/*
98c4ebaddefc 8034044: Class.getModifiers() returns "static" for anonymous classes
igerasim
parents:
diff changeset
     2
 * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
98c4ebaddefc 8034044: Class.getModifiers() returns "static" for anonymous classes
igerasim
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
98c4ebaddefc 8034044: Class.getModifiers() returns "static" for anonymous classes
igerasim
parents:
diff changeset
     4
 *
98c4ebaddefc 8034044: Class.getModifiers() returns "static" for anonymous classes
igerasim
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
98c4ebaddefc 8034044: Class.getModifiers() returns "static" for anonymous classes
igerasim
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
98c4ebaddefc 8034044: Class.getModifiers() returns "static" for anonymous classes
igerasim
parents:
diff changeset
     7
 * published by the Free Software Foundation.
98c4ebaddefc 8034044: Class.getModifiers() returns "static" for anonymous classes
igerasim
parents:
diff changeset
     8
 *
98c4ebaddefc 8034044: Class.getModifiers() returns "static" for anonymous classes
igerasim
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
98c4ebaddefc 8034044: Class.getModifiers() returns "static" for anonymous classes
igerasim
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
98c4ebaddefc 8034044: Class.getModifiers() returns "static" for anonymous classes
igerasim
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
98c4ebaddefc 8034044: Class.getModifiers() returns "static" for anonymous classes
igerasim
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
98c4ebaddefc 8034044: Class.getModifiers() returns "static" for anonymous classes
igerasim
parents:
diff changeset
    13
 * accompanied this code).
98c4ebaddefc 8034044: Class.getModifiers() returns "static" for anonymous classes
igerasim
parents:
diff changeset
    14
 *
98c4ebaddefc 8034044: Class.getModifiers() returns "static" for anonymous classes
igerasim
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
98c4ebaddefc 8034044: Class.getModifiers() returns "static" for anonymous classes
igerasim
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
98c4ebaddefc 8034044: Class.getModifiers() returns "static" for anonymous classes
igerasim
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
98c4ebaddefc 8034044: Class.getModifiers() returns "static" for anonymous classes
igerasim
parents:
diff changeset
    18
 *
98c4ebaddefc 8034044: Class.getModifiers() returns "static" for anonymous classes
igerasim
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
98c4ebaddefc 8034044: Class.getModifiers() returns "static" for anonymous classes
igerasim
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
98c4ebaddefc 8034044: Class.getModifiers() returns "static" for anonymous classes
igerasim
parents:
diff changeset
    21
 * questions.
98c4ebaddefc 8034044: Class.getModifiers() returns "static" for anonymous classes
igerasim
parents:
diff changeset
    22
 */
98c4ebaddefc 8034044: Class.getModifiers() returns "static" for anonymous classes
igerasim
parents:
diff changeset
    23
98c4ebaddefc 8034044: Class.getModifiers() returns "static" for anonymous classes
igerasim
parents:
diff changeset
    24
/*
98c4ebaddefc 8034044: Class.getModifiers() returns "static" for anonymous classes
igerasim
parents:
diff changeset
    25
 * @test
98c4ebaddefc 8034044: Class.getModifiers() returns "static" for anonymous classes
igerasim
parents:
diff changeset
    26
 * @bug 8034044
98c4ebaddefc 8034044: Class.getModifiers() returns "static" for anonymous classes
igerasim
parents:
diff changeset
    27
 * @summary An anonymous class should not be static
98c4ebaddefc 8034044: Class.getModifiers() returns "static" for anonymous classes
igerasim
parents:
diff changeset
    28
 */
98c4ebaddefc 8034044: Class.getModifiers() returns "static" for anonymous classes
igerasim
parents:
diff changeset
    29
98c4ebaddefc 8034044: Class.getModifiers() returns "static" for anonymous classes
igerasim
parents:
diff changeset
    30
import static java.lang.reflect.Modifier.*;
98c4ebaddefc 8034044: Class.getModifiers() returns "static" for anonymous classes
igerasim
parents:
diff changeset
    31
98c4ebaddefc 8034044: Class.getModifiers() returns "static" for anonymous classes
igerasim
parents:
diff changeset
    32
public class T8034044 {
98c4ebaddefc 8034044: Class.getModifiers() returns "static" for anonymous classes
igerasim
parents:
diff changeset
    33
    enum En {
98c4ebaddefc 8034044: Class.getModifiers() returns "static" for anonymous classes
igerasim
parents:
diff changeset
    34
        V() {}
98c4ebaddefc 8034044: Class.getModifiers() returns "static" for anonymous classes
igerasim
parents:
diff changeset
    35
    }
98c4ebaddefc 8034044: Class.getModifiers() returns "static" for anonymous classes
igerasim
parents:
diff changeset
    36
98c4ebaddefc 8034044: Class.getModifiers() returns "static" for anonymous classes
igerasim
parents:
diff changeset
    37
    static class InnStat {
98c4ebaddefc 8034044: Class.getModifiers() returns "static" for anonymous classes
igerasim
parents:
diff changeset
    38
        static Object o = new Object() {};
98c4ebaddefc 8034044: Class.getModifiers() returns "static" for anonymous classes
igerasim
parents:
diff changeset
    39
    }
98c4ebaddefc 8034044: Class.getModifiers() returns "static" for anonymous classes
igerasim
parents:
diff changeset
    40
98c4ebaddefc 8034044: Class.getModifiers() returns "static" for anonymous classes
igerasim
parents:
diff changeset
    41
    public static void main(String[] args)
98c4ebaddefc 8034044: Class.getModifiers() returns "static" for anonymous classes
igerasim
parents:
diff changeset
    42
            throws Throwable {
98c4ebaddefc 8034044: Class.getModifiers() returns "static" for anonymous classes
igerasim
parents:
diff changeset
    43
        Object o = new Object() {};
98c4ebaddefc 8034044: Class.getModifiers() returns "static" for anonymous classes
igerasim
parents:
diff changeset
    44
        test(o.getClass());
98c4ebaddefc 8034044: Class.getModifiers() returns "static" for anonymous classes
igerasim
parents:
diff changeset
    45
        test(En.V.getClass());
98c4ebaddefc 8034044: Class.getModifiers() returns "static" for anonymous classes
igerasim
parents:
diff changeset
    46
        test(InnStat.o.getClass());
98c4ebaddefc 8034044: Class.getModifiers() returns "static" for anonymous classes
igerasim
parents:
diff changeset
    47
        new T8034044().f();
98c4ebaddefc 8034044: Class.getModifiers() returns "static" for anonymous classes
igerasim
parents:
diff changeset
    48
    }
98c4ebaddefc 8034044: Class.getModifiers() returns "static" for anonymous classes
igerasim
parents:
diff changeset
    49
98c4ebaddefc 8034044: Class.getModifiers() returns "static" for anonymous classes
igerasim
parents:
diff changeset
    50
    public void f() {
98c4ebaddefc 8034044: Class.getModifiers() returns "static" for anonymous classes
igerasim
parents:
diff changeset
    51
        Object o = new Object() {};
98c4ebaddefc 8034044: Class.getModifiers() returns "static" for anonymous classes
igerasim
parents:
diff changeset
    52
        test(o.getClass());
98c4ebaddefc 8034044: Class.getModifiers() returns "static" for anonymous classes
igerasim
parents:
diff changeset
    53
    }
98c4ebaddefc 8034044: Class.getModifiers() returns "static" for anonymous classes
igerasim
parents:
diff changeset
    54
98c4ebaddefc 8034044: Class.getModifiers() returns "static" for anonymous classes
igerasim
parents:
diff changeset
    55
    static void test(Class clazz) {
98c4ebaddefc 8034044: Class.getModifiers() returns "static" for anonymous classes
igerasim
parents:
diff changeset
    56
        if ((clazz.getModifiers() & STATIC) != 0)
98c4ebaddefc 8034044: Class.getModifiers() returns "static" for anonymous classes
igerasim
parents:
diff changeset
    57
            throw new AssertionError(clazz.toString() +
98c4ebaddefc 8034044: Class.getModifiers() returns "static" for anonymous classes
igerasim
parents:
diff changeset
    58
                    " should not be static");
98c4ebaddefc 8034044: Class.getModifiers() returns "static" for anonymous classes
igerasim
parents:
diff changeset
    59
    }
98c4ebaddefc 8034044: Class.getModifiers() returns "static" for anonymous classes
igerasim
parents:
diff changeset
    60
}