aboutsummaryrefslogtreecommitdiffstats
path: root/org.aspectj.ajdt.core
diff options
context:
space:
mode:
authorAlexander Kriegisch <Alexander@Kriegisch.name>2023-10-05 11:22:13 +0700
committerAlexander Kriegisch <Alexander@Kriegisch.name>2023-10-05 11:22:13 +0700
commit39c5da6eb973ce31ad90c30c1b4156988d6b9bf8 (patch)
treea9e84d5c5f234d1ceb980343d7c2adda6aa4229e /org.aspectj.ajdt.core
parent78ee9cebd81f1496d69bd0c933e3ee16fa02a96f (diff)
downloadaspectj-39c5da6eb973ce31ad90c30c1b4156988d6b9bf8.tar.gz
aspectj-39c5da6eb973ce31ad90c30c1b4156988d6b9bf8.zip
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>
Diffstat (limited to 'org.aspectj.ajdt.core')
-rw-r--r--org.aspectj.ajdt.core/src/test/java/org/aspectj/tools/ajc/AjcTestCase.java7
1 files 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);