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.

2.x: @CheckReturnValue for public API

See original GitHub issue

How do you guys feel if the @CheckReturnValue annotation was added to certain public API methods?

The one that would probably benefit the most in my opinion would be the subscribe method where you get a Subscription or Disposable back. In 99% of the cases you want to handle it.

Also static analyze tools such as Error Prone could emit an error / warning.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:29 (9 by maintainers)

github_iconTop GitHub Comments

9reactions
autonomousappscommented, Apr 2, 2018

Ugh. After updating to RxJava 2.1.12, I have awful yellow warning highlighting everywhere. My two cents – I hate @CheckReturnValue. I do the following, which works well for my project:

.doOnSubscribe(subscriptions::add) // subscriptions is a CompositeDisposable

I find this much more readable than

Disposable disposable = somethingService.get().subscribe(...);
composititeDisposable.add(disposable);

I don’t want to suppress that warning everywhere, so now I have to litter my code with local suppressions.

9reactions
drakeetcommented, May 29, 2018

I love the @CheckReturnValue, but in some projects with RxLifecycle we do not actually need to care about this return value. In this case, we have to use suppress everywhere, 🤔…

P.S. I finally found a perfect solution: https://github.com/uber/AutoDispose

Read more comments on GitHub >

github_iconTop Results From Across the Web

javax.annotation.CheckReturnValue Java Examples
Prepares for a check that the subject is deadline within the given tolerance of an * expected value that will be provided in...
Read more >
CheckReturnValue (SpotBugs 3.1.2 API) - javadoc.io
This annotation is used to denote a method whose return value should always be checked when invoking the method. The checker treats this...
Read more >
Using annotation to ensure that value returned by method is ...
Having an annotation that would enforce clients to not ignore return values of certain methods, and having it enforced by the compiler at ......
Read more >
UnsignedInts (Guava: Google Core Libraries for Java 19.0 API)
Returns a string representation of x, where x is treated as unsigned. toString. @CheckReturnValue public static String toString(int x, int radix). Returns a ......
Read more >
JDABuilder (JDA 5.0.0-beta.2 API)
declaration: package: net.dv8tion.jda.api, class: JDABuilder. ... @Nonnull @CheckReturnValue public static JDABuilder createDefault(@Nullable String token).
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