He-Pin opened a new pull request, #3263:
URL: https://github.com/apache/pekko/pull/3263
### Motivation
`MarkerLoggingAdapter.format1` passed an `Array` argument to the varargs
`format(t, arg: Any*)` **without** spreading it (`: _*`), so the whole array
was
treated as a single template argument instead of being expanded into the
individual placeholders.
For example:
```scala
markerLog.info(LogMarker.Security, "{} {} {}", Array("a", "b", "c"))
```
| | base `LoggingAdapter` | `MarkerLoggingAdapter` (before) |
|---|---|---|
| Output | `a b c` | `ArraySeq(a, b, c) {} {}` |
The base `LoggingAdapter.format1` expands arrays correctly (it calls
`formatImpl(t, a.toSeq)` directly). The marker copy exists for binary
compatibility reasons (it cannot reach the base trait's `private
formatImpl`),
and when it was written the varargs spread (`: _*`) was forgotten. The
scaladoc
promising that an `Array` argument "will be expanded into replacement
arguments" was therefore not honored by the marker adapter.
Fixes #3257.
### Modification
Spread the array elements as varargs in both `Array` branches of
`MarkerLoggingAdapter.format1`, so each element fills its own placeholder,
and
documented the reason so it is not regressed:
```scala
case a: Array[?] if !a.getClass.getComponentType.isPrimitive => format(t,
a.toIndexedSeq: _*)
case a: Array[?] => format(t,
a.toIndexedSeq.asInstanceOf[IndexedSeq[AnyRef]]: _*)
case x => format(t, x)
```
`DiagnosticMarkerBusLoggingAdapter` inherits this method and is fixed by the
same change.
### Result
- `Array` arguments to the single-argument marker log template methods are
now
expanded into separate placeholders, matching `LoggingAdapter` and the
documented behavior (e.g. `"a b c"` instead of `"ArraySeq(a, b, c) {}
{}"`).
- `format1` is `private` and only its body changed — **no public API or
binary-compatibility change** (`actor / mimaReportBinaryIssues` is clean).
### Tests
- `sbt "actor-tests/testOnly org.apache.pekko.event.MarkerLoggingSpec"` →
all passed.
- Added directional tests for a non-primitive `Array[String]` and a primitive
`Array[Int]` (the two `format1` branches). Both **fail before the fix**
(rendering `"ArraySeq(a, b, c) {} {}"` / `"ArraySeq(1, 2, 3) {} {}"`) and
pass
after.
- `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.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]