@NonNull on parameters conflicts with method annotations #623

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

Projects

None yet

1 participant

@lombokissues
Collaborator

Migrated from Google Code (issue 588)

@lombokissues
Collaborator

👤 Vyacheslav.Dubinin   🕗 Oct 09, 2013 at 12:05 UTC

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");
}
}
}

@lombokissues
Collaborator

👤 Vyacheslav.Dubinin   🕗 Oct 10, 2013 at 12:21 UTC

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 :)

@lombokissues
Collaborator

👤 reinierz   🕗 Oct 10, 2013 at 20:35 UTC

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.

@lombokissues
Collaborator

👤 reinierz   🕗 Dec 20, 2013 at 15:17 UTC

Issue #652 has been merged into this issue.

@lombokissues
Collaborator

End of migration

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