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

NullPointerException using logger org.slf4j:slf4j-log4j12:jar:1.7.21 with testcontainers #375

Closed
islisava opened this issue Jun 19, 2017 · 5 comments
Labels
Milestone

Comments

@islisava
Copy link

From testcontainers documentation:
Testcontainers, and many of the libraries it uses, utilize slf4j for logging. In order to see logs from Testcontainers, your project should include an SLF4J implementation (Logback is recommended).

I expect testcontainers to support org.slf4j.slf4j-log4j12
The next NullPointerException appears:

Caused by: java.lang.NullPointerException
	at java.util.Hashtable.put(Hashtable.java:459)
	at org.apache.log4j.MDC.put0(MDC.java:150)
	at org.apache.log4j.MDC.put(MDC.java:85)
	at org.slf4j.impl.Log4jMDCAdapter.put(Log4jMDCAdapter.java:60)
	at org.slf4j.MDC.put(MDC.java:116)
	at org.testcontainers.utility.AuditLogger.doLog(AuditLogger.java:34)
	at org.testcontainers.dockerclient.AuditLoggingDockerClient.lambda$startContainerCmd$3(AuditLoggingDockerClient.java:43)
	at org.testcontainers.dockerclient.AuditLoggingDockerClient.lambda$wrappedCommand$14(AuditLoggingDockerClient.java:102)
	at com.sun.proxy.$Proxy20.exec(Unknown Source)
	at org.testcontainers.containers.GenericContainer.tryStart(GenericContainer.java:201)
	... 18 more

AuditLoggingDockerClient (for commands START,REMOVE,STOP,KILL,CREATE_NETWORK,REMOVE_NETWORK) has call like this:

(cmd, e) -> doLog("START", null, containerId, cmd, e));

doLog(String action, String image, String containerId, DockerCmd<?> cmd, @Nullable Exception e)

So image = null.
org.slf4j.impl.Log4jMDCAdapter uses Hashtable where therev is a check for value != null during call 'put'. So NullPointerException occurs.

Possible fix is to use image="" instead of image=null

@bsideup
Copy link
Member

bsideup commented Jun 19, 2017

Hi @IrishkA13,

Thanks for reporting!

The issue is known and already has a PR with a fix:
#370

@rnorth rnorth added this to the 1.3.1 milestone Jun 22, 2017
@bsideup
Copy link
Member

bsideup commented Jun 23, 2017

Closed with #370

@IrishkA13
May I ask you to try 1.3.1 to verify that the issue is gone? Thanks!

@bsideup bsideup closed this as completed Jun 23, 2017
@islisava
Copy link
Author

@bsideup
Thanks for fix! This works now!

@balonideepak
Copy link

Hi, I am also facing the same issue. Can you please tell what's the resolution. What's is meant by 1.3.1 in above comment.
I am having my app deployed over tomcat 8.0.42 version.Please help.

@islisava
Copy link
Author

1.3.1 is milestone - https://github.com/testcontainers/testcontainers-java/milestone/25
It is the version of the library of testcontainers. All upper versions should also contain the fix.
Check that you use version of testcontainers is 1.3.1 or higher.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants