Copilot commented on code in PR #13458: URL: https://github.com/apache/gravitino/pull/13458#discussion_r4157778227
########## core/src/main/java/org/apache/gravitino/listener/api/event/semantic/AlterSemanticModelEvent.java: ########## @@ -0,0 +1,74 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.gravitino.listener.api.event.semantic; + +import org.apache.gravitino.NameIdentifier; +import org.apache.gravitino.annotation.DeveloperApi; +import org.apache.gravitino.listener.api.event.OperationType; +import org.apache.gravitino.listener.api.info.SemanticModelInfo; +import org.apache.gravitino.semantic.SemanticModelChange; + +/** Successful alter-Semantic-Model event. */ +@DeveloperApi +public final class AlterSemanticModelEvent extends SemanticModelEvent { + private final SemanticModelChange[] semanticModelChanges; + private final SemanticModelInfo updatedSemanticModelInfo; + + /** + * Constructs an instance of {@code AlterSemanticModelEvent}. + * + * @param user The username of the individual who initiated the alteration. + * @param identifier The identifier of the altered Semantic Model. + * @param semanticModelChanges The applied changes. + * @param updatedSemanticModelInfo The Semantic Model information after the alteration. + */ + public AlterSemanticModelEvent( + String user, + NameIdentifier identifier, + SemanticModelChange[] semanticModelChanges, + SemanticModelInfo updatedSemanticModelInfo) { + super(user, identifier); + this.semanticModelChanges = semanticModelChanges.clone(); + this.updatedSemanticModelInfo = updatedSemanticModelInfo; + } + + /** + * Returns the applied Semantic Model changes. + * + * @return The Semantic Model changes. + */ + public SemanticModelChange[] semanticModelChanges() { + return semanticModelChanges; Review Comment: Returning the backing array defeats the constructor's defensive copy. `EventBus` passes the same event instance to each listener, so one listener can mutate these changes and alter what later listeners observe. Return a clone from the accessor as well. ########## core/src/main/java/org/apache/gravitino/listener/api/event/semantic/AlterSemanticModelFailureEvent.java: ########## @@ -0,0 +1,62 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.gravitino.listener.api.event.semantic; + +import org.apache.gravitino.NameIdentifier; +import org.apache.gravitino.annotation.DeveloperApi; +import org.apache.gravitino.listener.api.event.OperationType; +import org.apache.gravitino.semantic.SemanticModelChange; + +/** Failure event for altering a Semantic Model. */ +@DeveloperApi +public final class AlterSemanticModelFailureEvent extends SemanticModelFailureEvent { + private final SemanticModelChange[] semanticModelChanges; + + /** + * Constructs an instance of {@code AlterSemanticModelFailureEvent}. + * + * @param user The username of the individual who initiated the alteration. + * @param identifier The identifier of the Semantic Model being altered. + * @param exception The exception that caused the failure. + * @param semanticModelChanges The changes that failed to apply. + */ + public AlterSemanticModelFailureEvent( + String user, + NameIdentifier identifier, + Exception exception, + SemanticModelChange[] semanticModelChanges) { + super(user, identifier, exception); + this.semanticModelChanges = semanticModelChanges.clone(); + } + + /** + * Returns the Semantic Model changes that failed to apply. + * + * @return The Semantic Model changes. + */ + public SemanticModelChange[] semanticModelChanges() { + return semanticModelChanges; Review Comment: Returning the backing array defeats the constructor's defensive copy. `EventBus` passes the same event instance to each listener, so one listener can mutate the failure payload seen by later listeners. Return a clone from the accessor as well. ########## core/src/main/java/org/apache/gravitino/listener/api/event/semantic/AlterSemanticModelPreEvent.java: ########## @@ -0,0 +1,58 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.gravitino.listener.api.event.semantic; + +import org.apache.gravitino.NameIdentifier; +import org.apache.gravitino.annotation.DeveloperApi; +import org.apache.gravitino.listener.api.event.OperationType; +import org.apache.gravitino.semantic.SemanticModelChange; + +/** Pre-event before altering a Semantic Model. */ +@DeveloperApi +public class AlterSemanticModelPreEvent extends SemanticModelPreEvent { + private final SemanticModelChange[] semanticModelChanges; + + /** + * Constructs an instance of {@code AlterSemanticModelPreEvent}. + * + * @param user The username of the individual who initiated the alteration. + * @param identifier The identifier of the Semantic Model being altered. + * @param semanticModelChanges The changes to apply. + */ + public AlterSemanticModelPreEvent( + String user, NameIdentifier identifier, SemanticModelChange[] semanticModelChanges) { + super(user, identifier); + this.semanticModelChanges = semanticModelChanges.clone(); + } + + /** + * Returns the changes to apply to the Semantic Model. + * + * @return The Semantic Model changes. + */ + public SemanticModelChange[] semanticModelChanges() { + return semanticModelChanges; Review Comment: Returning the backing array defeats the constructor's defensive copy. `EventBus` passes the same pre-event instance to each listener, so one listener can mutate the changes observed by subsequent listeners. Return a clone from the accessor as well. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
