Browse Source

AjcTestCase: Make sure main methods can be called in Java 21

Since JDK 21, a public main method of a non-public (e.g. default-scoped)
class can no longer be invoked without making it accessible first.
Because many test sources contain multiple aspects and classes in one
file, this is a frequent use case.

Signed-off-by: Alexander Kriegisch <Alexander@Kriegisch.name>
tags/V1_9_21_M1
Alexander Kriegisch 7 months ago
parent
commit
39c5da6eb9

+ 5
- 2
org.aspectj.ajdt.core/src/test/java/org/aspectj/tools/ajc/AjcTestCase.java View File

@@ -759,8 +759,11 @@ public abstract class AjcTestCase extends TestCase {
Thread.currentThread().setContextClassLoader(sandboxLoader);

Class<?> toRun = sandboxLoader.loadClass(className);
Method mainMethod = toRun.getMethod("main", new Class[] { String[].class });

Method mainMethod = toRun.getMethod("main", String[].class);
// Since JDK 21, a public main method of a non-public (e.g. default-scoped) class can no longer be invoked without
// making it accessible first. Because many test sources contain multiple aspects and classes in one file, this is
// a frequent use case.
mainMethod.setAccessible(true);
mainMethod.invoke(null, new Object[] { args });
} catch (ClassNotFoundException cnf) {
fail("Can't find class: " + className);

Loading…
Cancel
Save