From 5cdda638ff84fa3713c40da9cb45d0549a2167a4 Mon Sep 17 00:00:00 2001 From: Alexander Kriegisch Date: Thu, 4 Apr 2024 12:26:49 +0200 Subject: [PATCH] Fix OSGiWeavingAdaptor::defineClass 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. --- .../aspectj/loadtime/OSGiWeavingAdaptor.java | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/org.eclipse.equinox.weaving.aspectj/src/org/eclipse/equinox/weaving/aspectj/loadtime/OSGiWeavingAdaptor.java b/org.eclipse.equinox.weaving.aspectj/src/org/eclipse/equinox/weaving/aspectj/loadtime/OSGiWeavingAdaptor.java index 549ad981e..bebf6e8c7 100644 --- a/org.eclipse.equinox.weaving.aspectj/src/org/eclipse/equinox/weaving/aspectj/loadtime/OSGiWeavingAdaptor.java +++ b/org.eclipse.equinox.weaving.aspectj/src/org/eclipse/equinox/weaving/aspectj/loadtime/OSGiWeavingAdaptor.java @@ -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());