Skip to content

Conversation

@mohamedsamehsalah
Copy link
Contributor

@mohamedsamehsalah mohamedsamehsalah commented Oct 31, 2025

Suggested commit message

Extend `{Flux,Mono}OnErrorComplete` Refaster rules (#1939)

return Mono.just(1).onErrorComplete().doOnError(e -> {});
}

Mono<Integer> testMonoDoOnErrorClassOnErrorComplete() {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I admittedly don't know:

  1. Why Refaster is not picking this line from the @BeforeTemplate.
  2. How to fix it 😄

@Stephan202 @rickie , would appreciate the help 🙏

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's because of the specific signature of this doOnError overload; I'll push a fix. 👍

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I still don't quite get it 😅

Copy link
Contributor Author

@mohamedsamehsalah mohamedsamehsalah Nov 1, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the diff output:

diff (-expected +actual):
    @@ -600,7 +600,7 @@
       }
     
       Mono<Integer> testMonoDoOnErrorClassOnErrorComplete() {
    -    return Mono.just(1).doOnError(IllegalArgumentException.class, e -> {}).onErrorComplete();
    +    return Mono.just(1).onErrorComplete().doOnError(IllegalArgumentException.class, e -> {});
       }

why didn't the @BeforeTemplate match the statement .doOnError(IllegalArgumentException.class, e -> {})

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The signature of that particular overload is:

public final <E extends Throwable> Mono<T> doOnError(Class<E> exceptionType, final Consumer<? super E> onError) {

My change introduces a similar type constraint involving E extends Throwable to appease the type matching.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AHA! Makes sense; thanks a ton 💡

Copy link
Member

@Stephan202 Stephan202 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added a commit. Suggested commit message:

Extend `{Flux,Mono}OnErrorComplete` Refaster rules (#1939)

As with #1938, I'd like to wrap up and merge #1927 #1942 before this one, so that we stop seeing the Error Prone compatibility check failure on master.

Comment on lines 1643 to 1654
/** Calling {@link Mono#doOnError(Consumer)} after {@link Mono#onErrorComplete()} is redundant. */
static final class MonoDoOnErrorOnErrorComplete<T> {
@BeforeTemplate
Mono<T> before(Mono<T> mono, Consumer<? super Throwable> onError) {
return mono.onErrorComplete().doOnError(onError);
}

@AfterTemplate
Mono<T> after(Mono<T> mono, Consumer<? super Throwable> onError) {
return mono.doOnError(onError).onErrorComplete();
}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We're trying to make sure that Refaster rules are behavior preserving. While this rule and the ones below may rewrite the code in a way that was intended, it does change behavior. I'm in favour of doing what we do elsewhere: just drop the redundant operators. Users that meant the other behavior can manually update the code.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense 🧠 👍

return Mono.just(1).onErrorComplete().doOnError(e -> {});
}

Mono<Integer> testMonoDoOnErrorClassOnErrorComplete() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's because of the specific signature of this doOnError overload; I'll push a fix. 👍

@BeforeTemplate
Mono<T> before(
Mono<T> mono, Class<? extends Throwable> clazz, Consumer<? super Throwable> onError) {
return mono.onErrorComplete().doOnError(clazz, onError);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's also a third doOnError overload; will add support.

@Stephan202 Stephan202 added this to the 0.27.0 milestone Oct 31, 2025
@github-actions
Copy link

Looks good. No mutations were possible for these changes.
Mutation testing report by Pitest. Review any surviving mutants by inspecting the line comments under Files changed.

@Stephan202 Stephan202 changed the title Introduce redundant Publisher#doOnError Refaster rules Extend {Flux,Mono}OnErrorComplete Refaster rules Oct 31, 2025
@mohamedsamehsalah
Copy link
Contributor Author

Thanks @Stephan202 🙏

@Stephan202 Stephan202 force-pushed the mohamedsamehsalah/do-on-error branch from 2da97d1 to 0ef65ec Compare November 11, 2025 21:21
@sonarqubecloud
Copy link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Development

Successfully merging this pull request may close these issues.

3 participants