google / error-prone

Catch common Java mistakes as compile-time errors
https://errorprone.info
Apache License 2.0
6.85k stars 744 forks source link

Check for unused AssertJ/FEST boolean assertion (e.g. assertThat(<expr>);) #308

Open sul3n3t opened 9 years ago

sul3n3t commented 9 years ago

AssertJ and FEST assertions are commonly used in different projects. Boolean assertions take the form assertThat(<expression>).isTrue(); or assertThat(<expression>).isFalse();.

A common mistake, visually easy to miss, is to just write assertThat(<expression>);. Someone unfamiliar with the assertion library may assume this would check that the expression evaluates to true. However, no assertion is made on the evaluated expression. I propose error-prone has a FAIL check on assertThat(<expression>);.

cushon commented 9 years ago

This also applies to truth assertions.

You can get this for free by adding @CheckReturnValue annotations to these methods (that's what truth does). But it if the other libraries can't be annotated directly, it would be easy to make a variant of ReturnValueIgnored that caught that error.

sul3n3t commented 9 years ago

Thanks! I'm trying the @CheckReturnValue approach with a PR to the project (I'm not on it), see joel-costigliola/assertj-core#436.

gaul commented 8 years ago

Fixing #422 will address this issue.