From 984dc1d58f449b71b69cd8a0067d654e64380118 Mon Sep 17 00:00:00 2001 From: Andy Wilkinson Date: Tue, 13 Jun 2023 13:08:09 +0100 Subject: [PATCH] Allow package-private main classes to be used with Devtools Fixes gh-35858 --- .../src/intTest/java/com/example/DevToolsTestApplication.java | 2 +- .../springframework/boot/devtools/restart/RestartLauncher.java | 3 ++- src/checkstyle/checkstyle-suppressions.xml | 1 + 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/spring-boot-project/spring-boot-devtools/src/intTest/java/com/example/DevToolsTestApplication.java b/spring-boot-project/spring-boot-devtools/src/intTest/java/com/example/DevToolsTestApplication.java index 5dfae2d5db..b5f045d53b 100644 --- a/spring-boot-project/spring-boot-devtools/src/intTest/java/com/example/DevToolsTestApplication.java +++ b/spring-boot-project/spring-boot-devtools/src/intTest/java/com/example/DevToolsTestApplication.java @@ -21,7 +21,7 @@ import org.springframework.boot.builder.SpringApplicationBuilder; import org.springframework.boot.web.context.WebServerPortFileWriter; @SpringBootApplication -public class DevToolsTestApplication { +class DevToolsTestApplication { public static void main(String[] args) { new SpringApplicationBuilder(DevToolsTestApplication.class).listeners(new WebServerPortFileWriter(args[0])) diff --git a/spring-boot-project/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/restart/RestartLauncher.java b/spring-boot-project/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/restart/RestartLauncher.java index 9d81002496..d7d3328f80 100644 --- a/spring-boot-project/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/restart/RestartLauncher.java +++ b/spring-boot-project/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/restart/RestartLauncher.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2020 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. @@ -46,6 +46,7 @@ class RestartLauncher extends Thread { try { Class mainClass = Class.forName(this.mainClassName, false, getContextClassLoader()); Method mainMethod = mainClass.getDeclaredMethod("main", String[].class); + mainMethod.setAccessible(true); mainMethod.invoke(null, new Object[] { this.args }); } catch (Throwable ex) { diff --git a/src/checkstyle/checkstyle-suppressions.xml b/src/checkstyle/checkstyle-suppressions.xml index ed4e5868c7..37a0a62428 100644 --- a/src/checkstyle/checkstyle-suppressions.xml +++ b/src/checkstyle/checkstyle-suppressions.xml @@ -59,6 +59,7 @@ +