# Reorder String Equality Check

# Description

To avoid NullPointerExceptions , it is recommended to put string literals in the left-hand-side of equals() or equalsIgnoreCase() when checking for equality.

# Benefits

This order prevents NullPointerExceptions from being raised, as a string literal can never be null by definition, and therefore makes the code less prone to errors. An example can be seen below.

# Tags

# Code Changes





Use a Java Refactoring Tool

Automate this Refactoring system-wide

You can apply this refactoring for free with the jSparrow Eclipse IDE plug-in.
Install the plug-in for Eclipse IDE: Eclipse Marketplace.

a drawn cute bird pointing at a graph that shows positive results

# Properties

Property Value
Rule ID StringLiteralEqualityCheck
First seen in jSparrow version 2.0.0
Minimum Java version 1.1
Remediation cost 10 min