lishunli / projectlombok

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

@NonNull on parameters conflicts with method annotations #588

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?

1. Create non-void method with parameters
2. Annotate some parameter with @NonNull
3. Annotate method with some annotation (@SneakyThrows or @Synchronized for 
example)
4. Compile

import lombok.NonNull;
import lombok.SneakyThrows;

public class Class {
    @SneakyThrows
    public String method(@NonNull final String parameter) {
        return parameter;
    }
}

What is the expected output? What do you see instead?

Expected successful compilation, get "unreachable statement" compilation error.

What version of the product are you using? On what operating system?

lombok 0.12.0; Ubuntu 13.04 with java version 1.7.0_25 (OpenJDK)

Please provide any additional information below.

Delombok shows the reason:

import lombok.NonNull;

public class Class {
    public String method(@NonNull final String parameter) {
        try {
            return parameter;
        } catch (final java.lang.Throwable $ex) {
            throw lombok.Lombok.sneakyThrow($ex);
        }
        if (parameter == null) {
            throw new java.lang.NullPointerException("parameter");
        }
    }
}

Original issue reported on code.google.com by Vyachesl...@gmail.com on 9 Oct 2013 at 12:05

GoogleCodeExporter commented 9 years ago
Setting very low priority for NonNullHandler (by adding 
@HandlerPriority(-65536) annotation) seems to solve this problem.
But I am not familiar with lombok's source code so I am not sure that this 
modification do not break something else :)

Original comment by Vyachesl...@gmail.com on 10 Oct 2013 at 12:21

GoogleCodeExporter commented 9 years ago
We actually upped the priority level of the HandleNonNull class (running it 
AFTER @Setter and the like), and then upped the priority level of 
HandleSynchronized and HandleSneakyThrows even more. That and some new tests 
and fixes to existing tests. Thanks for spotting it! Will be in 1.12.2 which 
will be released later today.

Original comment by reini...@gmail.com on 10 Oct 2013 at 8:35

GoogleCodeExporter commented 9 years ago
Issue 617 has been merged into this issue.

Original comment by reini...@gmail.com on 20 Dec 2013 at 3:17