Skip to content

Commit

Permalink
[apache#3941] fix(common): Fix potential bug of TopicDTO (apache#3942)
Browse files Browse the repository at this point in the history
### What changes were proposed in this pull request?

return a new instance when `build()` called

### Why are the changes needed?

Fix: apache#3941 

### Does this PR introduce _any_ user-facing change?

no

### How was this patch tested?

by logic
  • Loading branch information
mchades authored Jun 24, 2024
1 parent cc5e67b commit ca9f220
Showing 1 changed file with 10 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,12 @@ public int hashCode() {

/** A builder for constructing a Topic DTO. */
public static class Builder {
private final TopicDTO topic;
private String name;
private String comment;
private Map<String, String> properties;
private AuditDTO audit;

private Builder() {
topic = new TopicDTO();
}
private Builder() {}

/**
* Sets the name of the topic.
Expand All @@ -105,7 +106,7 @@ private Builder() {
* @return The builder instance.
*/
public Builder withName(String name) {
topic.name = name;
this.name = name;
return this;
}

Expand All @@ -116,7 +117,7 @@ public Builder withName(String name) {
* @return The builder instance.
*/
public Builder withComment(String comment) {
topic.comment = comment;
this.comment = comment;
return this;
}

Expand All @@ -127,7 +128,7 @@ public Builder withComment(String comment) {
* @return The builder instance.
*/
public Builder withProperties(Map<String, String> properties) {
topic.properties = properties;
this.properties = properties;
return this;
}

Expand All @@ -138,13 +139,13 @@ public Builder withProperties(Map<String, String> properties) {
* @return The builder instance.
*/
public Builder withAudit(AuditDTO audit) {
topic.audit = audit;
this.audit = audit;
return this;
}

/** @return The constructed Topic DTO. */
public TopicDTO build() {
return topic;
return new TopicDTO(name, comment, properties, audit);
}
}
}

0 comments on commit ca9f220

Please sign in to comment.