Skip to content
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

GH-2967: Some minor improvements in RetryableTopicAnnotationProcessor #2967

Conversation

NathanQingyangXu
Copy link
Contributor

@NathanQingyangXu NathanQingyangXu commented Dec 22, 2023

some minor and easily verified code quality improvements.
after the changes, the warnings in IDEA decreased from 16 to 5.

@NathanQingyangXu NathanQingyangXu force-pushed the improvement-on-RetryableTopicAnnotationProcessor branch from 626bd95 to 930bbee Compare December 22, 2023 02:58
if (concurrency != null) {
builder.concurrency(concurrency);
}
return builder.create(getKafkaTemplate(resolveExpressionAsString(annotation.kafkaTemplate(), "kafkaTemplate"), topics));
Copy link
Contributor Author

Choose a reason for hiding this comment

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

there are many loose ends regarding nullness safety net. Not sure why there is no usage of the following two entries in the package-info.java within the package of annotation:

@org.springframework.lang.NonNullApi
@org.springframework.lang.NonNullFields

if we added them, many NPE issues in this package would be better exposed.

Copy link
Contributor

@sobychacko sobychacko Dec 22, 2023

Choose a reason for hiding this comment

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

Sure. Feel free to send another PR with that change if you are up to it.

@@ -200,7 +210,6 @@ private EndpointHandlerMethod getDltProcessor(Method listenerMethod, Object bean
.orElse(RetryTopicConfigurer.DEFAULT_DLT_HANDLER);
}

@SuppressWarnings("deprecation")
Copy link
Contributor Author

Choose a reason for hiding this comment

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

seems leftover of previous JDK. In JDK17, I saw no compiling warnings after the removal of it.

if (this.beanFactory != null && this.beanFactory instanceof ConfigurableBeanFactory) {
return ((ConfigurableBeanFactory) this.beanFactory).resolveEmbeddedValue(value);
if (this.beanFactory instanceof ConfigurableBeanFactory cbf) {
return cbf.resolveEmbeddedValue(value);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

of course, the original nullness checking is unnecessary for instanceof has included it already.

if (this.expressionContext != null) {
String resolved = resolve(value);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

seems the resolved is only used within the if block, so it makes more sense to move it within, so when expressionContext is null, no unnecessary overhead will incur.

@NathanQingyangXu NathanQingyangXu changed the title some minor improvements on RetryableTopicAnnotationProcessor GH-2967: some minor improvements in RetryableTopicAnnotationProcessor Dec 22, 2023
@NathanQingyangXu NathanQingyangXu changed the title GH-2967: some minor improvements in RetryableTopicAnnotationProcessor GH-2967: Some minor improvements in RetryableTopicAnnotationProcessor Dec 22, 2023
policy.setMultiplier(multiplier);
policy.setMaxInterval(max > min ? max : ExponentialBackOffPolicy.DEFAULT_MAX_INTERVAL);
if (max != null && min != null && max > min) {
Copy link
Contributor

@sobychacko sobychacko Dec 22, 2023

Choose a reason for hiding this comment

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

What will max be if max <= min? In this case, currently, we set it to ExponentialBackOffPolicy.DEFAULT_MAX_INTERVAL. The new code seems to change that semantics.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good comment! Below is the relevant code snippet:

public class ExponentialBackOffPolicy implements SleepingBackOffPolicy<ExponentialBackOffPolicy> {
        ... ...
	/**
	 * The maximum value of the backoff period in milliseconds.
	 */
	private long maxInterval = DEFAULT_MAX_INTERVAL;

so regardless of whether we set the same default value or not in RetryableTopicAnnotationProcessor above, the end result is the same. I avoided duplication to make it more elegant.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Let me know whether we need to revert back old behaviour. I am perfectly fine with either way.

Copy link
Contributor

Choose a reason for hiding this comment

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

But don't we need to set that value in RetryableTopicAnnotationProcessor? Otherwise, how does this max variable get to that value? I am fine with cleaning it up if it is redundant. I am trying to see the connection.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

As I showed above, the policy class will set the fields to default values already just after the instance was initiated but before constructor is invoked, so after the default constructor was invoked, we have ended up with valid state already.

Am I missing something here?

Copy link
Contributor

Choose a reason for hiding this comment

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

Ok, I got it. Thanks for the explanation.

@sobychacko sobychacko merged commit 7cbef70 into spring-projects:main Dec 22, 2023
2 checks passed
@sobychacko sobychacko added this to the 3.1.2 milestone Dec 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants