apache / apache/gravitino

[Improvement] Ensure all Capability method calls are made within the correct classloader context

Open
#11,726 0 comments 0 reactions 0 assignees View on GitHub
improvement
Dominant language
Java
Stars
3.2k
Forks
935
Avg merge
1d 16h
Merged PRs (30d)
298

Description

### What would you like to be improved?

## Background

PR #11707 fixed an intermittent `NoClassDefFoundError` caused by
`HiveCatalogCapability.caseSensitiveOnName()` being called outside the
`IsolatedClassLoader.withClassLoader()` boundary. The fix worked around the
issue by removing the compiler-generated synthetic `$1` class.

However, as noted in the PR review, this is a workaround rather than a root fix.

## Root Cause

`CatalogWrapper.capabilities()` returns a `Capability` object loaded by the
catalog's isolated classloader. This object is then used **outside** the
`withClassLoader()` boundary (e.g., in `SchemaNormalizeDispatcher`). Any
`Capability` method implementation that references plugin-jar classes will
trigger a classloader mismatch, causing the JVM to permanently cache a
`NoClassDefFoundError` for the process lifetime.

## Scope of Impact

Any catalog that implements `Capability` methods referencing classes from the
plugin jar (e.g., using `switch-on-enum`, or calling plugin-internal types)
is potentially affected. This is not limited to the Hive catalog.

## Expected Fix

All calls to `Capability` methods should be made within the correct classloader
context, either by:
1. Wrapping `capabilities()` call sites with `withClassLoader()`, or
2. Ensuring `CatalogWrapper` proxies `Capability` method calls through the
isolated classloader automatically.

## References

- PR: #11707
- Related: `CatalogWrapper.capabilities()`, `SchemaNormalizeDispatcher`,
`IsolatedClassLoader.withClassLoader()`

### How should we improve?

_No response_

Contributor guide

Open the contributing guide

Research direction

Start with CatalogWrapper.capabilities(), SchemaNormalizeDispatcher, and IsolatedClassLoader.withClassLoader(), then trace the Capability call sites identified in the issue. Ensure each Capability method call runs in the catalog's isolated classloader context, and verify the NoClassDefFoundError scenario is no longer triggered.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
backend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.