BVal
  1. BVal
  2. BVAL-84

CNFEX org.slf4j.impl.StaticLoggerBinder building xstream and guice

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Minor Minor
    • Resolution: Fixed
    • Affects Version/s: 0.2-incubating
    • Fix Version/s: 0.3-incubating
    • Component/s: build
    • Labels:
      None

      Description

      Clean downloaded from trunk and hit the following exception in xstream and guice modules from "mvn install"

      java.lang.NoClassDefFoundError: org.slf4j.impl.StaticLoggerBinder
      at org.slf4j.LoggerFactory.bind(LoggerFactory.java:121)
      at org.slf4j.LoggerFactory.performInitialization(LoggerFactory.java:111)
      at org.slf4j.LoggerFactory.getILoggerFactory(LoggerFactory.java:268)
      at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:241)
      at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:254)
      at org.apache.bval.MetaBeanBuilder.<clinit>(MetaBeanBuilder.java:32)
      at java.lang.J9VMInternals.initializeImpl(Native Method)
      at java.lang.J9VMInternals.initialize(J9VMInternals.java:200)
      at java.lang.J9VMInternals.initialize(J9VMInternals.java:167)
      at org.apache.bval.xml.XMLMetaBeanManager.<init>(XMLMetaBeanManager.java:42)
      at org.apache.bval.xml.XMLMetaBeanManagerTest.<init>(XMLMetaBeanManagerTest.java:35)
      at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)

      1. BVAL-84.patch
        1.0 kB
        Albert Lee

        Activity

        Hide
        Albert Lee added a comment -

        Add slf4j-simple dependency to pom.xml in xstream/guice resolved the problem and now the whole project was built.

        Show
        Albert Lee added a comment - Add slf4j-simple dependency to pom.xml in xstream/guice resolved the problem and now the whole project was built.
        Hide
        Carlos Vara added a comment -

        Tried to reproduce but couldn't. Linux and sun's JDK here.

        During mvn install, SLF4J defaults to no logging correctly:
        Running org.apache.bval.guice.GuiceAwareValidationTestCase
        SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
        SLF4J: Defaulting to no-operation (NOP) logger implementation
        SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.

        If your problem is when consuming the built jars, you will need to declare the dependency for your chosen backend in your project (slf4j-log4j, slf4j-simple, etc.). We should not declare that dependency in our pom, as it's the consumer's decision what backend suits them best.

        Show
        Carlos Vara added a comment - Tried to reproduce but couldn't. Linux and sun's JDK here. During mvn install, SLF4J defaults to no logging correctly: Running org.apache.bval.guice.GuiceAwareValidationTestCase SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder". SLF4J: Defaulting to no-operation (NOP) logger implementation SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details. If your problem is when consuming the built jars, you will need to declare the dependency for your chosen backend in your project (slf4j-log4j, slf4j-simple, etc.). We should not declare that dependency in our pom, as it's the consumer's decision what backend suits them best.
        Hide
        Albert Lee added a comment -

        When I did was following the instructions checking out the bval.trunk branch then use "mvn clean install" to build the project.

        C:\temp>mkdir bval.trunk
        C:\temp>cd bval.trunk
        C:\temp\bval.trunk>svn co http://svn.apache.org/repos/asf/incubator/bval/trunk
        A trunk\NOTICE
        ......
        A trunk\bval-guice\pom.xml
        U trunk
        Checked out revision 1027567.

        C:\temp\bval.trunk>cd trunk
        C:\temp\bval.trunk\trunk>set path="c:\Program Files\maven-2.2.1\bin";%PATH%
        C:\temp\bval.trunk\trunk>mvn clean install
        [INFO] Scanning for projects...
        [INFO] Reactor build order:
        [INFO] Apache Bean Validation :: bval-parent (Parent POM)
        [INFO] Apache Bean Validation :: bval-core
        [INFO] Apache Bean Validation :: bval-xstream (optional)
        [INFO] Apache Bean Validation :: bval-jsr303
        [INFO] Apache Bean Validation :: org.apache.bval.bundle
        [INFO] Apache Bean Validation :: bval-json (optional)
        [INFO] Apache Bean Validation :: bval-guice (optional)
        [INFO] Apache Bean Validation :: bval-tck (TCK Runner)
        [INFO] ------------------------------------------------------------
        [INFO] Building Apache Bean Validation :: bval-parent (Parent POM)
        [INFO] task-segment: [clean, install]
        [INFO] ------------------------------------------------------------

        .........

        [INFO] ------------------------------------------------------------------------
        [INFO] Building Apache Bean Validation :: bval-xstream (optional)
        [INFO] task-segment: [clean, install]
        [INFO] ------------------------------------------------------------------------
        [INFO] [clean:clean

        {execution: default-clean}

        ]
        [INFO] [enforcer:enforce

        {execution: default}

        ]
        [INFO] [buildnumber:create

        {execution: default}

        ]
        [INFO] [remote-resources:process

        {execution: process-remote-resources}

        ]
        [INFO] [remote-resources:process

        {execution: default}

        ]
        [INFO] [resources:resources

        {execution: default-resources}

        ]
        [INFO] Using 'UTF-8' encoding to copy filtered resources.
        [INFO] skip non existing resourceDirectory C:\temp\bval.trunk\trunk\bval-xstream\src\main\resources
        [INFO] Copying 4 resources
        [INFO] Copying 4 resources
        [INFO] [compiler:compile

        {execution: default-compile}

        ]
        [INFO] Compiling 23 source files to C:\temp\bval.trunk\trunk\bval-xstream\target\classes
        [INFO] [resources:testResources

        {execution: default-testResources}

        ]
        [INFO] Using 'UTF-8' encoding to copy filtered resources.
        [INFO] Copying 2 resources
        [INFO] Copying 4 resources
        [INFO] Copying 4 resources
        [INFO] [compiler:testCompile

        {execution: default-testCompile}

        ]
        [INFO] Compiling 8 source files to C:\temp\bval.trunk\trunk\bval-xstream\target\test-classes
        [INFO] [surefire:test

        {execution: default-test}

        ]
        [INFO] Surefire report directory: C:\temp\bval.trunk\trunk\bval-xstream\target\surefire-reports

        -------------------------------------------------------
        T E S T S
        -------------------------------------------------------
        Running org.apache.bval.xml.XMLMetaBeanManagerTest
        Failed to instantiate SLF4J LoggerFactory
        Reported exception:
        java.lang.NoClassDefFoundError: org.slf4j.impl.StaticLoggerBinder
        at org.slf4j.LoggerFactory.bind(LoggerFactory.java:121)
        at org.slf4j.LoggerFactory.performInitialization(LoggerFactory.java:111)
        at org.slf4j.LoggerFactory.getILoggerFactory(LoggerFactory.java:268)
        at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:241)
        at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:254)
        at org.apache.bval.MetaBeanBuilder.<clinit>(MetaBeanBuilder.java:32)
        at java.lang.J9VMInternals.initializeImpl(Native Method)
        at java.lang.J9VMInternals.initialize(J9VMInternals.java:200)
        at java.lang.J9VMInternals.initialize(J9VMInternals.java:167)
        at org.apache.bval.xml.XMLMetaBeanManager.<init>(XMLMetaBeanManager.java:42)
        at org.apache.bval.xml.XMLMetaBeanManagerTest.<init>(XMLMetaBeanManagerTest.java:35)
        at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
        at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:44)

        Look further into LoggerFactory.bind()

        private static final void bind() {
        try

        { StaticLoggerBinder.getSingleton(); INITIALIZATION_STATE = 3; emitSubstituteLoggerWarning(); }

        catch (NoClassDefFoundError ncde) {
        String msg = ncde.getMessage();
        if ((msg != null) && (msg.indexOf("org/slf4j/impl/StaticLoggerBinder") != -1))

        { INITIALIZATION_STATE = 4; Util.report("Failed to load class \"org.slf4j.impl.StaticLoggerBinder\"."); Util.report("Defaulting to no-operation (NOP) logger implementation"); Util.report("See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details."); }

        else

        { <<<<< it is going into this path. failedBinding(ncde); throw ncde; }

        .......
        static void failedBinding(Throwable t)

        { INITIALIZATION_STATE = 2; Util.report("Failed to instantiate SLF4J LoggerFactory", t); }

        One thing I noticed is that on NoClassDefFoundError,

        if ((msg != null) && (msg.indexOf("org/slf4j/impl/StaticLoggerBinder") != -1)) {

        It is checking "org/slf4j/impl/StaticLoggerBinder" but the message contains "org.slf4j.impl.StaticLoggerBinder", hence it goes into the "else" leg, which posted

        Failed to instantiate SLF4J LoggerFactory

        and the exception in failedBinding(Throwable t)

        I cleaned up the slf4j in my local repository and make sure I am downloading the correct level from the remote repository and try again. The same error occurs.

        Looked into the newly created local repository and found the project is using 2 levels of slf4j code base, 1.5.1 and 1.6.1.

        Look into 1.5.1 level and it has a complete different implementation which showed that it is checking for "org/slf4j/impl/StaticLoggerBinder":

        static
        {
        try

        { loggerFactory = StaticLoggerBinder.SINGLETON.getLoggerFactory(); }

        catch (NoClassDefFoundError ncde) {
        String msg = ncde.getMessage();
        if ((msg != null) && (msg.indexOf("org/slf4j/impl/StaticLoggerBinder") != -1))

        { Util.reportFailure("Failed to load class \"org.slf4j.impl.StaticLoggerBinder\"."); Util.reportFailure("See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details."); }

        throw ncde;
        }
        catch (Exception e)

        { Util.reportFailure("Failed to instantiate logger [" + StaticLoggerBinder.SINGLETON.getLoggerFactoryClassStr() + "]", e); }

        Looks like there is a mixed use of 1.5.1 and 1.6.1 level of slf4j code. If the 1.5.1 level is use, you will pass but use of 1.6.1 level will flagged as an error.

        Albert Lee.

        Show
        Albert Lee added a comment - When I did was following the instructions checking out the bval.trunk branch then use "mvn clean install" to build the project. C:\temp>mkdir bval.trunk C:\temp>cd bval.trunk C:\temp\bval.trunk>svn co http://svn.apache.org/repos/asf/incubator/bval/trunk A trunk\NOTICE ...... A trunk\bval-guice\pom.xml U trunk Checked out revision 1027567. C:\temp\bval.trunk>cd trunk C:\temp\bval.trunk\trunk>set path="c:\Program Files\maven-2.2.1\bin";%PATH% C:\temp\bval.trunk\trunk>mvn clean install [INFO] Scanning for projects... [INFO] Reactor build order: [INFO] Apache Bean Validation :: bval-parent (Parent POM) [INFO] Apache Bean Validation :: bval-core [INFO] Apache Bean Validation :: bval-xstream (optional) [INFO] Apache Bean Validation :: bval-jsr303 [INFO] Apache Bean Validation :: org.apache.bval.bundle [INFO] Apache Bean Validation :: bval-json (optional) [INFO] Apache Bean Validation :: bval-guice (optional) [INFO] Apache Bean Validation :: bval-tck (TCK Runner) [INFO] ------------------------------------------------------------ [INFO] Building Apache Bean Validation :: bval-parent (Parent POM) [INFO] task-segment: [clean, install] [INFO] ------------------------------------------------------------ ......... [INFO] ------------------------------------------------------------------------ [INFO] Building Apache Bean Validation :: bval-xstream (optional) [INFO] task-segment: [clean, install] [INFO] ------------------------------------------------------------------------ [INFO] [clean:clean {execution: default-clean} ] [INFO] [enforcer:enforce {execution: default} ] [INFO] [buildnumber:create {execution: default} ] [INFO] [remote-resources:process {execution: process-remote-resources} ] [INFO] [remote-resources:process {execution: default} ] [INFO] [resources:resources {execution: default-resources} ] [INFO] Using 'UTF-8' encoding to copy filtered resources. [INFO] skip non existing resourceDirectory C:\temp\bval.trunk\trunk\bval-xstream\src\main\resources [INFO] Copying 4 resources [INFO] Copying 4 resources [INFO] [compiler:compile {execution: default-compile} ] [INFO] Compiling 23 source files to C:\temp\bval.trunk\trunk\bval-xstream\target\classes [INFO] [resources:testResources {execution: default-testResources} ] [INFO] Using 'UTF-8' encoding to copy filtered resources. [INFO] Copying 2 resources [INFO] Copying 4 resources [INFO] Copying 4 resources [INFO] [compiler:testCompile {execution: default-testCompile} ] [INFO] Compiling 8 source files to C:\temp\bval.trunk\trunk\bval-xstream\target\test-classes [INFO] [surefire:test {execution: default-test} ] [INFO] Surefire report directory: C:\temp\bval.trunk\trunk\bval-xstream\target\surefire-reports ------------------------------------------------------- T E S T S ------------------------------------------------------- Running org.apache.bval.xml.XMLMetaBeanManagerTest Failed to instantiate SLF4J LoggerFactory Reported exception: java.lang.NoClassDefFoundError: org.slf4j.impl.StaticLoggerBinder at org.slf4j.LoggerFactory.bind(LoggerFactory.java:121) at org.slf4j.LoggerFactory.performInitialization(LoggerFactory.java:111) at org.slf4j.LoggerFactory.getILoggerFactory(LoggerFactory.java:268) at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:241) at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:254) at org.apache.bval.MetaBeanBuilder.<clinit>(MetaBeanBuilder.java:32) at java.lang.J9VMInternals.initializeImpl(Native Method) at java.lang.J9VMInternals.initialize(J9VMInternals.java:200) at java.lang.J9VMInternals.initialize(J9VMInternals.java:167) at org.apache.bval.xml.XMLMetaBeanManager.<init>(XMLMetaBeanManager.java:42) at org.apache.bval.xml.XMLMetaBeanManagerTest.<init>(XMLMetaBeanManagerTest.java:35) at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:44) Look further into LoggerFactory.bind() private static final void bind() { try { StaticLoggerBinder.getSingleton(); INITIALIZATION_STATE = 3; emitSubstituteLoggerWarning(); } catch (NoClassDefFoundError ncde) { String msg = ncde.getMessage(); if ((msg != null) && (msg.indexOf("org/slf4j/impl/StaticLoggerBinder") != -1)) { INITIALIZATION_STATE = 4; Util.report("Failed to load class \"org.slf4j.impl.StaticLoggerBinder\"."); Util.report("Defaulting to no-operation (NOP) logger implementation"); Util.report("See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details."); } else { <<<<< it is going into this path. failedBinding(ncde); throw ncde; } ....... static void failedBinding(Throwable t) { INITIALIZATION_STATE = 2; Util.report("Failed to instantiate SLF4J LoggerFactory", t); } One thing I noticed is that on NoClassDefFoundError, if ((msg != null) && (msg.indexOf("org/slf4j/impl/StaticLoggerBinder") != -1)) { It is checking "org/slf4j/impl/StaticLoggerBinder" but the message contains "org.slf4j.impl.StaticLoggerBinder", hence it goes into the "else" leg, which posted Failed to instantiate SLF4J LoggerFactory and the exception in failedBinding(Throwable t) I cleaned up the slf4j in my local repository and make sure I am downloading the correct level from the remote repository and try again. The same error occurs. Looked into the newly created local repository and found the project is using 2 levels of slf4j code base, 1.5.1 and 1.6.1. Look into 1.5.1 level and it has a complete different implementation which showed that it is checking for "org/slf4j/impl/StaticLoggerBinder": static { try { loggerFactory = StaticLoggerBinder.SINGLETON.getLoggerFactory(); } catch (NoClassDefFoundError ncde) { String msg = ncde.getMessage(); if ((msg != null) && (msg.indexOf("org/slf4j/impl/StaticLoggerBinder") != -1)) { Util.reportFailure("Failed to load class \"org.slf4j.impl.StaticLoggerBinder\"."); Util.reportFailure("See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details."); } throw ncde; } catch (Exception e) { Util.reportFailure("Failed to instantiate logger [" + StaticLoggerBinder.SINGLETON.getLoggerFactoryClassStr() + "]", e); } Looks like there is a mixed use of 1.5.1 and 1.6.1 level of slf4j code. If the 1.5.1 level is use, you will pass but use of 1.6.1 level will flagged as an error. Albert Lee.
        Hide
        Albert Lee added a comment -

        Correction. the project is using 1.5.0 not 1.5.1 slf4j.

        Show
        Albert Lee added a comment - Correction. the project is using 1.5.0 not 1.5.1 slf4j.
        Hide
        Donald Woods added a comment -

        Was able to recreate Albert's problem on Win7 only when using the IBM 1.6 SDK.
        Will apply the fix, as we should support other JVMs....

        Show
        Donald Woods added a comment - Was able to recreate Albert's problem on Win7 only when using the IBM 1.6 SDK. Will apply the fix, as we should support other JVMs....
        Hide
        Donald Woods added a comment -

        Build with no org.slf4j artifacts in local repo now works when using IBM 1.6 SDK on Windows

        Show
        Donald Woods added a comment - Build with no org.slf4j artifacts in local repo now works when using IBM 1.6 SDK on Windows
        Hide
        Carlos Vara added a comment -

        Thanks for managing to replicate it Donald.

        Btw, the project should not be using 1.5 version of SLF4J but only 1.6.1. You can check it by running mvn dependency:tree on the trunk folder. If any different version appears please report it as it is likely a bug.

        Show
        Carlos Vara added a comment - Thanks for managing to replicate it Donald. Btw, the project should not be using 1.5 version of SLF4J but only 1.6.1. You can check it by running mvn dependency:tree on the trunk folder. If any different version appears please report it as it is likely a bug.
        Hide
        Donald Woods added a comment -

        With a clean repo, it was grabbing the 1.5.0 version as that was a dependency of one of the maven plugins (ianal I think) and was the only version available in the local repo. By setting the slf4j-simple version in the dependencyManagement section of the parent pom and adding some test depends, we should be good now w/o requiring slf4j-simple (still allowing consumers to choose their SLF4J bridge.)

        Show
        Donald Woods added a comment - With a clean repo, it was grabbing the 1.5.0 version as that was a dependency of one of the maven plugins (ianal I think) and was the only version available in the local repo. By setting the slf4j-simple version in the dependencyManagement section of the parent pom and adding some test depends, we should be good now w/o requiring slf4j-simple (still allowing consumers to choose their SLF4J bridge.)

          People

          • Assignee:
            Donald Woods
            Reporter:
            Albert Lee
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development