Commit 54c6166
authored
fix(common): strip leading whitespace in ClassPreLoader (#2560)
* fix(common): strip leading whitespace in ClassPreLoader
ClassPreLoader used line.stripTrailing() when parsing classesloaded.txt,
which keeps leading whitespace. Modules that ship the file with a leading
space on every line (for example powertools-tracing) passed names such as
" java.lang.Object" to Class.forName, which throws ClassNotFoundException,
so SnapStart class priming loaded 0 classes.
Use line.strip() so both leading and trailing whitespace are removed. Add a
regression test that references a class with a leading space.
Closes #2559
* fix(common): reject malformed classesloaded.txt entries and fix tracing test isolation
Harden ClassPreLoader to only pass well-formed binary class names to
Class.forName. Some modules ship classesloaded.txt with malformed entries
such as runtime-synthetic lambda classes and lines that glue a class name to
a file path, none of which are loadable. Add a debug log reporting how many
classes were preloaded.
Fixing the leading-whitespace parsing means the well-formed classes in
powertools-tracing now actually load during priming. That exposed a
pre-existing test isolation defect: PowerTracerToolEnabledForResponseWithCustomMapper
set the static TracingUtils.objectMapper from a static initializer, which
leaked into later tests in the same JVM fork and changed how errors were
serialized. Set the mapper from the constructor instead and reset it in the
aspect test teardown.
Relates to #2559
* fix(common): simplify class name pattern to avoid backtracking
Replace the nested-quantifier regex with a single linear character class.
SonarCloud flagged the previous pattern for possible catastrophic
backtracking on large inputs. The character class rejects the same malformed
entries (paths, URL-encoded spaces, synthetic lambda names) without the
backtracking risk.
* refactor(common): drop class name pattern, rely on Class.forName
Remove the binary class name pattern matching. Class.forName already rejects
malformed entries by throwing ClassNotFoundException, which is caught and
ignored, so the extra pattern check only duplicated that rejection and added
complexity. The tracing test failures were caused by test ordering (a leaked
static ObjectMapper), not by malformed entries, and that fix is retained.1 parent 4f869f5 commit 54c6166
5 files changed
Lines changed: 50 additions & 9 deletions
File tree
- powertools-common/src
- main/java/software/amazon/lambda/powertools/common/internal
- test
- java/software/amazon/lambda/powertools/common/internal
- resources
- powertools-tracing/src/test/java/software/amazon/lambda/powertools/tracing
- handlers
- internal
Lines changed: 15 additions & 5 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
22 | 22 | | |
23 | 23 | | |
24 | 24 | | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
25 | 28 | | |
26 | 29 | | |
27 | 30 | | |
28 | 31 | | |
29 | 32 | | |
30 | 33 | | |
| 34 | + | |
| 35 | + | |
31 | 36 | | |
32 | 37 | | |
33 | 38 | | |
| |||
57 | 62 | | |
58 | 63 | | |
59 | 64 | | |
| 65 | + | |
60 | 66 | | |
61 | 67 | | |
62 | 68 | | |
| |||
66 | 72 | | |
67 | 73 | | |
68 | 74 | | |
69 | | - | |
70 | | - | |
71 | | - | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
72 | 78 | | |
73 | 79 | | |
74 | 80 | | |
75 | 81 | | |
76 | 82 | | |
| 83 | + | |
77 | 84 | | |
78 | 85 | | |
79 | 86 | | |
80 | 87 | | |
81 | 88 | | |
82 | | - | |
| 89 | + | |
| 90 | + | |
83 | 91 | | |
84 | | - | |
| 92 | + | |
85 | 93 | | |
86 | 94 | | |
| 95 | + | |
87 | 96 | | |
88 | 97 | | |
| 98 | + | |
89 | 99 | | |
90 | 100 | | |
91 | 101 | | |
Lines changed: 23 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
| 11 | + | |
11 | 12 | | |
12 | 13 | | |
13 | 14 | | |
| |||
20 | 21 | | |
21 | 22 | | |
22 | 23 | | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
23 | 37 | | |
24 | 38 | | |
25 | 39 | | |
26 | 40 | | |
27 | | - | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
28 | 45 | | |
29 | 46 | | |
30 | 47 | | |
31 | | - | |
| 48 | + | |
32 | 49 | | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
33 | 54 | | |
34 | 55 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | | - | |
| 2 | + | |
| 3 | + | |
Lines changed: 5 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
28 | 28 | | |
29 | 29 | | |
30 | 30 | | |
31 | | - | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
32 | 36 | | |
33 | 37 | | |
34 | 38 | | |
| |||
Lines changed: 5 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
41 | 41 | | |
42 | 42 | | |
43 | 43 | | |
| 44 | + | |
44 | 45 | | |
45 | 46 | | |
46 | 47 | | |
| |||
70 | 71 | | |
71 | 72 | | |
72 | 73 | | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
73 | 78 | | |
74 | 79 | | |
75 | 80 | | |
| |||
0 commit comments