-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Annotate DSL API with @CheckReturnValue to help detect when calling execute() etc is forgotten #11718
Comments
Saw this on Twitter and had a similar problem lately where missing We‘ve registered every builder instance and removed it in Hard to fix properly, though. Would need tooling support like |
What are those
See the discussion in https://youtrack.jetbrains.com/issue/IDEA-265263 |
Awesome news from https://youtrack.jetbrains.com/issue/IDEA-265263 Just look at this nice trick! So, all we have to do is add an |
Most API is now annotated with this new annotation. I've searched for all |
…calling execute() etc is forgotten
ErrorProne also includes this annotation, so you can fail the build if it was missed. |
Yes I've seen that one, that's even more interesting. If someone is interested, I'm sure they can adapt the ErrorProne rule to the new jOOQ annotation. But for the same reasons I've chosen to use the JetBrains annotations Besides, I'm glad that the JetBrains annotations have |
ErrorProne checks on the simple name so it should catch the jetbrains one too. That means more users might see a benefit in their builds, not just those who use a particular IDE. So maybe even better than you thought. |
JetBrains doesn't have one yet, which is why I added the
Absolutely! Thanks for pointing this out :) |
With this change, you have also added Because of this change, our SpotBugs setup alerts for code like this:
I see no clean way to write the same code without triggering the SpotBugs warning. Is this change on such classes also by intention? Using jooq 3.15.1 and SpotBugs 4.0.4. |
Thanks for your pointer, @uwolfer. I'm aware of this limitation for the case when a mutable call chain is still consumed in the end. See also the discussion here, that triggered this improvement: https://youtrack.jetbrains.com/issue/IDEA-265263 (look for the Once a better annotation than Surely, there's a way of ignoring the warning in SpotBugs for some scope? |
Of course, this would not be an issue (in your case), if we had #2333 |
Thanks for your feedback!
Yes, there is, but unfortunately it seems to work only on a class level: @SuppressFBWarnings(
value = "RV_RETURN_VALUE_IGNORED",
justification = "ignoring jOOQ @CheckReturnValue")
Yes, in the case of limit / offset. But I also get these alerts for example for adding It's okay for me for now to add such annotations, but let's hope infrastructure improves in the future. |
Then don't! It's almost never necessary to leverage the mutable DSL API this way. Use In fact, it's great news that the mutating style triggers such warnings. That way, in the future, we might be able to move towards immutability more easily! |
Forgetting to execute DML queries is a common mistake in jOOQ:
The problem appears mostly when the result of query execution (in this case an update count) is discarded, which is mostly the case for DML statements. There's no easy way for jOOQ to fail compilation when such an
execute()
call is omitted.Static code analysis could help here, but isn't ready yet:
https://youtrack.jetbrains.com/issue/IDEA-265263
A way jOOQ could help here would be by leveraging GC related tools like
Object.finalize()
(which has a lot of disadvantages), or the newerjava.lang.ref.Cleaner
API orPhantomReference
, etc.The text was updated successfully, but these errors were encountered: