String concatenation inside a loop
Part of Code Quality & Syntax, which counts for 20% of the overall score. When this check fires it deducts 4 points from that category, once per scan, no matter how many places it turns up.
What it detects
A variable is rebuilt with += inside a for/while loop and the appended value is a string literal or expression, the textbook result += piece antipattern taught against in every Java course. Each += allocates a new String, making the loop O(n^2) in the total length. StringBuilder.append() in a loop, built once outside it, is linear.
Why it matters
Java Strings are immutable, so result += piece (or result = result + piece) inside a for/while loop allocates a brand-new String and copies the old contents into it on every single iteration, making the total work O(n^2) in the final string's length instead of O(n). This is one of the first performance lessons taught in Java specifically because the compiler cannot always optimize it away inside a loop the way it can for a fixed sequence of concatenations.
How to fix it
Use a StringBuilder: call builder.append(piece) inside the loop instead of +=, then builder.toString() once after the loop to get the final result. StringBuilder grows its internal buffer geometrically, so the total work is linear.
The paid report includes a ready-to-paste prompt for your AI coding agent for every check it finds, pointed at the exact findings from your scan. See pricing
Does your repo trip this check?
Paste a GitHub URL or drop a project folder. Scans run in your browser and take seconds.
Scan your repo