Skip to content

Commit 2c0edfd

Browse files
committed
Merge branch '3.0.x'
Closes gh-35221
2 parents 3287e61 + 67abe3f commit 2c0edfd

File tree

2 files changed

+21
-2
lines changed
  • spring-boot-project/spring-boot-devtools/src

2 files changed

+21
-2
lines changed

spring-boot-project/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/restart/MainMethod.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2019 the original author or authors.
2+
* Copyright 2012-2023 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -40,7 +40,9 @@ class MainMethod {
4040
}
4141

4242
private Method getMainMethod(Thread thread) {
43-
for (StackTraceElement element : thread.getStackTrace()) {
43+
StackTraceElement[] stackTrace = thread.getStackTrace();
44+
for (int i = stackTrace.length - 1; i >= 0; i--) {
45+
StackTraceElement element = stackTrace[i];
4446
if ("main".equals(element.getMethodName())) {
4547
Method method = getMainMethod(element);
4648
if (method != null) {

spring-boot-project/spring-boot-devtools/src/test/java/org/springframework/boot/devtools/restart/MainMethodTests.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,14 @@ void validMainMethod() throws Exception {
5656
assertThat(method.getDeclaringClassName()).isEqualTo(this.actualMain.getDeclaringClass().getName());
5757
}
5858

59+
@Test // gh-35214
60+
void nestedMainMethod() throws Exception {
61+
MainMethod method = new TestThread(Nested::main).test();
62+
Method nestedMain = Nested.class.getMethod("main", String[].class);
63+
assertThat(method.getMethod()).isEqualTo(nestedMain);
64+
assertThat(method.getDeclaringClassName()).isEqualTo(nestedMain.getDeclaringClass().getName());
65+
}
66+
5967
@Test
6068
void missingArgsMainMethod() {
6169
assertThatIllegalStateException().isThrownBy(() -> new TestThread(MissingArgs::main).test())
@@ -114,6 +122,15 @@ private static void someOtherMethod() {
114122

115123
}
116124

125+
public static class Nested {
126+
127+
public static void main(String... args) {
128+
mainMethod.set(new MainMethod());
129+
Valid.main(args);
130+
}
131+
132+
}
133+
117134
public static class MissingArgs {
118135

119136
public static void main() {

0 commit comments

Comments
 (0)