File tree 3 files changed +21
-6
lines changed
src/jdk.compiler/share/classes/com/sun/tools/javac/comp
test/langtools/tools/javac/lambda/8294461
3 files changed +21
-6
lines changed Original file line number Diff line number Diff line change @@ -2006,14 +2006,13 @@ void newVar(JCVariableDecl varDecl) {
2006
2006
void letInit (DiagnosticPosition pos , VarSymbol sym ) {
2007
2007
if (sym .adr >= firstadr && trackable (sym )) {
2008
2008
if ((sym .flags () & EFFECTIVELY_FINAL ) != 0 ) {
2009
- if (!uninits .isMember (sym .adr )) {
2010
- //assignment targeting an effectively final variable
2011
- //makes the variable lose its status of effectively final
2012
- //if the variable is _not_ definitively unassigned
2009
+ if (inits . isMember ( sym . adr ) || !uninits .isMember (sym .adr )) {
2010
+ //assignment targeting an effectively final variable makes the
2011
+ //variable lose its status of effectively final if the variable
2012
+ //is definitely assigned or _not_ definitively unassigned
2013
2013
sym .flags_field &= ~EFFECTIVELY_FINAL ;
2014
- } else {
2015
- uninit (sym );
2016
2014
}
2015
+ uninit (sym );
2017
2016
}
2018
2017
else if ((sym .flags () & FINAL ) != 0 ) {
2019
2018
if ((sym .flags () & PARAMETER ) != 0 ) {
Original file line number Diff line number Diff line change
1
+ /*
2
+ * @test /nodynamiccopyright/
3
+ * @summary Verify for() loop variable not effectively final even if loop never increments
4
+ * @bug 8294461
5
+ * @compile/fail/ref=EffectivelyFinalLoopIncrement.out -XDrawDiagnostics EffectivelyFinalLoopIncrement.java
6
+ */
7
+ class EffectivelyFinalLoopIncrement {
8
+ EffectivelyFinalLoopIncrement () {
9
+ for (int i = 0 ; i < 10 ; i ++) {
10
+ Runnable r = () -> System .out .println (i ); // variable i is NOT effectively final
11
+ break ; // even though "i++" is never reached
12
+ }
13
+ }
14
+ }
Original file line number Diff line number Diff line change
1
+ EffectivelyFinalLoopIncrement.java:10:51: compiler.err.cant.ref.non.effectively.final.var: i, (compiler.misc.lambda)
2
+ 1 error
You can’t perform that action at this time.
0 commit comments