Skip to content

Commit

Permalink
Fix OSGiWeavingAdaptor::defineClass
Browse files Browse the repository at this point in the history
Call ClassLoaderWeavingAdaptor::defineClass.

TODO: For 2024-06 (4.32), make ClassLoaderWeavingAdaptor::defineClass
protected and call it via super instead of duplicating class definition
code or hackily calling a private method via reflection.

Fixes #57.
  • Loading branch information
kriegaex committed Apr 4, 2024
1 parent 0383ce5 commit 5cdda63
Showing 1 changed file with 7 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -159,15 +159,16 @@ private void defineClass(final ClassLoader loader, final String name,
debug("generating class '" + name + "'");

try {
// TODO: For 2024-06 (4.32), make ClassLoaderWeavingAdaptor::defineClass protected and call it via super
// from here instead of duplicating class definition code or hackily calling a private method
if (defineClassMethod == null) {
defineClassMethod = ClassLoader.class.getDeclaredMethod(
"defineClass",
String.class, bytes.getClass(),
int.class, int.class);
defineClassMethod = ClassLoaderWeavingAdaptor.class.getDeclaredMethod(
"defineClass",
ClassLoader.class, String.class, byte[].class
);
}
defineClassMethod.setAccessible(true);
clazz = defineClassMethod.invoke(loader, name,
bytes, 0, bytes.length);
clazz = defineClassMethod.invoke(this, loader, name, bytes);
} catch (final InvocationTargetException e) {
if (e.getTargetException() instanceof LinkageError) {
warn("define generated class failed", e.getTargetException());
Expand Down

0 comments on commit 5cdda63

Please sign in to comment.