Skip to content

fix: Set TCCL before initialising A2AHttpClientFactory#873

Closed
kabir wants to merge 1 commit into
a2aproject:mainfrom
kabir:processor-tccl
Closed

fix: Set TCCL before initialising A2AHttpClientFactory#873
kabir wants to merge 1 commit into
a2aproject:mainfrom
kabir:processor-tccl

Conversation

@kabir
Copy link
Copy Markdown
Collaborator

@kabir kabir commented May 12, 2026

It has a ServiceLoader using the TCCL to find clients

It has a ServiceLoader using the TCCL to find clients
Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces a Thread Context Class Loader (TCCL) swap within the BasePushNotificationSender constructor to ensure that A2AHttpClientFactory is initialized correctly. However, the review feedback points out that this implementation is fragile because it relies on BasePushNotificationSender being the first class to trigger the factory's static initialization. It is recommended to refactor the service discovery logic within A2AHttpClientFactory itself to use a specific class loader, ensuring providers are consistently found regardless of the calling context.

Comment on lines +61 to +67
ClassLoader originalTccl = Thread.currentThread().getContextClassLoader();
try {
Thread.currentThread().setContextClassLoader(BasePushNotificationSender.class.getClassLoader());
this.httpClient = A2AHttpClientFactory.create();
} finally {
Thread.currentThread().setContextClassLoader(originalTccl);
}
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.

high

This TCCL (Thread Context Class Loader) swap is fragile because it depends on the initialization order of A2AHttpClientFactory. Since the factory's PROVIDERS list is initialized in a static block, this logic only works if BasePushNotificationSender is the first class to trigger the factory's loading. If another component accesses the factory first without this TCCL swap, the factory will be initialized with an empty provider list and remain broken for the life of the application. The service discovery should be made robust within A2AHttpClientFactory itself, for example by using ServiceLoader.load(A2AHttpClientProvider.class, A2AHttpClientProvider.class.getClassLoader()) to ensure the providers are always found regardless of the current thread's context.

@kabir kabir closed this May 12, 2026
@kabir kabir deleted the processor-tccl branch May 12, 2026 19:25
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.

1 participant