Skip to content

Commit 697bf7a

Browse files
lgxbslgxVicente Romero
authored andcommitted
8257740: Compiler crash when compiling type annotation on multicatch inside lambda
Reviewed-by: vromero
1 parent b549cbd commit 697bf7a

File tree

3 files changed

+106
-0
lines changed

3 files changed

+106
-0
lines changed

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2070,10 +2070,22 @@ public Symbol baseSymbol() {
20702070
case LOCAL_VAR:
20712071
ret = new VarSymbol(sym.flags() & FINAL, sym.name, sym.type, translatedSym);
20722072
((VarSymbol) ret).pos = ((VarSymbol) sym).pos;
2073+
// If sym.data == ElementKind.EXCEPTION_PARAMETER,
2074+
// set ret.data = ElementKind.EXCEPTION_PARAMETER too.
2075+
// Because method com.sun.tools.javac.jvm.Code.fillExceptionParameterPositions and
2076+
// com.sun.tools.javac.jvm.Code.fillLocalVarPosition would use it.
2077+
// See JDK-8257740 for more information.
2078+
if (((VarSymbol) sym).isExceptionParameter()) {
2079+
((VarSymbol) ret).setData(ElementKind.EXCEPTION_PARAMETER);
2080+
}
20732081
break;
20742082
case PARAM:
20752083
ret = new VarSymbol((sym.flags() & FINAL) | PARAMETER, sym.name, types.erasure(sym.type), translatedSym);
20762084
((VarSymbol) ret).pos = ((VarSymbol) sym).pos;
2085+
// Set ret.data. Same as case LOCAL_VAR above.
2086+
if (((VarSymbol) sym).isExceptionParameter()) {
2087+
((VarSymbol) ret).setData(ElementKind.EXCEPTION_PARAMETER);
2088+
}
20772089
break;
20782090
default:
20792091
Assert.error(skind.name());
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/*
2+
* Copyright (c) 2020, 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 8257740
27+
* @summary Compiler crash when compiling type annotation on uni-catch inside lambda
28+
* @run compile T8257740_1.java
29+
*/
30+
31+
import java.lang.annotation.ElementType;
32+
import java.lang.annotation.Target;
33+
34+
public class T8257740_1 {
35+
@Target(ElementType.TYPE_USE)
36+
@interface T8257740_1_Anno { }
37+
38+
void test() {
39+
Runnable r = () -> {
40+
try {
41+
System.out.println();
42+
} catch (@T8257740_1_Anno Exception e) { // uni-catch
43+
e.printStackTrace();
44+
}
45+
};
46+
}
47+
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/*
2+
* Copyright (c) 2020, 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 8257740
27+
* @summary Compiler crash when compiling type annotation on multi-catch inside lambda
28+
* @run compile T8257740_2.java
29+
*/
30+
31+
import java.lang.annotation.ElementType;
32+
import java.lang.annotation.Target;
33+
34+
public class T8257740_2 {
35+
@Target(ElementType.TYPE_USE)
36+
@interface T8257740_2_Anno { }
37+
38+
void test() {
39+
Runnable r = () -> {
40+
try {
41+
System.out.println();
42+
} catch (@T8257740_2_Anno Exception | Error e) { // multi-catch
43+
e.printStackTrace();
44+
}
45+
};
46+
}
47+
}

0 commit comments

Comments
 (0)