question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Add @CheckReturnValue to detect common mistake through static analysis

See original GitHub issue

A common mistake among new to ParSeq is to treat Task as if it’s creation caused is execution e.g.:

Task<RelevanceItems> getRelevanceItemsTask = _relevanceBackendClient.get(keys)
  .map(relevanceItems -> {
    if (Sets.difference(userItems, relevanceItems).size() > 0) {
      // Doesn’t actually execute since this is a Task but isn’t connected to parent task
      _userItemsClient.update(userId, userItems.addAll(relevanceItems));
    }
    return _userItems;
  });

Using jsr305 @CheckReturnValue on methods that return Task would allow detecting this mistake through static analysis.

Issue Analytics

  • State:open
  • Created 6 years ago
  • Comments:5

github_iconTop GitHub Comments

1reaction
jodzgacommented, Feb 15, 2018

One possibility is to create a custom FindBugs rule. It should not be too hard: refactor rule that validates @CheckReturnValue annotation with a twist that it applies to all methods (annotation is not necessary) which return Task type. This could be a tiny contrib project.

0reactions
linjercommented, Feb 16, 2018

If this turns out to be high effort, I want to note that findbugs community is moving towards the spotbugs project.

Some alternatives could include

  • Adding this as a feature in spotbugs instead
  • Use Google ErrorProne
Read more comments on GitHub >

github_iconTop Results From Across the Web

CheckReturnValue - Error Prone
add (element) returns a boolean : The return value is false if element was already contained in set . Typically, callers don't need...
Read more >
How to mark a Java method as "must use result" for static ...
I would like API users to be able to identify such bugs via static analysis, such as with FindBugs or IntelliJ inspections. I...
Read more >
NetBeans - More static code analysis · Timelessness
Through this option, we can inspect the project with the complete FindBugs static analysis rules set. If this profile is not available ...
Read more >
Bug descriptions — spotbugs 4.7.3 documentation
This code seems to be storing a non-serializable object into an HttpSession. If this session is passivated or migrated, an error will result....
Read more >
Android Lint API Guide - Google Samples
Compatibility: We may add additional parameters over time. ... This is a common mistake for new lint check authors: the lint check works...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found