Resttemplate throws a NPE with dependency spring-boot-starter-log4j2 within tests calling RestTemplate construtor.

Repository for reproduce:

https://github.com/mnhock/resttemplate-bug

Simple call the RestConfigurationTest.

If you remove spring-boot-starter-log4j2 dependency from the pom it works.

The problem is that the init of the Logger depends on the SpringProperties as well but is initialized before the localProperties is initialized.

    private static final Log logger = LogFactory.getLog(SpringProperties.class);
    private static final Properties localProperties = new Properties();

I think the problem exists with other files changed in #25151 as well.

Thanks, Martin

Comment From: jhoeller

Where exactly does logger initialization refer back to SpringProperties? Is that somewhere in Boot?

Anyway, the most defensive option is to get rid of logger usage in SpringProperties altogether.

Comment From: snicoll

For the record, this issue has been fixed in Spring Boot as well, see https://github.com/spring-projects/spring-boot/issues/24163