Uploaded image for project: 'Log4j 2'
  1. Log4j 2
  2. LOG4J2-2559

NullPointerException in JdbcAppender.createAppender()

Attach filesAttach ScreenshotVotersWatch issueWatchersCreate sub-taskLinkCloneUpdate Comment AuthorReplace String in CommentUpdate Comment VisibilityDelete Comments
    XMLWordPrintableJSON

Details

    • Bug
    • Status: Resolved
    • Major
    • Resolution: Fixed
    • 2.10.0, 2.11.1, 2.11.2
    • 3.0.0, 2.12.0
    • Appenders, JDBC
    • None

    Description

       when I build the appender with 'JdbcAppender.createAppender' ,   

      in static class JdbcDatabaseManagerFactory, the method  createManager  has exception that is not catched.  The code as follows:

      //代码占位符
      StringBuilder sb = (new StringBuilder("insert into ")).append(data.tableName).append(" (");
      JdbcDatabaseManager.appendColumnNames("INSERT", data, sb);
      sb.append(") values (");
      int i = 1;
      ColumnMapping[] arr$ = data.columnMappings;
      int len$ = arr$.length;
      
      int len$;
      for(len$ = 0; len$ < len$; ++len$) {
          ColumnMapping mapping = arr$[len$];
          String mappingName = mapping.getName();
          if (Strings.isNotEmpty(mapping.getLiteralValue())) {
              JdbcDatabaseManager.logger().trace("Adding INSERT VALUES literal for ColumnMapping[{}]: {}={} ", i, mappingName, mapping.getLiteralValue());
              sb.append(mapping.getLiteralValue());
          } else if (Strings.isNotEmpty(mapping.getParameter())) {
              JdbcDatabaseManager.logger().trace("Adding INSERT VALUES parameter for ColumnMapping[{}]: {}={} ", i, mappingName, mapping.getParameter());
              sb.append(mapping.getParameter());
          } else {
              JdbcDatabaseManager.logger().trace("Adding INSERT VALUES parameter marker for ColumnMapping[{}]: {}={} ", i, mappingName, '?');
              sb.append('?');
          }
      
          sb.append(',');
          ++i;
      }
      
      

      because I wanto use columnConfig,  and  the variable 'columnMappings' is null,  so there mayby a NullPointerException here.....

       

      the stack as follow

       

      //代码占位符
      Caused by: java.lang.NullPointerException
      at org.apache.logging.log4j.core.appender.db.jdbc.JdbcDatabaseManager.appendColumnNames(JdbcDatabaseManager.java:342) ~[log4j-core-2.11.2.jar:2.11.2]
      at org.apache.logging.log4j.core.appender.db.jdbc.JdbcDatabaseManager.access$100(JdbcDatabaseManager.java:62) ~[log4j-core-2.11.2.jar:2.11.2]
      at org.apache.logging.log4j.core.appender.db.jdbc.JdbcDatabaseManager$JdbcDatabaseManagerFactory.createManager(JdbcDatabaseManager.java:113) ~[log4j-core-2.11.2.jar:2.11.2]
      at org.apache.logging.log4j.core.appender.db.jdbc.JdbcDatabaseManager$JdbcDatabaseManagerFactory.createManager(JdbcDatabaseManager.java:104) ~[log4j-core-2.11.2.jar:2.11.2]
      at org.apache.logging.log4j.core.appender.AbstractManager.getManager(AbstractManager.java:113) ~[log4j-core-2.11.2.jar:2.11.2]
      at org.apache.logging.log4j.core.appender.db.AbstractDatabaseManager.getManager(AbstractDatabaseManager.java:87) ~[log4j-core-2.11.2.jar:2.11.2]
      at org.apache.logging.log4j.core.appender.db.jdbc.JdbcDatabaseManager.getManager(JdbcDatabaseManager.java:446) ~[log4j-core-2.11.2.jar:2.11.2]
      at org.apache.logging.log4j.core.appender.db.jdbc.JdbcAppender$Builder.build(JdbcAppender.java:95) ~[log4j-core-2.11.2.jar:2.11.2]
      at org.apache.logging.log4j.core.appender.db.jdbc.JdbcAppender.createAppender(JdbcAppender.java:202) ~[log4j-core-2.11.2.jar:2.11.2]
      
      

      Attachments

        Activity

          This comment will be Viewable by All Users Viewable by All Users
          Cancel

          People

            Unassigned Unassigned
            leilei Li Lei
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Slack

                Issue deployment