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

NullPointer Check fails when used with Testcontainers #323

Closed
idotobi opened this issue Dec 6, 2022 · 2 comments · Fixed by #334
Closed

NullPointer Check fails when used with Testcontainers #323

idotobi opened this issue Dec 6, 2022 · 2 comments · Fixed by #334
Milestone

Comments

@idotobi
Copy link

idotobi commented Dec 6, 2022

When trying to setup testcontainers in a project I ran into a problem with slf4j-test.

It seems that while testcontainers starts a container it creates a log event with the message being null.
This causes the check in line 409

LoggingEvent(
final Optional<TestLogger> creatingLogger,
final Level level,
final Map<String, String> mdc,
final Optional<Marker> marker,
final Optional<Throwable> throwable,
final String message,
final Object... arguments) {
super();
this.creatingLogger = creatingLogger;
this.level = checkNotNull(level);
this.mdc = ImmutableMap.copyOf(mdc);
this.marker = checkNotNull(marker);
this.throwable = checkNotNull(throwable);
this.message = checkNotNull(message);

to fail with the following stacktrace:

Caused by: java.lang.NullPointerException
	at com.google.common.base.Preconditions.checkNotNull(Preconditions.java:889)
	at com.github.valfirst.slf4jtest.LoggingEvent.<init>(LoggingEvent.java:409)
	at com.github.valfirst.slf4jtest.TestLogger.addLoggingEvent(TestLogger.java:448)
	at com.github.valfirst.slf4jtest.TestLogger.log(TestLogger.java:432)
	at com.github.valfirst.slf4jtest.TestLogger.log(TestLogger.java:409)
	at com.github.valfirst.slf4jtest.TestLogger.debug(TestLogger.java:170)
	at org.testcontainers.images.builder.ImageFromDockerfile$1.onNext(ImageFromDockerfile.java:106)
	at org.testcontainers.images.builder.ImageFromDockerfile$1.onNext(ImageFromDockerfile.java:98)
	at org.testcontainers.shaded.com.github.dockerjava.core.exec.AbstrAsyncDockerCmdExec$1.onNext(AbstrAsyncDockerCmdExec.java:41)
	at org.testcontainers.shaded.com.github.dockerjava.core.DefaultInvocationBuilder$JsonSink.accept(DefaultInvocationBuilder.java:315)
	at org.testcontainers.shaded.com.github.dockerjava.core.DefaultInvocationBuilder$JsonSink.accept(DefaultInvocationBuilder.java:298)
	at org.testcontainers.shaded.com.github.dockerjava.core.DefaultInvocationBuilder.lambda$executeAndStream$1(DefaultInvocationBuilder.java:275)
	at java.base/java.lang.Thread.run(Thread.java:833)

When I remove slf4j-test as a dependency the container starts up as expected.
Since I would expect the presence of slf4j-test not to have any impact on the general flow of a program I think this might be a bug in slf4j-test rather than testcontainers but you can judge this better than me 😅 .

@valfirst
Copy link
Owner

valfirst commented Dec 6, 2022

@idotobi could you please provide Short, Self Contained, Correct (Compilable), Example to reproduce the issue?

@josephw
Copy link

josephw commented Dec 15, 2022

Reproduction is fairly simple:

import org.slf4j.LoggerFactory;

public class LogNullTest {
    public static void main(String[] args) {
        LoggerFactory.getLogger(LogNullTest.class).info(null);
    }
}

with slf4j-test causes:

java.lang.NullPointerException
	at com.google.common.base.Preconditions.checkNotNull(Preconditions.java:878)
	at com.github.valfirst.slf4jtest.LoggingEvent.<init>(LoggingEvent.java:409)

whereas (e.g.) slf4j-simple logs:

[main] INFO LogNullTest - null

This seems like a bug in testcontainers, but other implementations accept it, and the SLF4J documentation for Logger doesn't specify whether or not null can be passed.

@valfirst valfirst added this to the 2.8.1 milestone Jan 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants