isEmpty()
101 String sql = "select * from user where userID =" + id + " and role = 1";
102 result = jdbcTemplate.query(sql, (rs, rowNum) -> new User(rs.getLong("userID"), rs.getString("firstName"), rs.getString("lastName"), rs.getString("email"), rs.getString("username"), rs.getString("password"), rs.getString("role"),rs.getString("salt")));
103 }
104 if (result.size() <= 0)105 return null;
106 return result.get(0);
107 }
A comparison involving the size of a collection or an array was found, which is always guaranteed to be either true or false.
This is a generally frivolous action and may have been caused by a typo. If this was done to prevent certain code from executing or to ensure some code always executes for debugging purposes, remove it. All debugging-related code changes should be cleaned up after their purpose is served.
Consider revisiting the expression to make sure such a comparison was intended.
Bad Practice
Certain comparisons don't ever make sense when dealing with the size of a collection or an array's length.
Consider:
someArray.length < 0
The expression above always evaluates to false
since it is impossible for an array to have a negative length.
Similarly, the following comparison is functionally useless:
someCollection.size() >= 0
The usual state of affairs is that collections cannot have negative sizes. It thus makes no sense to explicitly check if the size of a collection is non-negative as has been done here.
Recommended
Do not perform comparisons that are guaranteed to result in the same value everytime.
if (coll.size() > 24) {
// ...
}
If you need to check for when a collection is empty, you can use the isEmpty()
method to do so:
if (coll.isEmpty()) {
// ...
}