diff --git a/.all-contributorsrc b/.all-contributorsrc
index 3ccf2e8784..e26a244d2f 100644
--- a/.all-contributorsrc
+++ b/.all-contributorsrc
@@ -7866,6 +7866,15 @@
"code"
]
},
+ {
+ "login": "chenguangqi",
+ "name": "天热吃西瓜",
+ "avatar_url": "https://avatars.githubusercontent.com/u/6231010?v=4",
+ "profile": "http://chenguangqi.github.io/",
+ "contributions": [
+ "bug"
+ ]
+ },
{
"login": "wahajenius",
"name": "Willem A. Hajenius",
diff --git a/docs/pages/pmd/projectdocs/credits.md b/docs/pages/pmd/projectdocs/credits.md
index 8bedbc0f63..b6ccbdf647 100644
--- a/docs/pages/pmd/projectdocs/credits.md
+++ b/docs/pages/pmd/projectdocs/credits.md
@@ -1116,6 +1116,7 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d
zzzzfeng 🐛 |
Árpád Magosányi 🐛 |
任贵杰 🐛 |
+ 天热吃西瓜 🐛 |
茅延安 💻 |
diff --git a/docs/pages/release_notes.md b/docs/pages/release_notes.md
index f9967dcfc3..b7ab311cb1 100644
--- a/docs/pages/release_notes.md
+++ b/docs/pages/release_notes.md
@@ -23,6 +23,8 @@ This is a {{ site.pmd.release_type }} release.
* [#5293](https://github.com/pmd/pmd/issues/5293): \[java] Deadlock when executing PMD in multiple threads
* [#5324](https://github.com/pmd/pmd/issues/5324): \[java] Issue with type inference of nested lambdas
* [#5329](https://github.com/pmd/pmd/issues/5329): \[java] Type inference issue with unknown method ref in call chain
+* java-performance
+ * [#5314](https://github.com/pmd/pmd/issues/5314): \[java] InsufficientStringBufferDeclarationRule: Lack of handling for char type parameters
### 🚨 API Changes
diff --git a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/performance/InsufficientStringBufferDeclarationRule.java b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/performance/InsufficientStringBufferDeclarationRule.java
index a6fabf91a2..5acd063c15 100644
--- a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/performance/InsufficientStringBufferDeclarationRule.java
+++ b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/performance/InsufficientStringBufferDeclarationRule.java
@@ -240,6 +240,12 @@ public class InsufficientStringBufferDeclarationRule extends AbstractJavaRulecha
private int calculateExpression(ASTExpression expression) {
Object value = expression.getConstValue();
- return value == null ? State.UNKNOWN_CAPACITY : (Integer) value;
+ if (value == null) {
+ return State.UNKNOWN_CAPACITY;
+ }
+ if (value instanceof Character) {
+ return (Character) value;
+ }
+ return (Integer) value;
}
}
diff --git a/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/rule/performance/xml/InsufficientStringBufferDeclaration.xml b/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/rule/performance/xml/InsufficientStringBufferDeclaration.xml
index ec267fcfcc..bd5d364eb1 100644
--- a/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/rule/performance/xml/InsufficientStringBufferDeclaration.xml
+++ b/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/rule/performance/xml/InsufficientStringBufferDeclaration.xml
@@ -1419,4 +1419,23 @@ public class LiteralExpression {
}
]]>
+
+
+ #5314 [java] InsufficientStringBufferDeclarationRule: Lack of handling for char type parameters
+ 0
+
+