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

Closed
lombokissues opened this Issue Jul 14, 2015 · 5 comments

Projects

None yet

2 participants

@lombokissues
Collaborator

Migrated from Google Code (issue 520)

@lombokissues
Collaborator

👤 andrii.rubtsov   🕗 May 20, 2013 at 11:32 UTC

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)

@lombokissues
Collaborator

👤 askoning   🕗 May 20, 2013 at 15:06 UTC

Confirmed in 0.11.7 with commandline javac (OpenJDK 1.7.0_15).

@lombokissues
Collaborator

👤 reinierz   🕗 May 23, 2013 at 23:04 UTC

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: https://projectlombok.org/download-edge.html

@lombokissues lombokissues removed the accepted label Jul 14, 2015
@lombokissues lombokissues added the javac label Jul 14, 2015
@lombokissues
Collaborator

👤 andrii.rubtsov   🕗 May 28, 2013 at 11:31 UTC

Thanks for prompt reaction

@lombokissues
Collaborator

End of migration

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment