Uploaded image for project: 'Maven Compiler Plugin'
  1. Maven Compiler Plugin
  2. MCOMPILER-228

cannot assign a value to final variable in lamda

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Minor
    • Resolution: Not A Problem
    • 3.1
    • None
    • None
    • Windows 7 64 bit, Maven 3.2.2, JDK 64 bit 8u5

    Description

      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;
      

      See attached example source.

      [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
      

      The workaround is to remove final for the variable and just ensure that the value is assigned in each code path.

      Attachments

        1. FinalExample.java
          0.6 kB
          Robert Kish
        2. MCOMPILER-228.patch
          2 kB
          Robert Scholte

        Issue Links

          Activity

            People

              rfscholte Robert Scholte
              rmkish Robert Kish
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: