Skip to content

Commit 6286d30

Browse files
fix(sonarqube): bypass 10K result cap by fetching issues per-rule
Closes #33 The issues/search API enforces p*ps <= 10000. With PAGE_SIZE=500, page 21 returns HTTP 400. Fix: iterate per-rule instead of passing all ~600 rules in one query. Each single-rule query stays well under 10K. Also fixes off-by-one in page count (ceiling division) and adds HTTP status checking before reading response body.
1 parent b7b159c commit 6286d30

File tree

1 file changed

+18
-8
lines changed

1 file changed

+18
-8
lines changed

src/main/java/org/owasp/benchmark/report/sonarqube/SonarReport.java

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,16 +35,19 @@ public class SonarReport {
3535
private static final ObjectMapper objectMapper = new ObjectMapper();
3636

3737
public static void main(String[] args) throws Exception {
38-
String allJavaRules = String.join(",", allJavaRules());
38+
Set<String> allJavaRules = allJavaRules();
3939
List<String> issues = new ArrayList<>();
4040
List<String> hotspots = new ArrayList<>();
4141

42-
forAllPagesAt(
43-
"issues/search?componentKeys="
44-
+ SONAR_PROJECT
45-
+ "&types=VULNERABILITY&&rules="
46-
+ allJavaRules,
47-
(result -> issues.addAll(result.issues)));
42+
for (String rule : allJavaRules) {
43+
forAllPagesAt(
44+
"issues/search?componentKeys="
45+
+ SONAR_PROJECT
46+
+ "&types=VULNERABILITY&rules="
47+
+ rule,
48+
(result -> issues.addAll(result.issues)));
49+
}
50+
4851
forAllPagesAt(
4952
"hotspots/search?projectKey=" + SONAR_PROJECT,
5053
(result -> hotspots.addAll(result.hotspots)));
@@ -91,7 +94,9 @@ private static void forAllPagesAt(String apiPath, Consumer<SonarQubeResult> page
9194
objectMapper.readValue(
9295
apiCall(apiPath + pagingSuffix(page, apiPath)), SonarQubeResult.class);
9396

94-
pages = (result.paging.resultCount / PAGE_SIZE) + 1;
97+
pages =
98+
(result.paging.resultCount / PAGE_SIZE)
99+
+ (result.paging.resultCount % PAGE_SIZE == 0 ? 0 : 1);
95100

96101
pageHandlerCallback.accept(result);
97102

@@ -110,6 +115,11 @@ private static String apiCall(String apiPath) throws IOException {
110115
connection.setDoOutput(true);
111116
connection.setRequestProperty("Authorization", "Basic " + sonarAuth);
112117

118+
int status = connection.getResponseCode();
119+
if (status != 200) {
120+
throw new IOException("SonarQube API returned HTTP " + status + " for " + apiPath);
121+
}
122+
113123
return join("\n", readLines(connection.getInputStream(), defaultCharset()));
114124
}
115125

0 commit comments

Comments
 (0)