Code quality fixes#9348
Conversation
- String comparison using of == or != instead of equals(). - Number equality using == or != instead of equals(). - Expression compared to itself. - Long literal ending with lowercase 'l'. - Empty finally blocks. - Logging placeholders does not match number of arguments in logging call. - Serializable classes whose serialVersionUID field is not declared private static final long
2154b58 to
31ba6e3
Compare
| if (link.getId() != other.link.getId()) | ||
| return false; | ||
| if (metadataId.intValue() != metadataId.intValue()) | ||
| if (metadataId.intValue() != other.metadataId.intValue()) |
There was a problem hiding this comment.
The fixed equals() now calls both metadataId.intValue() and other.metadataId.intValue(), but metadataId is declared as boxed Integer with no @NotNull constraint. A MetadataLink constructed via the default constructor without calling setMetadataId() leaves the field null, so .intValue() throws NullPointerException.
Consider using Objects.equals(metadataId, other.metadataId) instead to handle the null case safely:
if (!Objects.equals(metadataId, other.metadataId))
return false;Note: hashCode() has the same risk: result = prime * result + metadataId will also unbox and NPE if metadataId is null.
| featuredType == that.featuredType && | ||
| Objects.equals(featuredType, that.featuredType) && | ||
| creatorId == that.creatorId && | ||
| url.equals(that.url) && |
There was a problem hiding this comment.
The PR fixes featuredType on line 181 but the adjacent fields url, creationDate, and creator use bare .equals() without null guards. All three are plain String fields with no @NotNull annotation and no initializer, so a default-constructed LinkDto has them as null. Calling equals() on such an instance throws NullPointerException.
The logo field just below already uses Objects.equals(logo, that.logo). The same pattern should be applied consistently to these three fields:
Objects.equals(url, that.url) &&
Objects.equals(creationDate, that.creationDate) &&
Objects.equals(creator, that.creator) &&| featuredType == that.featuredType && | ||
| Objects.equals(featuredType, that.featuredType) && | ||
| creatorId == that.creatorId && | ||
| url.equals(that.url) && |
There was a problem hiding this comment.
Same issue as LinkDto: url, creationDate, and creator are compared with bare .equals() without null guards. The fields are uninitialized Strings with no @NotNull constraint, so a default-constructed UserSearchDto will throw NullPointerException when equals() is called.
Please apply Objects.equals() consistently here just as was done for featuredType on line 208:
Objects.equals(url, that.url) &&
Objects.equals(creationDate, that.creationDate) &&
Objects.equals(creator, that.creator) &&- Use Objects.equals to avoid NullPointerException in comparisons of fields annotated with @nonnull and no initializer - Update MetadataLink.hash to avoid NullPointerException
6d70001 to
1fd72bc
Compare
|
@juanluisrp thanks for the review, I have addressed the issues, please check. |
Includes the following code fixes:
Checklist
mainbranch, backports managed with labelREADME.mdfilespom.xmldependency management. Update build documentation with intended library use and library tutorials or documentation