lishunli / projectlombok

Automatically exported from code.google.com/p/projectlombok
0 stars 0 forks source link

val inside Java7 try-with-resources does not work with Javac #520

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
import java.io.ByteArrayInputStream;
import java.io.IOException;
import lombok.val;

public class ValInsideTryWithResources {
    public static void main(String[] args) throws IOException {
        try (val is = new ByteArrayInputStream("test".getBytes())) {
        }
    }
}

What is the expected output? What do you see instead?
Compilation fails under "javac" (maven). Code works when compiled/executed from 
Eclipse.
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ lombok-test ---
[INFO] Changes detected - recompiling the module!
[WARNING] File encoding has not been set, using platform encoding Cp1251, i.e. 
build is platform dependent!
[INFO] Compiling 1 source file to D:\workspace\lombok-test\target\classes
[INFO] -------------------------------------------------------------
[ERROR] COMPILATION ERROR :
[INFO] -------------------------------------------------------------
[ERROR] 
/D:/workspace/lombok-test/src/main/java/ValInsideTryWithResources.java:[10,23] 
incompatible types
  required: lombok.val
  found:    java.io.ByteArrayInputStream
[ERROR] 
/D:/workspace/lombok-test/src/main/java/ValInsideTryWithResources.java:[10,18] 
try-with-resources not applicable to variable type
  required: java.lang.AutoCloseable
  found:    lombok.val
[INFO] 2 errors
[INFO] -------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.271s
[INFO] Finished at: Mon May 20 13:37:28 EEST 2013
[INFO] Final Memory: 11M/154M

What version of the product are you using? On what operating system?
0.11.8
Win7 x 64
java version "1.7.0_11"
Java(TM) SE Runtime Environment (build 1.7.0_11-b21)
Java HotSpot(TM) 64-Bit Server VM (build 23.6-b04, mixed mode)

Original issue reported on code.google.com by andrii.r...@gmail.com on 20 May 2013 at 11:32

GoogleCodeExporter commented 9 years ago
Confirmed in 0.11.7 with commandline javac (OpenJDK 1.7.0_15).

Original comment by askon...@gmail.com on 20 May 2013 at 3:06

GoogleCodeExporter commented 9 years ago
Good catch (heh). We fixed it and it'll be in the next major lombok release. If 
you can't wait, there's an edge release that has the bug fixed: 
http://projectlombok.org/download-edge.html

Original comment by reini...@gmail.com on 23 May 2013 at 11:04

GoogleCodeExporter commented 9 years ago
Thanks for prompt reaction

Original comment by andrii.r...@gmail.com on 28 May 2013 at 11:31