From ca9f2201cb7d133f912328d82bf26df08b36db9b Mon Sep 17 00:00:00 2001 From: mchades Date: Mon, 24 Jun 2024 10:52:25 +0800 Subject: [PATCH] [#3941] fix(common): Fix potential bug of TopicDTO (#3942) ### What changes were proposed in this pull request? return a new instance when `build()` called ### Why are the changes needed? Fix: #3941 ### Does this PR introduce _any_ user-facing change? no ### How was this patch tested? by logic --- .../gravitino/dto/messaging/TopicDTO.java | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/common/src/main/java/com/datastrato/gravitino/dto/messaging/TopicDTO.java b/common/src/main/java/com/datastrato/gravitino/dto/messaging/TopicDTO.java index f060f3d98f1..2be3b9920e7 100644 --- a/common/src/main/java/com/datastrato/gravitino/dto/messaging/TopicDTO.java +++ b/common/src/main/java/com/datastrato/gravitino/dto/messaging/TopicDTO.java @@ -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 properties; + private AuditDTO audit; - private Builder() { - topic = new TopicDTO(); - } + private Builder() {} /** * Sets the name of the topic. @@ -105,7 +106,7 @@ private Builder() { * @return The builder instance. */ public Builder withName(String name) { - topic.name = name; + this.name = name; return this; } @@ -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; } @@ -127,7 +128,7 @@ public Builder withComment(String comment) { * @return The builder instance. */ public Builder withProperties(Map properties) { - topic.properties = properties; + this.properties = properties; return this; } @@ -138,13 +139,13 @@ public Builder withProperties(Map 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); } } }