My application has no default configuration file, only profile specific ones (application-profile1.properties, application-profile2.properties, etc.). The user must activate a specific profile to successfully run the application.

To improve usability, I check whether a profile has been activated (using spring.profiles.active or SPRING_PROFILES_ACTIVE) in my main method (before SpringApplication#run). If not, I display an error message and exit.

To improve usability even further, the error message attempts to list the available profiles from which the user must choose. It does so by passing "classpath:application-*.properties" to org.springframework.core.io.support.PathMatchingResourcePatternResolver#getResources to enumerate the available configuration files.

In 3.1 and 3.2 with loaderImplementation=CLASSIC this works but in 3.2 without loaderImplementation=CLASSIC it fails with:

Exception in thread "main" java.lang.reflect.InvocationTargetException
    at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:118)
    at java.base/java.lang.reflect.Method.invoke(Method.java:580)
    at org.springframework.boot.loader.launch.Launcher.launch(Launcher.java:91)
    at org.springframework.boot.loader.launch.Launcher.launch(Launcher.java:53)
    at org.springframework.boot.loader.launch.JarLauncher.main(JarLauncher.java:58)
Caused by: java.io.FileNotFoundException: class path resource [] cannot be resolved to URL because it does not exist
    at org.springframework.core.io.ClassPathResource.getURL(ClassPathResource.java:230)
    at org.springframework.core.io.support.PathMatchingResourcePatternResolver.findPathMatchingResources(PathMatchingResourcePatternResolver.java:574)
    at org.springframework.core.io.support.PathMatchingResourcePatternResolver.getResources(PathMatchingResourcePatternResolver.java:349)
    at com.example.MyApplication.getAvailableProfiles(MyApplication.java:138)
    at com.example.MyApplication.validateProfile(MyApplication.java:121)
    at com.example.MyApplication.main(MyApplication.java:112)
    at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:103)
    ... 4 more

Not sure if this is a regression or intended (and if so how best to achieve my end with the new implementation).

Comment From: philwebb

The following code is enough to trigger the problem. The result should not be null.

ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
System.out.println(classLoader.getResource(""));