-
Notifications
You must be signed in to change notification settings - Fork 25k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Static analysis tool for String.format #87166
Comments
Pinging @elastic/es-core-infra (Team:Core/Infra) |
Pinging @elastic/es-delivery (Team:Delivery) |
IntelliJ has an inspection for this, but it's not an error so this can still slip into the codebase. I suspect we could write a custom checkstyle rule for this. |
Do we not already have some prior art with |
we do, but extending ESLoggerUsageChecker to work with String.format is a lot of work. This is because Logger would just allow for ESLoggerUsageChecker in itself is not easy to extend. If there is a easier to adopt tool it would save us a lot of effort |
Sorry, I didn't mean to suggest that we extend |
Related to #103186 |
I suppose the best version of this would handle |
Description
String.format can throw RuntimeException when a format has more place holders than provided arguments. If more arguments is provided, it silently return a result.
When a String.format is used in logging, more importantly in delayed execution for instance
it will not fail when tested without logging level set to trace.
ES should use a static analysis to find out usages of String.format like this (and the Strings.format which is a utility in core)
Sonarqube has a rule for this, maybe it could be adopted?
https://rules.sonarsource.com/java/RSPEC-2275
The text was updated successfully, but these errors were encountered: