From 3afacf2405a3f8e973e2756cd0654e5cebb8976b Mon Sep 17 00:00:00 2001 From: "pixeebot[bot]" <104101892+pixeebot[bot]@users.noreply.github.com> Date: Wed, 22 Jan 2025 10:39:47 +0000 Subject: [PATCH] Switch order of literals to prevent NullPointerException (#2769) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This change defensively switches the order of literals in comparison expressions to ensure that no null pointer exceptions are unexpectedly thrown. Runtime exceptions especially can cause exceptional and unexpected code paths to be taken, and this can result in unexpected behavior. Both simple vulnerabilities (like information disclosure) and complex vulnerabilities (like business logic flaws) can take advantage of these unexpected code paths. Our changes look something like this: ```diff String fieldName = header.getFieldName(); String fieldValue = header.getFieldValue(); - if(fieldName.equals("requestId")) { + if("requestId".equals(fieldName)) { logRequest(fieldValue); } ```
More reading * [https://cwe.mitre.org/data/definitions/476.html](https://cwe.mitre.org/data/definitions/476.html) * [https://en.wikibooks.org/wiki/Java_Programming/Preventing_NullPointerException](https://en.wikibooks.org/wiki/Java_Programming/Preventing_NullPointerException) * [https://rules.sonarsource.com/java/RSPEC-1132/](https://rules.sonarsource.com/java/RSPEC-1132/)
🧚🤖 Powered by Pixeebot [Feedback](https://ask.pixee.ai/feedback) | [Community](https://pixee-community.slack.com/signup#/domain-signup) | [Docs](https://docs.pixee.ai/) | Codemod ID: pixee:java/switch-literal-first ![](https://d1zaessa2hpsmj.cloudfront.net/pixel/v1/track?writeKey=2PI43jNm7atYvAuK7rJUz3Kcd6A&event=DRIP_PR%7CStirling-Tools%2FStirling-PDF%7Cc45a84d1797c774f11f1a6a0ccbbd8ee5a208be3) Co-authored-by: pixeebot[bot] <104101892+pixeebot[bot]@users.noreply.github.com> --- .../software/SPDF/service/MetricsAggregatorService.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/stirling/software/SPDF/service/MetricsAggregatorService.java b/src/main/java/stirling/software/SPDF/service/MetricsAggregatorService.java index 61a18938..ad911f96 100644 --- a/src/main/java/stirling/software/SPDF/service/MetricsAggregatorService.java +++ b/src/main/java/stirling/software/SPDF/service/MetricsAggregatorService.java @@ -39,7 +39,7 @@ public class MetricsAggregatorService { if (method == null || uri == null) { return; } - if (!method.equals("GET") && !method.equals("POST")) { + if (!"GET".equals(method) && !"POST".equals(method)) { return; } // Skip URIs that are 2 characters or shorter