Created
November 17, 2017 09:22
-
-
Save mbjelac/faee5b754558f2243bf550989b85c75c to your computer and use it in GitHub Desktop.
Lombok @nonnull doesn't work for local variables (by design)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import lombok.NonNull; | |
import lombok.Value; | |
import lombok.val; | |
import org.junit.Test; | |
import static org.junit.Assert.fail; | |
public class LombokNonNullTest { | |
@Value | |
class Bean { | |
String message; | |
} | |
class SomeCode { | |
void process(Bean bean) { | |
@NonNull | |
val message = bean.getMessage(); | |
// ... go on happily because message cannot be null | |
} | |
} | |
@Test | |
public void nonNull_works_on_local_variable() { | |
try { | |
new SomeCode().process(new Bean(null)); | |
fail(); | |
} catch (IllegalArgumentException expected) { | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment