fix(common): strip leading whitespace in ClassPreLoader#2560
Open
phipag wants to merge 4 commits into
Open
Conversation
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
6 tasks
…ng 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
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.
Contributor
Author
|
The PMD |
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.
|
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.



Summary
Changes
ClassPreLoaderparsedclassesloaded.txtwithline.stripTrailing(), which removes trailing whitespace but keeps leading whitespace. Modules that ship the file with a leading space on every line, such aspowertools-tracing, passed names like" java.lang.Object"toClass.forName. That call throwsClassNotFoundException, and the loader swallows it, so SnapStart class priming loaded 0 classes.powertools-tracingships this format today, so its automatic priming is a no-op in released versions.This change replaces
stripTrailing()withstrip(), which removes leading and trailing whitespace.strip()handles both file formats, so no resource files need to change.I added a regression test that references a class with a leading space in the test
classesloaded.txt. The test fails on the current code and passes with the fix. I also confirmed the fix on a deployed Lambda: preloaded classes went from 0 to 4062.Issue number: #2559
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.