Copilot commented on code in PR #1292:
URL: https://github.com/apache/ratis/pull/1292#discussion_r2386027734


##########
ratis-server/src/main/java/org/apache/ratis/server/impl/ServerImplUtils.java:
##########
@@ -170,8 +170,8 @@ public static RaftServerProxy newRaftServer(
       RaftPeerId id, RaftGroup group, RaftStorage.StartupOption option, 
StateMachine.Registry stateMachineRegistry,
       ThreadGroup threadGroup, RaftProperties properties, Parameters 
parameters) throws IOException {
     RaftServer.LOG.debug("newRaftServer: {}, {}", id, group);
+    Objects.requireNonNull(id, "id == null");
     if (group != null && !group.getPeers().isEmpty()) {
-      Objects.requireNonNull(id, () -> "RaftPeerId " + id + " is not in 
RaftGroup " + group);
       Objects.requireNonNull(group.getPeer(id), () -> "RaftPeerId " + id + " 
is not in RaftGroup " + group);

Review Comment:
   The null check for `id` has been moved before the group validation, but the 
lambda expression in line 175 still references `id` which could be null if the 
previous check fails. The error message should be updated to handle the case 
where `id` might be null.
   ```suggestion
         Objects.requireNonNull(group.getPeer(id), () -> "RaftPeerId " + 
String.valueOf(id) + " is not in RaftGroup " + group);
   ```



##########
ratis-common/src/main/java/org/apache/ratis/util/VersionInfo.java:
##########
@@ -0,0 +1,133 @@
+/*
+ * 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.ratis.util;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.Collections;
+import java.util.EnumMap;
+import java.util.LinkedHashMap;
+import java.util.Map;
+import java.util.Objects;
+import java.util.Properties;
+import java.util.function.Consumer;
+
+/**
+ * This class is for the resource generated by 
hadoop-maven-plugins:version-info.
+ * <p>
+ * This class is immutable.
+ */
+public final class VersionInfo {
+  static final Logger LOG = LoggerFactory.getLogger(VersionInfo.class);
+
+  private static final String VERSION_PROPERTIES = "ratis-version.properties";
+  private static final String UNKNOWN = "<unknown>";
+  private static final String FORMAT = "  %20s: %s";
+
+  private enum Key {
+    NAME, VERSION, REVISION, URL, JAVA_VERSION;
+
+    static Key parse(String key) {
+      for (Key k : Key.values()) {
+        if (k.getLowerCaseName().equals(key)) {
+          return k;
+        }
+      }
+      return null;
+    }
+
+    private final String lowerCaseName = name().toLowerCase();
+
+    String getLowerCaseName() {
+      return lowerCaseName;
+    }
+  }
+
+  private static class KeyMap {
+    private final Map<Key, String> map;
+
+    KeyMap(EnumMap<Key, String> map) {
+      this.map = Collections.unmodifiableMap(map);
+    }
+
+    String getOrDefault(Key key) {
+      return map.getOrDefault(key, UNKNOWN);
+    }
+
+    String format(Key key) {
+      return String.format(FORMAT, key.getLowerCaseName(), getOrDefault(key));
+    }
+  }
+
+  public static VersionInfo load(Class<?> clazz) {
+    final Properties properties = new Properties();
+
+    try (InputStream in = 
clazz.getClassLoader().getResourceAsStream(VERSION_PROPERTIES)) {
+      properties.load(in);

Review Comment:
   The `InputStream` could be null if the resource is not found, which would 
cause a NullPointerException when trying to load properties. Add a null check 
before calling `properties.load(in)`.
   ```suggestion
         if (in != null) {
           properties.load(in);
         } else {
           LOG.warn("Resource '{}' not found for {}", VERSION_PROPERTIES, 
clazz);
         }
   ```



-- 
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]

Reply via email to