Skip to content

Close and unregister plugin classloader when load fails#57

Merged
huangdihd merged 2 commits into
huangdihd:2.2.2-SNAPSHOTfrom
newPlayerAL:fix/plugin-classloader-leak
Jun 1, 2026
Merged

Close and unregister plugin classloader when load fails#57
huangdihd merged 2 commits into
huangdihd:2.2.2-SNAPSHOTfrom
newPlayerAL:fix/plugin-classloader-leak

Conversation

@newPlayerAL

Copy link
Copy Markdown
Contributor

When a plugin fails to load during Class.forName / newInstance (e.g. a bad main class, an exception in the plugin constructor), the PluginClassLoader had already been registered in pluginLoaders (and the dependency list in pluginDependencies) before instantiation was attempted. On failure the exception propagated out without closing the classloader or removing the map entries, leaking the open jar file handle. On Windows this surfaces as "file is in use" when reloading the plugin.

Changes

  • PluginManager.loadPlugin(File) and instantiateAndLoad: wrap the Class.forName / newInstance in try/catch; on failure remove the pluginLoaders and pluginDependencies entries, close() the classloader, then rethrow.
  • Added PluginClassloaderLeakTest: loads a jar whose plugin.yml is valid but whose main points to a non-existent class, asserts the load throws and that no classloader / dependency entry lingers afterwards.
  • Registered the new test in maven-test.yml.

No behavior change on the successful-load path.

@codacy-production

codacy-production Bot commented Jun 1, 2026

Copy link
Copy Markdown

Not up to standards ⛔

NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.

@huangdihd
huangdihd merged commit 166c534 into huangdihd:2.2.2-SNAPSHOT Jun 1, 2026
1 check failed
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