Skip to content

Switch order of literals to prevent NullPointerException#2

Open
pixee-f1759869d20e4af7[bot] wants to merge 1 commit into
mainfrom
pixeebot/drip-2024-05-03-pixee-java/switch-literal-first
Open

Switch order of literals to prevent NullPointerException#2
pixee-f1759869d20e4af7[bot] wants to merge 1 commit into
mainfrom
pixeebot/drip-2024-05-03-pixee-java/switch-literal-first

Conversation

@pixee-f1759869d20e4af7
Copy link
Copy Markdown

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:

  String fieldName = header.getFieldName();
  String fieldValue = header.getFieldValue();
- if(fieldName.equals("requestId")) {
+ if("requestId".equals(fieldName)) {
    logRequest(fieldValue);
  }
More reading

🧚🤖Powered by Pixeebot (codemod ID: pixee:java/switch-literal-first)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

0 participants