Restaurant-Management-System icon indicating copy to clipboard operation
Restaurant-Management-System copied to clipboard

Switch order of literals to prevent NullPointerException

Open zcarroll4 opened this issue 1 year ago • 1 comments

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)

zcarroll4 avatar Oct 29 '23 12:10 zcarroll4

Any thoughts on this pull request? @harismuneer

zcarroll4 avatar Mar 09 '24 18:03 zcarroll4