Skip to content

Fixes an issue with the contextDiagnostic being registered multiple times#25

Merged
rieckpil merged 1 commit intoPragmaTech-GmbH:mainfrom
timbrueckner:handle-multiple-refresh-events-in-context-diagnostic-initializer
Sep 18, 2025
Merged

Fixes an issue with the contextDiagnostic being registered multiple times#25
rieckpil merged 1 commit intoPragmaTech-GmbH:mainfrom
timbrueckner:handle-multiple-refresh-events-in-context-diagnostic-initializer

Conversation

@timbrueckner
Copy link
Copy Markdown
Contributor

This pull request fixes the issue which caused the contextDiagnostic bean to be registered twice if more than one ContextRefreshedEvent was handled in ContextDiagnosticApplicationInitializer.

This fix changes the registration to only react to the main (parent) application context.

… only in parent context and prevent duplicate registration
@sonarqubecloud
Copy link
Copy Markdown

.getBeanFactory()
.registerSingleton("contextDiagnostic", completedDiagnostic);
LOG.debug("Context Diagnostic Completed: {}", completedDiagnostic);
if (event instanceof ContextRefreshedEvent contextEvent) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

looks like you should check parent before call ContextDiagnostic.started() in line 20

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The change @timbrueckner introduced in line 24 if(contextEvent.getApplicationContext().getParent() == null should do the trick now or do you mean there needs to be another parent check (@pavlickm)?

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

i mean that you shouldn't start ContextDiagnostic in line 20 if parent is not null because otherway you may start many ContextDiagnostic , but complete ony one and finally results may be vary

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@timbrueckner @rieckpil
I implemented the same validation and initially did it the way you've described it, but later found it too complex to understand. Do you think it might make sense to wrap this validation in an "ensureContextNotExist" method or something similar to make the code easier to read? What do you think?

Copy link
Copy Markdown
Contributor

@rieckpil rieckpil Sep 18, 2025

Choose a reason for hiding this comment

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

I will integrate it as is, to fix the current issue of the duplicate bean.

There are still some cases where this diagnostic isn't working properly and still needs some additional work.

@rieckpil rieckpil merged commit 769b01d into PragmaTech-GmbH:main Sep 18, 2025
6 checks passed
rieckpil pushed a commit that referenced this pull request Sep 18, 2025
@timbrueckner timbrueckner deleted the handle-multiple-refresh-events-in-context-diagnostic-initializer branch September 20, 2025 06:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants