Skip to content

Commit

Permalink
fix: use && in equals check to avoid possible NPE (#1927)
Browse files Browse the repository at this point in the history
* fix: use && in equals check to avoid possible NPE

* chore: update goldens
  • Loading branch information
burkedavison authored Aug 17, 2023
1 parent f86eca2 commit 815567c
Show file tree
Hide file tree
Showing 70 changed files with 73 additions and 73 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1349,8 +1349,8 @@ private static MethodDefinition createEqualsMethod(
RelationalOperationExpr.equalToWithExprs(
getClassMethodInvocationExpr,
getClassMethodInvocationExpr.toBuilder().setExprReferenceExpr(argVarExpr).build());
LogicalOperationExpr orLogicalExpr =
LogicalOperationExpr.logicalOrWithExprs(oNotEqualsNullExpr, getClassEqualsExpr);
LogicalOperationExpr andLogicalExpr =
LogicalOperationExpr.logicalAndWithExprs(oNotEqualsNullExpr, getClassEqualsExpr);

// Create second if statement's body assignment expression.
Variable thatVariable = Variable.builder().setName("that").setType(thisClassType).build();
Expand Down Expand Up @@ -1399,11 +1399,11 @@ private static MethodDefinition createEqualsMethod(
.setConditionExpr(oEqualsThisExpr)
.setBody(Arrays.asList(ExprStatement.withExpr(returnTrueExpr)))
.build();
// Code: if (o != null || getClass() == o.getClass()) { FoobarName that = ((FoobarName) o);
// Code: if (o != null && getClass() == o.getClass()) { FoobarName that = ((FoobarName) o);
// return ..}
IfStatement secondIfStatement =
IfStatement.builder()
.setConditionExpr(orLogicalExpr)
.setConditionExpr(andLogicalExpr)
.setBody(
Arrays.asList(
ExprStatement.withExpr(thatAssignmentExpr),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ public class AgentName implements ResourceName {
if (o == this) {
return true;
}
if (o != null || getClass() == o.getClass()) {
if (o != null && getClass() == o.getClass()) {
AgentName that = ((AgentName) o);
return Objects.equals(this.project, that.project)
&& Objects.equals(this.location, that.location);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ public class BillingAccountLocationName implements ResourceName {
if (o == this) {
return true;
}
if (o != null || getClass() == o.getClass()) {
if (o != null && getClass() == o.getClass()) {
BillingAccountLocationName that = ((BillingAccountLocationName) o);
return Objects.equals(this.billingAccount, that.billingAccount)
&& Objects.equals(this.location, that.location);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ public class ResourceName implements com.google.api.resourcenames.ResourceName {
if (o == this) {
return true;
}
if (o != null || getClass() == o.getClass()) {
if (o != null && getClass() == o.getClass()) {
ResourceName that = ((ResourceName) o);
return Objects.equals(this.project, that.project)
&& Objects.equals(this.location, that.location)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ public class FoobarName implements ResourceName {
if (o == this) {
return true;
}
if (o != null || getClass() == o.getClass()) {
if (o != null && getClass() == o.getClass()) {
FoobarName that = ((FoobarName) o);
return Objects.equals(this.project, that.project)
&& Objects.equals(this.foobar, that.foobar)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ public class SessionName implements ResourceName {
if (o == this) {
return true;
}
if (o != null || getClass() == o.getClass()) {
if (o != null && getClass() == o.getClass()) {
SessionName that = ((SessionName) o);
return Objects.equals(this.session, that.session);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ public class TestName implements ResourceName {
if (o == this) {
return true;
}
if (o != null || getClass() == o.getClass()) {
if (o != null && getClass() == o.getClass()) {
TestName that = ((TestName) o);
return Objects.equals(this.session, that.session)
&& Objects.equals(this.shardId, that.shardId)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ public boolean equals(Object o) {
if (o == this) {
return true;
}
if (o != null || getClass() == o.getClass()) {
if (o != null && getClass() == o.getClass()) {
BlurbName that = ((BlurbName) o);
return Objects.equals(this.user, that.user)
&& Objects.equals(this.legacyUser, that.legacyUser)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ public boolean equals(Object o) {
if (o == this) {
return true;
}
if (o != null || getClass() == o.getClass()) {
if (o != null && getClass() == o.getClass()) {
ProfileName that = ((ProfileName) o);
return Objects.equals(this.user, that.user);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ public boolean equals(Object o) {
if (o == this) {
return true;
}
if (o != null || getClass() == o.getClass()) {
if (o != null && getClass() == o.getClass()) {
RoomName that = ((RoomName) o);
return Objects.equals(this.room, that.room);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ public boolean equals(Object o) {
if (o == this) {
return true;
}
if (o != null || getClass() == o.getClass()) {
if (o != null && getClass() == o.getClass()) {
SequenceName that = ((SequenceName) o);
return Objects.equals(this.sequence, that.sequence);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ public boolean equals(Object o) {
if (o == this) {
return true;
}
if (o != null || getClass() == o.getClass()) {
if (o != null && getClass() == o.getClass()) {
SequenceReportName that = ((SequenceReportName) o);
return Objects.equals(this.sequence, that.sequence);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ public boolean equals(Object o) {
if (o == this) {
return true;
}
if (o != null || getClass() == o.getClass()) {
if (o != null && getClass() == o.getClass()) {
SessionName that = ((SessionName) o);
return Objects.equals(this.session, that.session);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ public boolean equals(Object o) {
if (o == this) {
return true;
}
if (o != null || getClass() == o.getClass()) {
if (o != null && getClass() == o.getClass()) {
StreamingSequenceName that = ((StreamingSequenceName) o);
return Objects.equals(this.streamingSequence, that.streamingSequence);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ public boolean equals(Object o) {
if (o == this) {
return true;
}
if (o != null || getClass() == o.getClass()) {
if (o != null && getClass() == o.getClass()) {
StreamingSequenceReportName that = ((StreamingSequenceReportName) o);
return Objects.equals(this.streamingSequence, that.streamingSequence);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ public boolean equals(Object o) {
if (o == this) {
return true;
}
if (o != null || getClass() == o.getClass()) {
if (o != null && getClass() == o.getClass()) {
TestName that = ((TestName) o);
return Objects.equals(this.session, that.session) && Objects.equals(this.test, that.test);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ public boolean equals(Object o) {
if (o == this) {
return true;
}
if (o != null || getClass() == o.getClass()) {
if (o != null && getClass() == o.getClass()) {
UserName that = ((UserName) o);
return Objects.equals(this.user, that.user);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ public boolean equals(Object o) {
if (o == this) {
return true;
}
if (o != null || getClass() == o.getClass()) {
if (o != null && getClass() == o.getClass()) {
BlurbName that = ((BlurbName) o);
return Objects.equals(this.user, that.user)
&& Objects.equals(this.legacyUser, that.legacyUser)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ public boolean equals(Object o) {
if (o == this) {
return true;
}
if (o != null || getClass() == o.getClass()) {
if (o != null && getClass() == o.getClass()) {
ProfileName that = ((ProfileName) o);
return Objects.equals(this.user, that.user);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ public boolean equals(Object o) {
if (o == this) {
return true;
}
if (o != null || getClass() == o.getClass()) {
if (o != null && getClass() == o.getClass()) {
RoomName that = ((RoomName) o);
return Objects.equals(this.room, that.room);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ public boolean equals(Object o) {
if (o == this) {
return true;
}
if (o != null || getClass() == o.getClass()) {
if (o != null && getClass() == o.getClass()) {
SequenceName that = ((SequenceName) o);
return Objects.equals(this.sequence, that.sequence);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ public boolean equals(Object o) {
if (o == this) {
return true;
}
if (o != null || getClass() == o.getClass()) {
if (o != null && getClass() == o.getClass()) {
SequenceReportName that = ((SequenceReportName) o);
return Objects.equals(this.sequence, that.sequence);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ public boolean equals(Object o) {
if (o == this) {
return true;
}
if (o != null || getClass() == o.getClass()) {
if (o != null && getClass() == o.getClass()) {
SessionName that = ((SessionName) o);
return Objects.equals(this.session, that.session);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ public boolean equals(Object o) {
if (o == this) {
return true;
}
if (o != null || getClass() == o.getClass()) {
if (o != null && getClass() == o.getClass()) {
StreamingSequenceName that = ((StreamingSequenceName) o);
return Objects.equals(this.streamingSequence, that.streamingSequence);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ public boolean equals(Object o) {
if (o == this) {
return true;
}
if (o != null || getClass() == o.getClass()) {
if (o != null && getClass() == o.getClass()) {
StreamingSequenceReportName that = ((StreamingSequenceReportName) o);
return Objects.equals(this.streamingSequence, that.streamingSequence);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ public boolean equals(Object o) {
if (o == this) {
return true;
}
if (o != null || getClass() == o.getClass()) {
if (o != null && getClass() == o.getClass()) {
TestName that = ((TestName) o);
return Objects.equals(this.session, that.session) && Objects.equals(this.test, that.test);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ public boolean equals(Object o) {
if (o == this) {
return true;
}
if (o != null || getClass() == o.getClass()) {
if (o != null && getClass() == o.getClass()) {
UserName that = ((UserName) o);
return Objects.equals(this.user, that.user);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ public boolean equals(Object o) {
if (o == this) {
return true;
}
if (o != null || getClass() == o.getClass()) {
if (o != null && getClass() == o.getClass()) {
EndpointName that = ((EndpointName) o);
return Objects.equals(this.project, that.project)
&& Objects.equals(this.endpoint, that.endpoint);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ public boolean equals(Object o) {
if (o == this) {
return true;
}
if (o != null || getClass() == o.getClass()) {
if (o != null && getClass() == o.getClass()) {
FeedName that = ((FeedName) o);
return Objects.equals(this.project, that.project)
&& Objects.equals(this.feed, that.feed)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ public boolean equals(Object o) {
if (o == this) {
return true;
}
if (o != null || getClass() == o.getClass()) {
if (o != null && getClass() == o.getClass()) {
FolderName that = ((FolderName) o);
return Objects.equals(this.folder, that.folder);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ public boolean equals(Object o) {
if (o == this) {
return true;
}
if (o != null || getClass() == o.getClass()) {
if (o != null && getClass() == o.getClass()) {
OrganizationName that = ((OrganizationName) o);
return Objects.equals(this.organization, that.organization);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ public boolean equals(Object o) {
if (o == this) {
return true;
}
if (o != null || getClass() == o.getClass()) {
if (o != null && getClass() == o.getClass()) {
ProjectName that = ((ProjectName) o);
return Objects.equals(this.project, that.project);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ public boolean equals(Object o) {
if (o == this) {
return true;
}
if (o != null || getClass() == o.getClass()) {
if (o != null && getClass() == o.getClass()) {
SavedQueryName that = ((SavedQueryName) o);
return Objects.equals(this.project, that.project)
&& Objects.equals(this.savedQuery, that.savedQuery)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ public boolean equals(Object o) {
if (o == this) {
return true;
}
if (o != null || getClass() == o.getClass()) {
if (o != null && getClass() == o.getClass()) {
InstanceName that = ((InstanceName) o);
return Objects.equals(this.project, that.project)
&& Objects.equals(this.instance, that.instance);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ public boolean equals(Object o) {
if (o == this) {
return true;
}
if (o != null || getClass() == o.getClass()) {
if (o != null && getClass() == o.getClass()) {
TableName that = ((TableName) o);
return Objects.equals(this.project, that.project)
&& Objects.equals(this.instance, that.instance)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ public boolean equals(Object o) {
if (o == this) {
return true;
}
if (o != null || getClass() == o.getClass()) {
if (o != null && getClass() == o.getClass()) {
ServiceAccountName that = ((ServiceAccountName) o);
return Objects.equals(this.project, that.project)
&& Objects.equals(this.serviceAccount, that.serviceAccount);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ public boolean equals(Object o) {
if (o == this) {
return true;
}
if (o != null || getClass() == o.getClass()) {
if (o != null && getClass() == o.getClass()) {
CryptoKeyName that = ((CryptoKeyName) o);
return Objects.equals(this.project, that.project)
&& Objects.equals(this.location, that.location)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ public boolean equals(Object o) {
if (o == this) {
return true;
}
if (o != null || getClass() == o.getClass()) {
if (o != null && getClass() == o.getClass()) {
CryptoKeyVersionName that = ((CryptoKeyVersionName) o);
return Objects.equals(this.project, that.project)
&& Objects.equals(this.location, that.location)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ public boolean equals(Object o) {
if (o == this) {
return true;
}
if (o != null || getClass() == o.getClass()) {
if (o != null && getClass() == o.getClass()) {
ImportJobName that = ((ImportJobName) o);
return Objects.equals(this.project, that.project)
&& Objects.equals(this.location, that.location)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ public boolean equals(Object o) {
if (o == this) {
return true;
}
if (o != null || getClass() == o.getClass()) {
if (o != null && getClass() == o.getClass()) {
KeyRingName that = ((KeyRingName) o);
return Objects.equals(this.project, that.project)
&& Objects.equals(this.location, that.location)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ public boolean equals(Object o) {
if (o == this) {
return true;
}
if (o != null || getClass() == o.getClass()) {
if (o != null && getClass() == o.getClass()) {
LocationName that = ((LocationName) o);
return Objects.equals(this.project, that.project)
&& Objects.equals(this.location, that.location);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ public boolean equals(Object o) {
if (o == this) {
return true;
}
if (o != null || getClass() == o.getClass()) {
if (o != null && getClass() == o.getClass()) {
BookName that = ((BookName) o);
return Objects.equals(this.shelf, that.shelf) && Objects.equals(this.book, that.book);
}
Expand Down
Loading

0 comments on commit 815567c

Please sign in to comment.