Skip to content

Exclude ByteBuddy classloaders from plugin class patching#672

Merged
skybber merged 1 commit intoHotswapProjects:masterfrom
Artur-:bytebuddy
Feb 15, 2026
Merged

Exclude ByteBuddy classloaders from plugin class patching#672
skybber merged 1 commit intoHotswapProjects:masterfrom
Artur-:bytebuddy

Conversation

@Artur-
Copy link
Copy Markdown
Contributor

@Artur- Artur- commented Feb 15, 2026

ClassLoaderDefineClassPatcher.isPatchAvailable() did not exclude ByteBuddy's synthetic classloaders (ByteArrayClassLoader and JavaDispatcher$DynamicClassLoader). When Mockito's inline mock maker uses ByteBuddy to retransform classes, HotswapAgent would patch all plugin classes (including inner classes like
VaadinPlugin$UpdateRoutesCommand) into ByteBuddy's classloaders.

This causes IllegalAccessError because the plugin's inner classes end up in a different classloader than the plugin class itself:

"failed to access class VaadinPlugin$UpdateRoutesCommand from class
VaadinPlugin (VaadinPlugin$UpdateRoutesCommand is in unnamed module
of loader ByteArrayClassLoader; VaadinPlugin is in unnamed module
of loader 'app')"

The fix adds ByteBuddy's ByteArrayClassLoader and
JavaDispatcher$DynamicClassLoader to the exclusion list, matching the existing exclusions for JDK's DelegatingClassLoader. These synthetic classloaders should never receive HotswapAgent plugin class definitions.

Fixes #671

ClassLoaderDefineClassPatcher.isPatchAvailable() did not exclude
ByteBuddy's synthetic classloaders (ByteArrayClassLoader and
JavaDispatcher$DynamicClassLoader). When Mockito's inline mock maker
uses ByteBuddy to retransform classes, HotswapAgent would patch all
plugin classes (including inner classes like
VaadinPlugin$UpdateRoutesCommand) into ByteBuddy's classloaders.

This causes IllegalAccessError because the plugin's inner classes end
up in a different classloader than the plugin class itself:

  "failed to access class VaadinPlugin$UpdateRoutesCommand from class
   VaadinPlugin (VaadinPlugin$UpdateRoutesCommand is in unnamed module
   of loader ByteArrayClassLoader; VaadinPlugin is in unnamed module
   of loader 'app')"

The fix adds ByteBuddy's ByteArrayClassLoader and
JavaDispatcher$DynamicClassLoader to the exclusion list, matching the
existing exclusions for JDK's DelegatingClassLoader. These synthetic
classloaders should never receive HotswapAgent plugin class
definitions.
@skybber skybber merged commit 7fc5e6d into HotswapProjects:master Feb 15, 2026
1 check passed
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.

IllegalAccessError when using HotswapAgent with Mockito/ByteBuddy — plugin classes patched into ByteBuddy classloaders

2 participants