canonical / canonical/devpack-for-spring-cli
Improve version string matching in Add plugin recipe
- Dominant language
- Java
- Stars
- 1
- Forks
- 5
- Avg merge
- 1d 20h
- Merged PRs (30d)
- 31
Description
```
─── src/main/java/com/canonical/devpackspring/rewrite/visitors/AddPluginVisitorSupport.java:228-229 ───
[bug · medium] For non-literal version arguments (variables, Groovy GString / Kotlin string
interpolation), `versionMatches` falls back to `expr.toString()`, which on an OpenRewrite tree node
does not reliably return the expression's source text, so the equality check against pluginVersion
is unreliable. This is also inconsistent with `pluginNameFilter()` (below), which conservatively
returns false for non-literals. As a result, a version that actually matches may be treated as a
mismatch and have its plugin statement needlessly replaced. Consider conservatively returning false
for non-literals (as pluginNameFilter does) or using a source-printing helper to extract the text.
- String versionStr = (expr instanceof J.Literal literal && literal.getValue() != null)
- ? literal.getValue().toString() : expr.toString();
+ if (!(expr instanceof J.Literal literal) || literal.getValue() == null) {
+ // Cannot reliably determine version from non-literal expression
+ return false;
+ }
+ String versionStr = literal.getValue().toString();
```
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.