DomGarguilo opened a new pull request #2472:
URL: https://github.com/apache/accumulo/pull/2472
There are many instances in our tests where we expect an exception to be
thrown and use a try-catch block to ensure that it is. An example (where
`IllegalArgumentException` will be thrown upon calling `new Range(tr)`) looks
like this:
```java
try {
new Range(tr);
fail("Thrift constructor allowed invalid range");
} catch (IllegalArgumentException exc) {
/* good! */
}
```
This way if the expected exception is thrown, the catch block catches it and
does nothing, otherwise the test will fail via the `fail()` statement. While
this works, it can be more effectively handled using `assertThrows()`.
Preserving functionality, the example above would be converted to:
```java
assertThrows("Thrift constructor allowed invalid range",
IllegalArgumentException.class,
() -> new Range(tr));
```
These instances were found using the ErrorProne profile from #2447 with
`-Xep:TryFailRefactoring` added as an arg in the ErrorProne plugin section in
the pom.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]