commit
2c0edfd0b5
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2012-2019 the original author or authors.
|
||||
* Copyright 2012-2023 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
|
@ -40,7 +40,9 @@ class MainMethod {
|
|||
}
|
||||
|
||||
private Method getMainMethod(Thread thread) {
|
||||
for (StackTraceElement element : thread.getStackTrace()) {
|
||||
StackTraceElement[] stackTrace = thread.getStackTrace();
|
||||
for (int i = stackTrace.length - 1; i >= 0; i--) {
|
||||
StackTraceElement element = stackTrace[i];
|
||||
if ("main".equals(element.getMethodName())) {
|
||||
Method method = getMainMethod(element);
|
||||
if (method != null) {
|
||||
|
|
|
|||
|
|
@ -56,6 +56,14 @@ class MainMethodTests {
|
|||
assertThat(method.getDeclaringClassName()).isEqualTo(this.actualMain.getDeclaringClass().getName());
|
||||
}
|
||||
|
||||
@Test // gh-35214
|
||||
void nestedMainMethod() throws Exception {
|
||||
MainMethod method = new TestThread(Nested::main).test();
|
||||
Method nestedMain = Nested.class.getMethod("main", String[].class);
|
||||
assertThat(method.getMethod()).isEqualTo(nestedMain);
|
||||
assertThat(method.getDeclaringClassName()).isEqualTo(nestedMain.getDeclaringClass().getName());
|
||||
}
|
||||
|
||||
@Test
|
||||
void missingArgsMainMethod() {
|
||||
assertThatIllegalStateException().isThrownBy(() -> new TestThread(MissingArgs::main).test())
|
||||
|
|
@ -114,6 +122,15 @@ class MainMethodTests {
|
|||
|
||||
}
|
||||
|
||||
public static class Nested {
|
||||
|
||||
public static void main(String... args) {
|
||||
mainMethod.set(new MainMethod());
|
||||
Valid.main(args);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static class MissingArgs {
|
||||
|
||||
public static void main() {
|
||||
|
|
|
|||
Loading…
Reference in New Issue