Skip to content

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

Closed

Description

@islisava

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

Activity

  1. bsideup commented on Jun 19, 2017

    @bsideup
    Member

    Hi @IrishkA13,

    Thanks for reporting!

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

  2. added this to the 1.3.1 milestone on Jun 22, 2017
  3. bsideup commented on Jun 23, 2017

    @bsideup
    Member

    Closed with #370

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

  4. islisava commented on Jul 17, 2017

    @islisava
    Author

    @bsideup
    Thanks for fix! This works now!

  5. balonideepak commented on Aug 23, 2018

    @balonideepak

    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.

  6. islisava commented on Aug 24, 2018

    @islisava
    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions