Fail loudly when LayoutWrappingEncoder has no layout (#1046) - #1052
Merged
ceki merged 1 commit intoJul 25, 2026
Conversation
A LayoutWrappingEncoder left without a layout (for instance when an <if>/<then>/<else> block is silently ignored) started successfully and then threw a NullPointerException from Layout.doLayout on every logging event, so the appender ran while logging nothing. headerBytes() and footerBytes() already tolerate a null layout; encode() did not. Guard encode() against a null layout (consistent with headerBytes() and footerBytes()) and report an error at start() so the misconfiguration surfaces immediately instead of causing silent log loss. Fixes qos-ch#1046 Signed-off-by: seonwoo_jung <79202163+seonwooj0810@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #1046
Root cause
A
LayoutWrappingEncoderwhoselayoutends upnull— which happens when an<if>/<then>/<else>block is silently ignored (see the reports in #1046) — used tostart()"successfully" (started = true) and then throwfrom
encode()on every logging event. The event is dropped, so the appender runs while logging nothing and the only signal is a status warning. As several users noted on the issue, silent log loss is about the worst failure mode for a logging framework.Notably
headerBytes()andfooterBytes()in the same class already guardif (layout == null) return null;—encode()was the one path that did not, so the class was internally inconsistent.Change
encode()returnsnullwhenlayout == null, consistent withheaderBytes()/footerBytes()(andOutputStreamAppender.writeBytesalready treats anull/empty byte array as a no-op, so no event spam and no NPE).start()emits anERRORstatus whenlayout == null, so the misconfiguration surfaces loudly at startup rather than as silent log loss at runtime.Test
Added
LayoutWrappingEncoderTestinlogback-core:nullLayoutReportsErrorOnStartAndDoesNotThrowOnEncode— asserts anERRORstatus is recorded atstart()and thatencode()returnsnullwithout throwing (fails before this change: NPE + no error status).encodesWhenLayoutIsSet— confirms the normal path is unaffected (error-free, correct output).Verification done: (1) searched open/closed PRs for
LayoutWrappingEncoderand issue #1046 — no in-flight PR (my other open PRs #1050/#1051 are unrelated); (2) no self-claim in the thread; (3) code-focused (.javaonly); (4) grepped master —start()still setsstarted = trueunconditionally andencode()dereferencedlayoutdirectly; (6) no triage gate (not a spring-projects repo). Built and ran the new test withmvn -pl logback-core teston JDK 21 (release target 17): 2 passed, 0 failed.