Skip to content

Commit 07a7510

Browse files
lgxbslgxmcimadamore
authored andcommitted
8200145: Conditional expression mistakenly treated as standalone
Reviewed-by: mcimadamore
1 parent 41fc7dd commit 07a7510

File tree

3 files changed

+46
-1
lines changed

3 files changed

+46
-1
lines changed

src/jdk.compiler/share/classes/com/sun/tools/javac/code/Types.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4319,6 +4319,8 @@ public Type boxedTypeOrType(Type t) {
43194319
* Return the primitive type corresponding to a boxed type.
43204320
*/
43214321
public Type unboxedType(Type t) {
4322+
if (t.hasTag(ERROR))
4323+
return Type.noType;
43224324
for (int i=0; i<syms.boxedName.length; i++) {
43234325
Name box = syms.boxedName[i];
43244326
if (box != null &&

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
@@ -1968,7 +1968,7 @@ private boolean isBooleanOrNumeric(Env<AttrContext> env, JCExpression tree) {
19681968
}
19691969
//where
19701970
boolean primitiveOrBoxed(Type t) {
1971-
return (!t.hasTag(TYPEVAR) && types.unboxedTypeOrType(t).isPrimitive());
1971+
return (!t.hasTag(TYPEVAR) && !t.isErroneous() && types.unboxedTypeOrType(t).isPrimitive());
19721972
}
19731973

19741974
TreeTranslator removeClassParams = new TreeTranslator() {
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/*
2+
* Copyright (c) 2021, 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 8200145
27+
* @summary Conditional expression mistakenly treated as standalone
28+
* @run compile T8200145.java
29+
*/
30+
31+
public class T8200145 {
32+
static class Outer {
33+
class Inner<T> implements Runnable { public void run() {} }
34+
}
35+
36+
void test(Outer outer) {
37+
boolean test = 1 == 1 ;
38+
Outer.Inner<String> inner1 = outer.new Inner<>();
39+
Outer.Inner<String> inner2 = test ? outer.new Inner<>() : null;
40+
Outer.Inner<String> inner3 = test ? null: outer.new Inner<>();
41+
Outer.Inner<String> inner4 = test ? outer.new Inner<>() : outer.new Inner<>();
42+
}
43+
}

0 commit comments

Comments
 (0)