Commit c99e05c
Fix ClassCastException in CSI generator when advice captures multiple partial arguments (#11130)
fix(csi): sort ArgumentSpecification by index when generating partial-argument advice
Stream.sorted() without a comparator requires Comparable, but
ArgumentSpecification does not implement it. This caused a
ClassCastException in AdviceGeneratorImpl.writeStackOperations whenever
an advice method captured a strict subset (≥2 args) of a target
method's parameters positionally — e.g. capturing args 0 and 1 from a
3-arg target method.
Single-argument partial captures were unaffected because TimSort never
calls compare() on a one-element list.
Fix: use Comparator.comparingInt on ArgumentSpecification.getIndex().
Add a regression test with a @before advice that captures two of three
arguments from String.format(Locale, String, Object[]).
fix(csi): remove incorrect Stream.sorted() from partial-argument index generation
Stream.sorted() without a comparator requires Comparable, but
ArgumentSpecification does not implement it, causing ClassCastException
when an advice method captures two or more arguments positionally from a
target method that has strictly more parameters.
The parameters map is a TreeMap keyed by advice-parameter index, so
Stream.sorted() was both redundant and incorrect: it would have
re-sorted by natural order (broken) or by pointcut index (wrong for
advices that intentionally reorder captures). Removing it preserves the
TreeMap's advice-parameter-index order, which is what dupParameters
and the advice descriptor both expect.
Add MultiplePartialArgumentsBeforeAdvice with two variants:
- In-order capture (args 0,1 from 3-arg method): generates {0,1}
- Reversed capture (arg 1 then arg 0): generates {1,0} not {0,1},
proving parameterIndices follows advice-parameter order.
Merge branch 'master' into fix/csi-generator-partial-args-sort
Co-authored-by: devflow.devflow-routing-intake <devflow.devflow-routing-intake@kubernetes.us1.ddbuild.io>1 parent d5d2097 commit c99e05c
File tree
2 files changed
+65
-1
lines changed- buildSrc/call-site-instrumentation-plugin/src
- main/java/datadog/trace/plugin/csi/impl
- test/java/datadog/trace/plugin/csi/impl
2 files changed
+65
-1
lines changedLines changed: 0 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
266 | 266 | | |
267 | 267 | | |
268 | 268 | | |
269 | | - | |
270 | 269 | | |
271 | 270 | | |
272 | 271 | | |
| |||
Lines changed: 65 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
426 | 426 | | |
427 | 427 | | |
428 | 428 | | |
| 429 | + | |
| 430 | + | |
| 431 | + | |
| 432 | + | |
| 433 | + | |
| 434 | + | |
| 435 | + | |
| 436 | + | |
| 437 | + | |
| 438 | + | |
| 439 | + | |
| 440 | + | |
| 441 | + | |
| 442 | + | |
| 443 | + | |
| 444 | + | |
| 445 | + | |
| 446 | + | |
| 447 | + | |
| 448 | + | |
| 449 | + | |
| 450 | + | |
| 451 | + | |
| 452 | + | |
| 453 | + | |
| 454 | + | |
| 455 | + | |
| 456 | + | |
| 457 | + | |
| 458 | + | |
| 459 | + | |
| 460 | + | |
| 461 | + | |
| 462 | + | |
| 463 | + | |
| 464 | + | |
| 465 | + | |
| 466 | + | |
| 467 | + | |
| 468 | + | |
| 469 | + | |
| 470 | + | |
| 471 | + | |
| 472 | + | |
| 473 | + | |
| 474 | + | |
| 475 | + | |
| 476 | + | |
| 477 | + | |
| 478 | + | |
| 479 | + | |
| 480 | + | |
| 481 | + | |
| 482 | + | |
| 483 | + | |
| 484 | + | |
| 485 | + | |
| 486 | + | |
| 487 | + | |
| 488 | + | |
| 489 | + | |
| 490 | + | |
| 491 | + | |
| 492 | + | |
| 493 | + | |
429 | 494 | | |
430 | 495 | | |
431 | 496 | | |
| |||
0 commit comments