Uploaded image for project: 'SLF4J'
  1. SLF4J
  2. SLF4J-356

slf4j-simple initialization should be thread safe

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 1.7.18
    • Component/s: slf4j-simple
    • Labels:
      None

      Description

      MultithreadedInitializationTest in slf4j-simple fails (see below) because SimpleLogger.init method is called via SimpleLoggerFactory.getLogger. Thus SimpleLogger may be used before it is actually initialized.

      -------------------------------------------------------
       T E S T S
      -------------------------------------------------------
      Running org.slf4j.InvocationTest
      Running org.slf4j.impl.SimpleLoggerTest
      Running org.slf4j.impl.MultithreadedInitializationTest
      Running org.slf4j.DetectLoggerNameMismatchTest
      Tests run: 6, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.284 sec - in org.slf4j.InvocationTest
      testNullParameter_BUG78(org.slf4j.InvocationTest)  Time elapsed: 0.064 sec
      testNull(org.slf4j.InvocationTest)  Time elapsed: 0.008 sec
      testMarker(org.slf4j.InvocationTest)  Time elapsed: 0.004 sec
      test2(org.slf4j.InvocationTest)  Time elapsed: 0.001 sec
      testMDC(org.slf4j.InvocationTest)  Time elapsed: 0.002 sec
      test1(org.slf4j.InvocationTest)  Time elapsed: 0 sec
      THREAD_COUNT=8
      Exception in thread "Thread-7" java.lang.NullPointerException
      	at org.slf4j.impl.SimpleLogger.write(SimpleLogger.java:378)
      	at org.slf4j.impl.SimpleLogger.log(SimpleLogger.java:373)
      	at org.slf4j.impl.SimpleLogger.info(SimpleLogger.java:534)
      	at org.slf4j.impl.MultithreadedInitializationTest$LoggerAccessingThread.run(MultithreadedInitializationTest.java:119)
      SLF4J: A number (6) of logging calls during the initialization phase have been intercepted and are
      SLF4J: now being replayed. These are suject to the filtering rules of the underlying logging system.
      SLF4J: See also http://www.slf4j.org/codes.html#replay
      [Thread-0] INFO org.slf4j.impl.MultithreadedInitializationTest$LoggerAccessingThread-1 - in run method
      [Thread-0] INFO org.slf4j.impl.MultithreadedInitializationTest$LoggerAccessingThread-6 - in run method
      [Thread-0] INFO org.slf4j.impl.MultithreadedInitializationTest$LoggerAccessingThread-3 - in run method
      [Thread-0] INFO org.slf4j.impl.MultithreadedInitializationTest$LoggerAccessingThread-4 - in run method
      [Thread-0] INFO org.slf4j.impl.MultithreadedInitializationTest$LoggerAccessingThread-2 - in run method
      [Thread-0] INFO org.slf4j.impl.MultithreadedInitializationTest$LoggerAccessingThread-5 - in run method
      [Thread-0] INFO org.slf4j.impl.MultithreadedInitializationTest$LoggerAccessingThread-0 - in run method
      [main] INFO org.slf4j.impl.MultithreadedInitializationTest$LoggerAccessingThread-0 - post harness
      [main] INFO org.slf4j.impl.MultithreadedInitializationTest$LoggerAccessingThread-1 - post harness
      [main] INFO org.slf4j.impl.MultithreadedInitializationTest$LoggerAccessingThread-2 - post harness
      [main] INFO org.slf4j.impl.MultithreadedInitializationTest$LoggerAccessingThread-3 - post harness
      [main] INFO org.slf4j.impl.MultithreadedInitializationTest$LoggerAccessingThread-4 - post harness
      [main] INFO org.slf4j.impl.MultithreadedInitializationTest$LoggerAccessingThread-5 - post harness
      [main] INFO org.slf4j.impl.MultithreadedInitializationTest$LoggerAccessingThread-6 - post harness
      [main] INFO org.slf4j.impl.MultithreadedInitializationTest$LoggerAccessingThread-7 - post harness
      [main] INFO org.slf4j.impl.MultithreadedInitializationTest.slowInitialization-9350 - hello
      Tests run: 1, Failures: 1, Errors: 0, Skipped: 0, Time elapsed: 0.208 sec <<< FAILURE! - in org.slf4j.impl.MultithreadedInitializationTest
      multiThreadedInitialization(org.slf4j.impl.MultithreadedInitializationTest)  Time elapsed: 0.05 sec  <<< FAILURE!
      java.lang.AssertionError: expected:<19> but was:<25>
      	at org.junit.Assert.fail(Assert.java:93)
      	at org.junit.Assert.failNotEquals(Assert.java:647)
      	at org.junit.Assert.assertEquals(Assert.java:128)
      	at org.junit.Assert.assertEquals(Assert.java:472)
      	at org.junit.Assert.assertEquals(Assert.java:456)
      	at org.slf4j.impl.MultithreadedInitializationTest.multiThreadedInitialization(MultithreadedInitializationTest.java:84)
      	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
      	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      	at java.lang.reflect.Method.invoke(Method.java:606)
      	at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:45)
      	at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
      	at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:42)
      	at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
      	at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
      	at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:30)
      	at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:263)
      	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:68)
      	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:47)
      	at org.junit.runners.ParentRunner$3.run(ParentRunner.java:231)
      	at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:60)
      	at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:229)
      	at org.junit.runners.ParentRunner.access$000(ParentRunner.java:50)
      	at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:222)
      	at org.junit.runners.ParentRunner.run(ParentRunner.java:300)
      	at org.apache.maven.surefire.junit4.JUnit4Provider.execute(JUnit4Provider.java:367)
      	at org.apache.maven.surefire.junit4.JUnit4Provider.executeWithRerun(JUnit4Provider.java:274)
      	at org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:238)
      	at org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:161)
      	at org.apache.maven.surefire.booter.ForkedBooter.invokeProviderInSameClassLoader(ForkedBooter.java:290)
      	at org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:242)
      	at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:121)
      
      Tests run: 5, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.248 sec - in org.slf4j.impl.SimpleLoggerTest
      emptyLoggerName(org.slf4j.impl.SimpleLoggerTest)  Time elapsed: 0.022 sec
      loggerNameWithNoDots_WithLevel(org.slf4j.impl.SimpleLoggerTest)  Time elapsed: 0 sec
      loggerNameWithOneDotShouldInheritFromParent(org.slf4j.impl.SimpleLoggerTest)  Time elapsed: 0.001 sec
      loggerNameWithNoDots_WithNoSetLevel(org.slf4j.impl.SimpleLoggerTest)  Time elapsed: 0 sec
      loggerNameWithOneDot_NoSetLevel(org.slf4j.impl.SimpleLoggerTest)  Time elapsed: 0.004 sec
      Tests run: 5, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.229 sec - in org.slf4j.DetectLoggerNameMismatchTest
      testPassIfMatch(org.slf4j.DetectLoggerNameMismatchTest)  Time elapsed: 0.021 sec
      verifyLoggerDefinedInBaseWithOverridenGetClassMethod(org.slf4j.DetectLoggerNameMismatchTest)  Time elapsed: 0.001 sec
      testNoTriggerWithoutProperty(org.slf4j.DetectLoggerNameMismatchTest)  Time elapsed: 0.004 sec
      testTriggerWithProperty(org.slf4j.DetectLoggerNameMismatchTest)  Time elapsed: 0.001 sec
      testTriggerWholeMessage(org.slf4j.DetectLoggerNameMismatchTest)  Time elapsed: 0 sec
      
      Results :
      
      Failed tests: 
        MultithreadedInitializationTest.multiThreadedInitialization:84 expected:<19> but was:<25>
      

        Issue Links

          Activity

          There are no comments yet on this issue.

            People

            • Assignee:
              slf4j-dev@qos.ch SLF4J developers list
              Reporter:
              noreply.ceki@qos.ch Ceki Gulcu
            • Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: