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

LoggingSystem calls with Log4J throws NullPointerException #24163

Closed
underbell opened this issue Nov 16, 2020 · 4 comments
Closed

LoggingSystem calls with Log4J throws NullPointerException #24163

underbell opened this issue Nov 16, 2020 · 4 comments
Assignees
Milestone

Comments

@underbell
Copy link

@underbell underbell commented Nov 16, 2020

build.gradle

plugins {
    id 'org.springframework.boot' version '2.4.0'
    id 'io.spring.dependency-management' version '1.0.10.RELEASE'
    id 'java'
}

configurations {
        compileOnly {
            extendsFrom annotationProcessor
        }
        // exclude logback logging
        compile.exclude module: 'spring-boot-starter-logging'
}

dependencies {
        implementation 'org.springframework.boot:spring-boot-starter-actuator'
        implementation 'org.springframework.boot:spring-boot-starter-web'
        implementation 'org.springframework.boot:spring-boot-starter-log4j2'
        ...
}

Build and start are OK, but an error occurs when the following command is executed.
java -Djarmode=layertools -jar application.jar extract

log

INFO[0148] Running: [/bin/sh -c java -Djarmode=layertools -jar application.jar extract] 
Exception in thread "main" java.lang.reflect.InvocationTargetException
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:566)
	at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:49)
	at org.springframework.boot.loader.Launcher.launch(Launcher.java:107)
	at org.springframework.boot.loader.Launcher.launch(Launcher.java:58)
	at org.springframework.boot.loader.JarLauncher.main(JarLauncher.java:88)
Caused by: java.lang.ExceptionInInitializerError
	at org.apache.commons.logging.LogAdapter$Log4jAdapter.createLog(LogAdapter.java:122)
	at org.apache.commons.logging.LogAdapter.createLog(LogAdapter.java:89)
	at org.apache.commons.logging.LogFactory.getLog(LogFactory.java:67)
	at org.apache.commons.logging.LogFactory.getLog(LogFactory.java:59)
	at org.springframework.core.io.support.SpringFactoriesLoader.<clinit>(SpringFactoriesLoader.java:71)
	at org.springframework.boot.loader.jarmode.JarModeLauncher.main(JarModeLauncher.java:39)
	... 8 more
Caused by: java.lang.NullPointerException
	at org.springframework.core.io.support.SpringFactoriesLoader.loadSpringFactories(SpringFactoriesLoader.java:136)
	at org.springframework.core.io.support.SpringFactoriesLoader.loadFactoryNames(SpringFactoriesLoader.java:132)
	at org.springframework.core.io.support.SpringFactoriesLoader.loadFactories(SpringFactoriesLoader.java:101)
	at org.springframework.boot.logging.LoggingSystemFactory.lambda$fromSpringFactories$0(LoggingSystemFactory.java:44)
	at org.springframework.boot.logging.DelegatingLoggingSystemFactory.getLoggingSystem(DelegatingLoggingSystemFactory.java:41)
	at org.springframework.boot.logging.LoggingSystem.get(LoggingSystem.java:159)
	at org.springframework.boot.logging.log4j2.SpringBootConfigurationFactory.getConfiguration(SpringBootConfigurationFactory.java:60)
	at org.apache.logging.log4j.core.config.ConfigurationFactory$Factory.getConfiguration(ConfigurationFactory.java:551)
	at org.apache.logging.log4j.core.config.ConfigurationFactory$Factory.getConfiguration(ConfigurationFactory.java:475)
	at org.apache.logging.log4j.core.config.ConfigurationFactory.getConfiguration(ConfigurationFactory.java:323)
	at org.apache.logging.log4j.core.LoggerContext.reconfigure(LoggerContext.java:687)
	at org.apache.logging.log4j.core.LoggerContext.reconfigure(LoggerContext.java:708)
	at org.apache.logging.log4j.core.LoggerContext.start(LoggerContext.java:263)
	at org.apache.logging.log4j.core.impl.Log4jContextFactory.getContext(Log4jContextFactory.java:153)
	at org.apache.logging.log4j.core.impl.Log4jContextFactory.getContext(Log4jContextFactory.java:45)
	at org.apache.logging.log4j.LogManager.getContext(LogManager.java:194)
	at org.apache.commons.logging.LogAdapter$Log4jLog.<clinit>(LogAdapter.java:155)
	... 14 more
@snicoll
Copy link
Member

@snicoll snicoll commented Nov 16, 2020

Thanks for the report but a partial snippet from your build is not helpful. Can you please attach a small sample that we can run to reproduce this problem? You can do so by attaching a zip to this issue or sharing a link to a GitHub repository.

@underbell
Copy link
Author

@underbell underbell commented Nov 16, 2020

Thanks for responding.
This is a demo in which only logging is changed to log4j2 in Spring Initializr.
github : https://github.com/underbell/log4j2-demo

It does not occur in the case of logback.
Occurs in the case of log4j2.

@snicoll
Copy link
Member

@snicoll snicoll commented Nov 16, 2020

@underbell thank you for the sample and sharing additional details. This is a regression in the way we lookup which LoggingSystem to use on startup.

You can workaround the issue for now by adding an extra system property, i.e.:

java -Djarmode=layertools -Dorg.springframework.boot.logging.LoggingSystem=none -jar application.jar
@snicoll snicoll changed the title layertools extract not working 2.4.0 version NPE using layertools with Log4j2 Nov 16, 2020
@underbell
Copy link
Author

@underbell underbell commented Nov 16, 2020

@snicoll Thanks for your guide.

@philwebb philwebb changed the title NPE using layertools with Log4j2 LoggingSystem calls with Log4J throws NullPointerException Nov 18, 2020
@philwebb philwebb self-assigned this Nov 18, 2020
@philwebb philwebb closed this in 0ce3e7e Nov 18, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
4 participants