Skip to content

Add XmlService classloader fallback for ServiceLoader discovery#12237

Open
gnodet wants to merge 1 commit into
masterfrom
fix/xmlservice-classloader-fallback
Open

Add XmlService classloader fallback for ServiceLoader discovery#12237
gnodet wants to merge 1 commit into
masterfrom
fix/xmlservice-classloader-fallback

Conversation

@gnodet
Copy link
Copy Markdown
Contributor

@gnodet gnodet commented Jun 4, 2026

Summary

Extracted from #11742 (by @arturobernalg) to keep the classloader fix separate from the namespace-preservation fix (#11715).

When the thread context classloader cannot see the XmlService provider (e.g. in isolated plugin classloaders), the ServiceLoader.load(XmlService.class) call fails with IllegalStateException("No XmlService implementation found").

This change:

  • Tries XmlService.class.getClassLoader() first — this is the core realm classloader which always sees the provider
  • Falls back to the TCCL if the class's own classloader doesn't find it
  • The order (class CL → TCCL) is intentional: XmlService lives in the API module, and its classloader reliably sees the impl/maven-xml provider through Maven's core realm. The TCCL may be a plugin classrealm or an isolated classloader that cannot.

Test plan

  • XmlServiceLoadingTest verifies discovery works when TCCL is an empty URLClassLoader that cannot see the provider

Claude Code on behalf of Guillaume Nodet

Co-authored-by: Arturo Bernal abernal@apache.org

When the thread context classloader cannot see the XmlService
provider (e.g. in plugin classloaders), fall back to loading
via XmlService's own classloader. This prevents
IllegalStateException("No XmlService implementation found")
in environments where the TCCL is isolated.

Co-authored-by: Arturo Bernal <abernal@apache.org>
gnodet added a commit to arturobernalg/maven that referenced this pull request Jun 4, 2026
- Remove XmlService classloader fallback (extracted to PR apache#12237)
- Use MavenModelVersion to compute the minimum model version
  instead of hardcoding 4.0.0 as the fallback
- Align namespace/schemaLocation format strings with
  TransformerSupport conventions

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
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.

2 participants