fix: expand Array arguments in MarkerLoggingAdapter log templates (#3257)#3263
Merged
Conversation
Motivation:
MarkerLoggingAdapter.format1 passed an Array argument to the varargs format
without spreading it, so the whole array was treated as a single template
argument. A call like markerLog.info(marker, "{} {} {}", Array("a", "b", "c"))
rendered as "ArraySeq(a, b, c) {} {}" instead of "a b c". The base
LoggingAdapter expands arrays correctly; the marker copy did not.
DiagnosticMarkerBusLoggingAdapter inherits the same method and was affected too.
Modification:
- Spread the array elements as varargs in both Array branches of
MarkerLoggingAdapter.format1 so each element fills its own placeholder.
Result:
Array arguments to the single-argument marker log template methods are now
expanded into separate placeholders, matching LoggingAdapter behavior.
Tests:
- actor-tests/testOnly org.apache.pekko.event.MarkerLoggingSpec - all passed.
Added directional tests (non-primitive and primitive arrays) that fail
before the fix (rendering ArraySeq(...)) and pass after.
References:
Fixes #3257
Member
|
Is there any chance that since the existing behaviour has been like that for a long time, that we just accept that that is the behaviour? Where in the docs does it say that this change is what users should expect? |
Member
Author
|
The problem is this ,it change the default behavior. |
He-Pin
commented
Jun 28, 2026
| private def format1(t: String, arg: Any): String = arg match { | ||
| case a: Array[?] if !a.getClass.getComponentType.isPrimitive => format(t, a.toIndexedSeq) | ||
| case a: Array[?] => format(t, a.toIndexedSeq.asInstanceOf[IndexedSeq[AnyRef]]) | ||
| case a: Array[?] if !a.getClass.getComponentType.isPrimitive => format(t, a.toIndexedSeq: _*) |
Member
Author
There was a problem hiding this comment.
Not sure if it's safe to change ,let's defer this.
Member
|
Actually, the javadoc says So your change is probably correct. |
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.
Motivation
MarkerLoggingAdapter.format1passed anArrayargument to the varargsformat(t, arg: Any*)without spreading it (: _*), so the whole array wastreated as a single template argument instead of being expanded into the
individual placeholders.
For example:
LoggingAdapterMarkerLoggingAdapter(before)a b cArraySeq(a, b, c) {} {}The base
LoggingAdapter.format1expands arrays correctly (it callsformatImpl(t, a.toSeq)directly). The marker copy exists for binarycompatibility reasons (it cannot reach the base trait's
private formatImpl),and when it was written the varargs spread (
: _*) was forgotten. The scaladocpromising that an
Arrayargument "will be expanded into replacementarguments" was therefore not honored by the marker adapter.
Fixes #3257.
Modification
Spread the array elements as varargs in both
Arraybranches ofMarkerLoggingAdapter.format1, so each element fills its own placeholder, anddocumented the reason so it is not regressed:
DiagnosticMarkerBusLoggingAdapterinherits this method and is fixed by thesame change.
Result
Arrayarguments to the single-argument marker log template methods are nowexpanded into separate placeholders, matching
LoggingAdapterand thedocumented behavior (e.g.
"a b c"instead of"ArraySeq(a, b, c) {} {}").format1isprivateand only its body changed — no public API orbinary-compatibility change (
actor / mimaReportBinaryIssuesis clean).Tests
sbt "actor-tests/testOnly org.apache.pekko.event.MarkerLoggingSpec"→all passed.
Array[String]and a primitiveArray[Int](the twoformat1branches). Both fail before the fix(rendering
"ArraySeq(a, b, c) {} {}"/"ArraySeq(1, 2, 3) {} {}") and passafter.
sbt "actor/mimaReportBinaryIssues"→ no binary issues.References
Fixes #3257
This is an original contribution to Apache Pekko, made under the Apache License
2.0 (i.e. the changes are now Apache licensed). No third-party or Akka-derived
code is included.