--- old/src/share/classes/com/sun/tools/javac/comp/Attr.java 2014-03-07 10:50:43.279747098 +0400 +++ new/src/share/classes/com/sun/tools/javac/comp/Attr.java 2014-03-07 10:50:42.559756150 +0400 @@ -2111,10 +2111,8 @@ // // This expression is then *transformed* as follows: // - // (1) add a STATIC flag to the class definition - // if the current environment is static - // (2) add an extends or implements clause - // (3) add a constructor. + // (1) add an extends or implements clause + // (2) add a constructor. // // For instance, if C is a class, and ET is the type of E, // the expression @@ -2131,7 +2129,13 @@ // } // ... // } - if (Resolve.isStatic(env)) cdef.mods.flags |= STATIC; + // + // NOTE: STATIC flag used to be added to the class + // definition in a static environment. + // However, according to JLS: 15.9.5: + // "An anonymous class is never static" + // So, it is not added anymore. + // if (clazztype.tsym.isInterface()) { cdef.implementing = List.of(clazz); --- old/src/share/classes/com/sun/tools/javac/comp/Check.java 2014-03-07 10:50:46.007712804 +0400 +++ new/src/share/classes/com/sun/tools/javac/comp/Check.java 2014-03-07 10:50:45.211722809 +0400 @@ -1073,9 +1073,11 @@ if (sym.isLocal()) { mask = LocalClassFlags; if (sym.name.isEmpty()) { // Anonymous class - // Anonymous classes in static methods are themselves static; - // that's why we admit STATIC here. - mask |= STATIC; + // JLS 15.9.5.: An anonymous class is never static, + if ((flags & ENUM) != 0) { + // extended ENUM is an exception + mask |= STATIC; + } // JLS: Anonymous classes are final. implicit |= FINAL; } --- /dev/null 2014-03-02 18:42:37.224835302 +0400 +++ new/test/tools/javac/T8034044.java 2014-03-07 10:50:47.731691129 +0400 @@ -0,0 +1,61 @@ +/* + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/* + * @test + * @bug 8034044 + * @summary An anonymous class should not be static + */ + +import static java.lang.reflect.Modifier.*; + +public class T8034044 { + enum En { + V() {} + } + + static class InnStat { + static Object o = new Object() {}; + } + + public static void main(String[] args) throws Throwable { + Object o = new Object() {}; + test(o.getClass(), false); + test(En.V.getClass(), true); + test(InnStat.o.getClass(), false); + new T8034044().f(); + } + + public void f() { + Object o = new Object() {}; + test(o.getClass(), false); + } + + static void test(Class clazz, boolean shouldBeStatic) { + boolean isStatic = (0 != (STATIC & clazz.getModifiers())); + if (isStatic != shouldBeStatic) + throw new AssertionError(clazz.toString() + + " should " + (shouldBeStatic ? "" : "not") + + " be static"); + } +}