Skip to content

SpringProfile arbiter fails without a Spring's environment #1783

Closed
@ppkarwasz

Description

@ppkarwasz

Description

In a Spring Boot application Log4j Core is initialized at least twice:

  • the first initialization is the static Log4j Core initialization (Spring's Environment is not available yet),
  • the second initialization is performed programmatically by Spring Boot as soon as it creates an Environment. It can use the same configuration file as the first one.

On the other hand the builder of SpringProfileArbiter returns null if no Spring Environment is present, which causes (handled) NullPointerExceptions in AbstractConfiguration#processConditionals or AbstractConfiguration#processSelect.

Since the arbiter logic itself accepts a null environment, we should remove the following null-check:

environment = (Environment) loggerContext.getObject(Log4j2SpringBootLoggingSystem.ENVIRONMENT_KEY);
if (environment == null) {
    LOGGER.warn("Cannot create Arbiter, no Spring Environment provided");
    return null;
}

The fix should be propagated to the Spring Boot project.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugIncorrect, unexpected, or unintended behavior of existing code

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions