-
Bug
-
Resolution: Fixed
-
P4
-
8u20
-
b26
-
x86_64
-
windows_7
-
Verified
Issue | Fix Version | Assignee | Priority | Status | Resolution | Resolved In Build |
---|---|---|---|---|---|---|
JDK-8056885 | emb-9 | Unassigned | P4 | Resolved | Fixed | b26 |
JDK-8064051 | 8u45 | Maurizio Cimadamore | P4 | Resolved | Fixed | b01 |
JDK-8052388 | 8u40 | Maurizio Cimadamore | P4 | Resolved | Fixed | b06 |
JDK-8070271 | emb-8u47 | Maurizio Cimadamore | P4 | Resolved | Fixed | team |
FULL PRODUCT VERSION :
java version "1.8.0_20-ea"
Java(TM) SE Runtime Environment (build 1.8.0_20-ea-b23)
Java HotSpot(TM) 64-Bit Server VM (build 25.20-b22, mixed mode)
ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows [versie 6.1.7601]
EXTRA RELEVANT SYSTEM CONFIGURATION :
Apache Maven 3.0.5 (r01de14724cdef164cd33c7c8c2fe155faf9602da; 2013-02-19 14:51:28+0100)
Maven home: D:\apache-maven-3.0.5\bin\..
Java version: 1.8.0_20-ea, vendor: Oracle Corporation
Java home: c:\Program Files\Java\jdk1.8.0_20\jre
Default locale: nl_NL, platform encoding: Cp1252
OS name: "windows 7", version: "6.1", arch: "amd64", family: "dos"
A DESCRIPTION OF THE PROBLEM :
As registered at https://jira.codehaus.org/browse/MCOMPILER-228
Code example compiles in Eclipse, but not with Maven Compiler Plugin. Code is like below (inside a lamda expression)
final x;
if (some condition)
x = a;
else if (some other condition)
x = b;
else
x = c;
ERROR MESSAGES/STACK TRACES THAT OCCUR :
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:compile (default-compile) on project MediaIndexer: Compilation failure: Compilation failure:
[ERROR] /C:/MAPS/MediaIndexer/src/main/java/example/FinalExample.java:[11,13] cannot assign a value to final variable compareTo
[ERROR] /C:/MAPS/MediaIndexer/src/main/java/example/FinalExample.java:[14,13] cannot assign a value to final variable compareTo
[ERROR] /C:/MAPS/MediaIndexer/src/main/java/example/FinalExample.java:[17,13] cannot assign a value to final variable compareTo
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
package example;
import java.util.Comparator;
public class FinalExample {
public static final Comparator<String> comparator = (o1, o2) -> {
final String desc1 = o1;
final String desc2 = o2;
final int compareTo;
if (desc1 == null) {
compareTo = -1;
}
else if (desc2 == null) {
compareTo = 1;
}
else {
compareTo = desc1.compareTo(desc2);
}
if (compareTo == 0) {
return 3;
}
return compareTo;
};
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
The workaround is to remove final for the variable and just ensure that the value is assigned in each code path.
java version "1.8.0_20-ea"
Java(TM) SE Runtime Environment (build 1.8.0_20-ea-b23)
Java HotSpot(TM) 64-Bit Server VM (build 25.20-b22, mixed mode)
ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows [versie 6.1.7601]
EXTRA RELEVANT SYSTEM CONFIGURATION :
Apache Maven 3.0.5 (r01de14724cdef164cd33c7c8c2fe155faf9602da; 2013-02-19 14:51:28+0100)
Maven home: D:\apache-maven-3.0.5\bin\..
Java version: 1.8.0_20-ea, vendor: Oracle Corporation
Java home: c:\Program Files\Java\jdk1.8.0_20\jre
Default locale: nl_NL, platform encoding: Cp1252
OS name: "windows 7", version: "6.1", arch: "amd64", family: "dos"
A DESCRIPTION OF THE PROBLEM :
As registered at https://jira.codehaus.org/browse/MCOMPILER-228
Code example compiles in Eclipse, but not with Maven Compiler Plugin. Code is like below (inside a lamda expression)
final x;
if (some condition)
x = a;
else if (some other condition)
x = b;
else
x = c;
ERROR MESSAGES/STACK TRACES THAT OCCUR :
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:compile (default-compile) on project MediaIndexer: Compilation failure: Compilation failure:
[ERROR] /C:/MAPS/MediaIndexer/src/main/java/example/FinalExample.java:[11,13] cannot assign a value to final variable compareTo
[ERROR] /C:/MAPS/MediaIndexer/src/main/java/example/FinalExample.java:[14,13] cannot assign a value to final variable compareTo
[ERROR] /C:/MAPS/MediaIndexer/src/main/java/example/FinalExample.java:[17,13] cannot assign a value to final variable compareTo
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
package example;
import java.util.Comparator;
public class FinalExample {
public static final Comparator<String> comparator = (o1, o2) -> {
final String desc1 = o1;
final String desc2 = o2;
final int compareTo;
if (desc1 == null) {
compareTo = -1;
}
else if (desc2 == null) {
compareTo = 1;
}
else {
compareTo = desc1.compareTo(desc2);
}
if (compareTo == 0) {
return 3;
}
return compareTo;
};
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
The workaround is to remove final for the variable and just ensure that the value is assigned in each code path.
- backported by
-
JDK-8052388 Cannot assign a value to final variable in lambda
-
- Resolved
-
-
JDK-8056885 Cannot assign a value to final variable in lambda
-
- Resolved
-
-
JDK-8064051 Cannot assign a value to final variable in lambda
-
- Resolved
-
-
JDK-8070271 Cannot assign a value to final variable in lambda
-
- Resolved
-
- duplicates
-
JDK-8073618 Cannot assign a value to final variable in lambda if it is in enum entry/const
-
- Closed
-