Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SpringProfile arbiter fails without a Spring's environment #1783

Closed
ppkarwasz opened this issue Sep 10, 2023 · 0 comments · Fixed by #1836
Closed

SpringProfile arbiter fails without a Spring's environment #1783

ppkarwasz opened this issue Sep 10, 2023 · 0 comments · Fixed by #1836
Labels
bug Incorrect, unexpected, or unintended behavior of existing code
Milestone

Comments

@ppkarwasz
Copy link
Contributor

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.

@ppkarwasz ppkarwasz added the bug Incorrect, unexpected, or unintended behavior of existing code label Sep 10, 2023
@ppkarwasz ppkarwasz added this to the 2.x milestone Oct 5, 2023
ppkarwasz added a commit to ppkarwasz/logging-log4j2 that referenced this issue Oct 6, 2023
Most Log4j configurations in Spring Boot are used twice: with no
environment and with an environment present. Therefore the Spring Boot
arbiter should not fail with no environment.

Fixes apache#1783.
ppkarwasz added a commit to ppkarwasz/logging-log4j2 that referenced this issue Oct 6, 2023
Most Log4j configurations in Spring Boot are used twice: with no
environment and with an environment present. Therefore the Spring Boot
arbiter should not fail with no environment.

Fixes apache#1783.
ppkarwasz added a commit that referenced this issue Oct 6, 2023
Most Log4j configurations in Spring Boot are used twice: with no
environment and with an environment present. Therefore the Spring Boot
arbiter should not fail with no environment.

Fixes #1783.
@ppkarwasz ppkarwasz modified the milestones: 2.x, 2.22.0, 2.21.0 Nov 13, 2023
@ppkarwasz ppkarwasz reopened this Mar 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Incorrect, unexpected, or unintended behavior of existing code
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant