Uploaded image for project: 'Groovy'
  1. Groovy
  2. GROOVY-6123

Cannot use @CompileStatic with loop over Enumeration

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 2.0.8, 2.1.3
    • 2.4.3
    • Static compilation
    • None

    Description

      I'm seeing a compilation error with this code:

      def zipFile = new ZipFile(self)
      for (ZipArchiveEntry entry in zipFile.entries) {
          ...
      }
      

      The error:

      lazybones/src/main/groovy/uk/co/cacoethes/util/ArchiveMethods.groovy: 36: [Static type checking] - Cannot loop with element of type org.apache.commons.compress.archivers.zip.ZipArchiveEntry with collection of type java.util.Enumeration <org.apache.commons.compress.archivers.zip.ZipArchiveEntry>
       @ line 36, column 9.
                 for (ZipArchiveEntry entry in zipFile.entries) {
                 ^
       
      1 error
      

      It seems that the static compilation doesn't like generic {{Enumeration}}s because this compiles file if I modify it slightly to look like:

      def zipFile = new ZipFile(self)
      for (ZipArchiveEntry entry in (zipFile.entries as List<ZipArchiveEntry>)) {
          ...
      }
      

      I have attached a sample Gradle project to demonstrate the problem. Simply unpack it into a fresh directory and run ./gradlew compileGroovy.

      Attachments

        1. static-compilation-bug.zip
          991 kB
          Peter Ledbrook

        Issue Links

          Activity

            People

              melix Cédric Champeau
              pledbrook Peter Ledbrook
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: