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 Spring-boot logback-core 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> </encoder> </appender> <appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender"> <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy"> <FileNamePattern>$\{LOG_HOME}/connectivi.log.%d\{yyyy-MM-dd}.log</FileNamePattern> <MaxHistory>6</MaxHistory> </rollingPolicy> <encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder"> <pattern>%d\{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger\{50} - %msg%n</pattern> <immediateFlush>true</immediateFlush> </encoder> <triggeringPolicy class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy"> <MaxFileSize>10MB</MaxFileSize> </triggeringPolicy> <filter class="ch.qos.logback.classic.filter.ThresholdFilter"> <level>TRACE</level> </filter> </appender> <logger name="com.mindsphere.china.poc.connectivity" level="DEBUG" additivity="false"> <appender-ref ref="STDOUT" /> <appender-ref ref="FILE" /> </logger> <root level="ERROR"> <appender-ref ref="STDOUT" /> <appender-ref ref="FILE" /> </root> </configuration> ------ 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. BTW 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 jbjiangb...@icloud.com -- This message was sent by Atlassian JIRA (v7.3.1#73012) _______________________________________________ logback-dev mailing list logback-dev@qos.ch http://mailman.qos.ch/mailman/listinfo/logback-dev