projectlombok / lombok

Very spicy additions to the Java programming language.
https://projectlombok.org/
Other
12.85k stars 2.38k forks source link

@Cleanup is silently ignored in lambdas #1045

Open bdonlan opened 8 years ago

bdonlan commented 8 years ago

When the @Cleanup annotation is used on a local variable declared within a lambda block, it is silently ignored. Repro:

import lombok.Cleanup;
import java.util.concurrent.CountDownLatch;

public class main {
    public static void main(String[] args) {
        CountDownLatch cdl = new CountDownLatch(1);

        Runnable r = () -> {
            @Cleanup("countDown") CountDownLatch cdl2 = cdl;
        };

        r.run();

        if (cdl.getCount() != 0) {
            throw new Error("@Cleanup didn't run");
        }
    }
}
n-kernel commented 8 years ago

I am also occasionally having this issue. I also decompiled my code of a build which was having issues and it indeed turned out that @cleanup was not working within my lambda statements. It affected the whole jar file. This however only rarely happens.

Using maven with the following settings: Lombok 1.16.6 maven compiler plugin 3.3 with java 1.8 maven jar plugin 2.6

If you want more information I can supply this.

tonychenr commented 4 years ago

I tried running that test case. On Lombok 1.16.18 and JDK 1.8, I don't have that problem.