From 39c5da6eb973ce31ad90c30c1b4156988d6b9bf8 Mon Sep 17 00:00:00 2001 From: Alexander Kriegisch Date: Thu, 5 Oct 2023 11:22:13 +0700 Subject: [PATCH] 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 --- .../src/test/java/org/aspectj/tools/ajc/AjcTestCase.java | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/org.aspectj.ajdt.core/src/test/java/org/aspectj/tools/ajc/AjcTestCase.java b/org.aspectj.ajdt.core/src/test/java/org/aspectj/tools/ajc/AjcTestCase.java index e50ea9757..9aec7d947 100644 --- a/org.aspectj.ajdt.core/src/test/java/org/aspectj/tools/ajc/AjcTestCase.java +++ b/org.aspectj.ajdt.core/src/test/java/org/aspectj/tools/ajc/AjcTestCase.java @@ -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); -- 2.39.5