docs: Improve String concatenation best practice#3553
Open
Conversation
This change splits the "don't use String concatenation" best practice into two parts:
- A recommendation concerning performance: string concatenation is not efficient if the logger is off.
- A security recommendation: format string must be constants to prevent `{}` placeholder injection.
The `${dangerousLookup}` part of the example is removed, since lookups are not executed since version `2.15.0`
vy
reviewed
Mar 21, 2025
| + | ||
| [source,java] | ||
| ---- | ||
| /* GOOD */ LOGGER.info(() -> "failed for user ID: " + userId); |
Member
There was a problem hiding this comment.
@ppkarwasz, I think this is a foot gun. It'd be very hard to distinguish for inexperienced users, which is the chief audience of this guide, why it is fine to do string concatenation here, whereas before it was not. IMHO, this should not be supported by the API in the first place, but anyway. In short, unless you strongly object, can we remove this part, please?
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.
This change splits the "don't use String concatenation" best practice into two parts:
{}placeholder injection.The
${dangerousLookup}part of the example is removed, since lookups are not executed since version2.15.0