Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix uber#667 Contract annotations support boolean constraints
For example, the following method will behave equivalently to guava `Preconditions.checkState` with regards to null checks: ```java @contract("false -> fail") static void check(boolean pass) { if (!pass) throw new RuntimeException(); } ``` This implementation works in a couple of layers: Firstly, contracts with a single boolean resultin in failure are handled by inserting a conditional throw node inline following the annotated method. This provides support for complex boolean logic input validateion. Secondly, simple null equal-to and not-equal-to checks are handled by the existing ContractHandler. These don't support such complex inputs, however they are able to work correctly with boolean outputs rather than exclusively `fail` cases. Note that this PR also fixes an assumption in the `ContractHandler` which assumed that `null -> true` implied `!null -> false` which isn't guaranteed unless otherwise specified -- fixing this allows for several new test cases to work as expected. I've also updated the ContractHandler to use more precise language around antecedent nullness, previously null antecedents were described as nullable. Please let me know if I've misunderstood the logic, but reframing the values helped me to understand the logic.
- Loading branch information