Skip to content

Rfc5424Layout prints null as the timestamp of an event 1 ms before the epoch #4490

Open

Description

@ramanathan1504

Rfc5424Layout caches the last formatted timestamp in an instance field. The cache starts with the time -1 and no string. An event at exactly -1 ms matches that seed, so the layout writes the four characters null as TIMESTAMP:

<134>1 null localhost app 15847 - - m

The expected record is <134>1 1969-12-31T23:59:59.999Z localhost app 15847 - - m. RFC 5424 can express this time, since DATE-FULLYEAR is four digits. NILVALUE is only for an application that cannot obtain the time, so - is not the right output either.

The record stays null for every -1 ms event until an event with another time reaches the same layout. After that, -1 ms formats correctly. An event at -2 ms is always correct. SyslogAppender with format="RFC5424" uses the same layout.

Seeding the cache with Long.MIN_VALUE, as CachedDateFormat does, fixes it. Times before the epoch are rare in logs, so this is not urgent. InstantPatternThreadLocalCachedFormatter has the same -1 seed, which is being discussed on #4322.

Configuration

Version: 2.x at ea28f5a and main at 2bb673f. Also 2.17.2, 2.24.3, 2.26.1 and 3.0.0-beta3. The code dates from the first version of the layout.

Operating system: any. Reproduced on macOS.

JDK: 17

Logs

None.

Reproduction

@Test
void rfc5424BeforeTheEpoch() { // with a UTC default time zone
    final Rfc5424Layout layout = Rfc5424Layout.newBuilder().setAppName("app").build();
    final LogEvent event = Log4jLogEvent.newBuilder().setTimeMillis(-1).build();
    final String timestamp = layout.toSerializable(event).split(" ")[1];
    assertEquals("1969-12-31T23:59:59.999Z", timestamp); // actual: null
}

Related

The same method does not pad the year to four digits, and GregorianCalendar uses the Julian calendar before 1582. An event in the year 999 prints 999-06-10T00:00:00.000Z instead of 0999-06-15T00:00:00.000Z. That is a separate defect.

Activity

  1. added
    layouts
    bug
    priority: P3
    on Nov 17, 2026
  2. added this to the 2.27.0 milestone on Nov 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    buglayoutspriority: P3

    Type

    No type

    Projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions