GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — [java] ConsecutiveLiteralAppends and InsufficientStringBufferDeclaration: FP with switch expressions · Issue #3152 · pmd/pmd Closed DescriptionSince PMD 6.27.0, still in the latest 6.32.0, needs at least Java15 due to Switch Expressions Rules: ConsecutiveLiteralAppends and InsufficientStringBufferDeclaration I encountered similar issues, with PMD 6.31.0/6.32.0 the following code are causing both PMD.InsufficientStringBufferDeclaration, PMD.ConsecutiveLiteralAppends public class FalsePositive { public static String escapeHTML(String text) { int length = text.length(); int index = findHTMLReservedChar(text); if (index == length) return text; var builder = new StringBuilder(length * 2); // Rule:InsufficientStringBufferDeclaration Priority:3 StringBuffer constructor is initialized with size 16, but has at least 29 characters appended.. for (int i = 0; i < index; i++) builder.append(text.charAt(i)); for (; index < length; index++) { char ch = text.charAt(index); switch (ch) { case '<' -> builder.append("<"); // Rule:ConsecutiveLiteralAppends Priority:3 StringBuffer (or StringBuilder).append is called 6 consecutive times with literals. Use a single append with a single combined String.. case '>' -> builder.append(">"); case '"' -> builder.append("""); case '&' -> builder.append("&"); case '\'' -> builder.append("'"); case '/' -> builder.append("/"); default -> builder.append(ch); } } return builder.toString(); } private static int findHTMLReservedChar(String text) { return 0; } } Originally posted by @neowu in #2427 (comment) Activity
MetadataMetadataAssigneesLabelsa:false-positivePMD flags a piece of code that is not problematic TypeProjectsMilestoneRelationshipsDevelopmentIssue actions |
| You are visitor 01402775 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |