Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
*/
package org.apache.logging.log4j.core.appender.rolling;

import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
import static org.junit.jupiter.api.Assertions.assertEquals;

import java.time.Instant;
Expand All @@ -29,6 +30,8 @@
import org.junit.jupiter.api.parallel.ResourceAccessMode;
import org.junit.jupiter.api.parallel.ResourceLock;
import org.junit.jupiter.api.parallel.Resources;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ValueSource;

/**
* Tests the PatternProcessor class.
Expand Down Expand Up @@ -394,4 +397,10 @@ public void testGetNextTimeDailyReturnsFirstHourOfNextDayInGmtIfZoneIsInvalid()
TimeZone.setDefault(old);
}
}

@ParameterizedTest
@ValueSource(strings = {"%d{UNIX}", "%d{UNIX_MILLIS}"})
void does_not_throw_with_unix_pattern(final String pattern) {
assertDoesNotThrow(() -> new PatternProcessor(pattern));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,10 @@ protected final void formatFileName(final StringBuilder buf, final Object... obj
}

private RolloverFrequency calculateFrequency(final String pattern) {
// The UNIX and UNIX_MILLIS converters do not have a pattern
if (pattern == null) {
return null;
}
if (patternContains(pattern, MILLIS_CHAR)) {
return RolloverFrequency.EVERY_MILLISECOND;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,7 @@ public void format(final StringBuilder toAppendTo, final Object... objects) {
/**
* Gets the pattern string describing this date format.
*
* @return the pattern string describing this date format.
* @return the pattern string describing this date format or {@code null} if the format does not have a pattern.
*/
public String getPattern() {
return formatter.toPattern();
Expand Down
8 changes: 8 additions & 0 deletions src/changelog/.2.x.x/2346_unix_millis_data_pattern.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<entry xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://logging.apache.org/log4j/changelog"
xsi:schemaLocation="http://logging.apache.org/log4j/changelog https://logging.apache.org/log4j/changelog-0.1.3.xsd"
type="changed">
<issue id="2346" link="https://github.com/apache/logging-log4j2/pull/2346"/>
<description format="asciidoc">Fix `NullPointerException` in `PatternProcessor` for a `UNIX_MILLIS` pattern.</description>
</entry>