[logback-dev] [JIRA] (LOGBACK-1393) The ch.qos.logback.core.rolling.helper.FileFilterUtil.afterLastSlash function may caused NPE problem

QOS.CH (JIRA) noreply-jira at qos.ch
Tue Mar 27 11:39:00 CEST 2018

Jiang Biao created LOGBACK-1393:

             Summary: The ch.qos.logback.core.rolling.helper.FileFilterUtil.afterLastSlash function may caused NPE problem
                 Key: LOGBACK-1393
                 URL: https://jira.qos.ch/browse/LOGBACK-1393
             Project: logback
          Issue Type: Bug
          Components: logback-core
    Affects Versions: 1.1.1
         Environment: Java 1.8.0

Intellij idea 



            Reporter: Jiang Biao
            Assignee: Logback dev list
            Priority: Critical
         Attachments: Capture.PNG

I debug the logback codes and found the afterLastSlash function may caused NullPointException . Because of the function as follows.

public static String afterLastSlash(String sregex) \{
          {color:#ff0000}int i = sregex.lastIndexOf('/');{color}
          if (i == -1) \{ 
          return sregex;
         } else \{
         return sregex.substring(i + 1);

if the "sregex" is a null String . The function will throw the exception and the program logic will be interrupted .

I will show your this case how to happed . 

I create the a spring-boot project use the logback as log framework . The logback configuration is 


<?xml version="1.0" encoding="UTF-8"?>
<configuration debug="false">
 <property name="LOG_HOME" value="log" />
 <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
 <encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
 <pattern>%d\{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger\{50} - %msg%n</pattern>
 <appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
 <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
 <encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
 <pattern>%d\{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger\{50} - %msg%n</pattern>
 <triggeringPolicy class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy">
 <filter class="ch.qos.logback.classic.filter.ThresholdFilter">

 <logger name="com.mindsphere.china.poc.connectivity" level="DEBUG" additivity="false">
 <appender-ref ref="STDOUT" />
 <appender-ref ref="FILE" />

<root level="ERROR">
 <appender-ref ref="STDOUT" />
 <appender-ref ref="FILE" />


The program write the log into the file until the file size is small than 10MB ,When the log file size is more than 10MB . The logback continue write log will trigger the SizeBasedTriggeringPolicy . The TimeBasedRollingPolicy class will call the rollover() function . 

public void rollover() throws RolloverFailure \{

 // when rollover is called the elapsed period's file has
 // been already closed. This is a working assumption of this method.

 {color:#ff0000}String elapsedPeriodsFileName = timeBasedFileNamingAndTriggeringPolicy.getElapsedPeriodsFileName();{color}

 String elapsedPeriodStem = FileFilterUtil.afterLastSlash(elapsedPeriodsFileName);

but the function timeBasedFileNamingAndTriggeringPolicy.getElapsedPeriodsFileName() return null . So the program could be broken and lose the logs.



I have choose another way to configuration the logback.xml and get the right result .But I think this is still a issues .So if you still want to have more details can connect will me by emails jbjiangbiao at icloud.com



This message was sent by Atlassian JIRA

More information about the logback-dev mailing list