Skip to content
This repository has been archived by the owner on Jun 21, 2023. It is now read-only.

CallExecutor fails if null is returned #42

Closed
mkopylec opened this issue Dec 29, 2017 · 4 comments
Closed

CallExecutor fails if null is returned #42

mkopylec opened this issue Dec 29, 2017 · 4 comments
Labels
Milestone

Comments

@mkopylec
Copy link

It is quite common that retryable call will produce null result. Now it is impossible to return null because of:

    private Optional<T> tryCall(Callable<T> callable) throws UnexpectedException {
        try {
            T result = callable.call();
            return Optional.of(result); // TODO Allow nulls, use ofNullable(result);
        } catch (Exception e) {
            if (shouldThrowException(e)) {
                logger.trace("Throwing expected exception {}", e);
                throw new UnexpectedException(e);
            } else {
                lastKnownExceptionThatCausedRetry = e;
                return Optional.empty();
            }
        }
    }
@elennick elennick added the bug label Dec 30, 2017
@elennick elennick modified the milestones: 0.7.3, 0.8.0 Dec 30, 2017
@elennick elennick added enhancement and removed bug labels Dec 30, 2017
@elennick
Copy link
Owner

So I feel like i may have designed myself into a bit of a corner here. Retry4j really only considers three result scenarios:

  1. an expected exception is thrown and it retries (or fails because too many retries have occurred)
  2. an unexpected exception is thrown and it fails
  3. ANY result is returned and it succeeds

The problem that you're pointing out here is that when a null value comes back and there is logic expects that ANY value is a success executes, it blows up with a NPE due to that value being null.

So anyhow, I could do what you're suggesting above and use Optional.ofNullable() instead of Optional.of() but then I'm adding in another case above where:

  1. a null result is returned and the executor retries (or fails because of too many retries)

...that seems potentially ok?

I might also just want to refactor the call executor to not use optionals the way it is now in which case a null result would just be considered a success which feels a little more natural and intuitive. Let me think about this a little before I rush a change.

@mkopylec
Copy link
Author

What I expect is that the null result is a valid result and doesn't trigger retries.
As for the implementation just do it as you like. I don't know the code well so I will not suggest any solution :)

@elennick
Copy link
Owner

Yea... in retrospect i might have overcomplicated things when thinking about it, the entire issue is just caused by me using an optional internally. Already have it fixed, I'll push it out soon.

@elennick elennick modified the milestones: 0.8.0, 0.7.3 Dec 30, 2017
@elennick
Copy link
Owner

fixed with 0.7.3 release just now

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

2 participants