Skip to content

Commit 05c9eec

Browse files
author
Vicente Romero
committed
8361214: An anonymous class is erroneously being classify as an abstract class
Reviewed-by: liach, mcimadamore
1 parent fea73c1 commit 05c9eec

File tree

2 files changed

+45
-1
lines changed

2 files changed

+45
-1
lines changed

src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Attr.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2833,7 +2833,7 @@ public void visitNewClass(final JCNewClass tree) {
28332833
resultInfo.checkContext.deferredAttrContext().mode == DeferredAttr.AttrMode.SPECULATIVE;
28342834
boolean skipNonDiamondPath = false;
28352835
// Check that class is not abstract
2836-
if (cdef == null && !isSpeculativeDiamondInferenceRound && // class body may be nulled out in speculative tree copy
2836+
if (cdef == null && !tree.classDeclRemoved() && !isSpeculativeDiamondInferenceRound && // class body may be nulled out in speculative tree copy
28372837
(clazztype.tsym.flags() & (ABSTRACT | INTERFACE)) != 0) {
28382838
log.error(tree.pos(),
28392839
Errors.AbstractCantBeInstantiated(clazztype.tsym));
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/*
2+
* Copyright (c) 2025, 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.
8+
*
9+
* This code is distributed in the hope that it will be useful, but WITHOUT
10+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12+
* version 2 for more details (a copy is included in the LICENSE file that
13+
* accompanied this code).
14+
*
15+
* You should have received a copy of the GNU General Public License version
16+
* 2 along with this work; if not, write to the Free Software Foundation,
17+
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18+
*
19+
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20+
* or visit www.oracle.com if you need additional information or have any
21+
* questions.
22+
*/
23+
24+
/*
25+
* @test
26+
* @bug 8361214
27+
* @summary An anonymous class is erroneously being classify as an abstract class
28+
* @compile AnonymousLabeledAsAbstractTest.java
29+
*/
30+
31+
class AnonymousLabeledAsAbstractTest {
32+
abstract class Base<T> {}
33+
abstract class Derived1<T> extends Base<T> {}
34+
abstract class Derived2<T> extends Base<T> {
35+
Derived2(Derived1<T> obj){}
36+
}
37+
abstract class Derived3<T> extends Base<T> {
38+
Derived3(Derived2<T> obj){}
39+
}
40+
41+
Base<String> obj = new Derived2<>(new Derived1<>(){}){};
42+
Base<String> obj2 = new Derived3<String>(new Derived2<>(new Derived1<>(){}){}){};
43+
Base<String> obj3 = new Derived3<>(new Derived2<>(new Derived1<>(){}){}){};
44+
}

0 commit comments

Comments
 (0)