Opened 10 years ago
Closed 9 years ago
#475 closed defect (fixed)
Compilation issue with Java 8
Reported by: | Kevin Milner | Owned by: | |
---|---|---|---|
Priority: | major | Milestone: | OpenSHA 1.4 |
Component: | sha | Version: | |
Keywords: | Cc: | fengo.win@… |
Description
The following line of code in LogicTreePBSWriter.java:673 does not compile on Java 8:
for (ZipEntry entry : Lists.newArrayList(Iterators.forEnumeration(zip.entries()))) {
Here is the error:
Test.java:12: error: incompatible types: UnmodifiableIterator<CAP#1> cannot be converted to ZipEntry for (ZipEntry entry : Lists.newArrayList(Iterators.forEnumeration(zip.entries()))) { ^ where CAP#1 is a fresh type-variable: CAP#1 extends ZipEntry from capture of ? extends ZipEntry
This compiles fine on Java 7, and once compiled runs correctly on Java 8. Here is a small test code snippet that can be compiled outside of opensha to demonstrate (just put guava in your classpath when compiling):
import java.util.zip.ZipEntry; import java.util.zip.ZipFile; import java.io.File; import com.google.common.collect.Iterators; import com.google.common.collect.Lists; public class Test { public static void main(String[] args) throws Exception { ZipFile zip = new ZipFile(new File("/tmp/minisect_dm_files.zip")); for (ZipEntry entry : Lists.newArrayList(Iterators.forEnumeration(zip.entries()))) { System.out.println(entry); } } }
Note: See
TracTickets for help on using
tickets.
Fixed Java 8 compilation in [10907], although I still believe that this is a Java bug. See https://bugs.openjdk.java.net/browse/JDK-8043926.
Fixed by switching to use of Collections.list(...) instead of the double nested Lists.newArrayList(Iterators.forEnumeration(...)).