Copilot commented on code in PR #11541:
URL: https://github.com/apache/ozone/pull/11541#discussion_r4276409041
##########
hadoop-hdds/framework/src/main/java/org/apache/hadoop/hdds/utils/HddsServerUtil.java:
##########
@@ -199,6 +200,21 @@ public static List<InetAddress>
getValidInetsForCurrentHost()
return hostIps;
}
+ /**
+ * A network interface returns every IPv6 address with the interface as
scope, which
+ * {@link #isScopedOrMaskingIPv6Address(InetAddress)} rejects. Only a
link-local address needs the scope, so it is
+ * dropped from any other address.
+ *
+ * @param addr the InetAddress as returned by a network interface
+ * @return the address without scope, or the same address if it is
link-local or not an IPv6 address
+ */
+ public static InetAddress dropScopeUnlessLinkLocal(InetAddress addr) throws
UnknownHostException {
+ if (addr instanceof Inet6Address && !addr.isLinkLocalAddress()) {
+ return InetAddress.getByAddress(addr.getAddress());
+ }
+ return addr;
+ }
Review Comment:
`dropScopeUnlessLinkLocal` declares `throws UnknownHostException`, but
`InetAddress.getByAddress(byte[])` does not throw it. Keeping the checked
exception forces unnecessary exception handling/propagation and requires an
extra import. Consider removing the `throws UnknownHostException` from the
method signature (and the corresponding import), then updating call sites/tests
accordingly.
##########
hadoop-hdds/framework/src/main/java/org/apache/hadoop/hdds/utils/HddsServerUtil.java:
##########
@@ -68,6 +68,7 @@
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.NetworkInterface;
+import java.net.UnknownHostException;
Review Comment:
`dropScopeUnlessLinkLocal` declares `throws UnknownHostException`, but
`InetAddress.getByAddress(byte[])` does not throw it. Keeping the checked
exception forces unnecessary exception handling/propagation and requires an
extra import. Consider removing the `throws UnknownHostException` from the
method signature (and the corresponding import), then updating call sites/tests
accordingly.
##########
hadoop-hdds/framework/src/main/java/org/apache/hadoop/hdds/utils/HddsServerUtil.java:
##########
@@ -199,6 +200,21 @@ public static List<InetAddress>
getValidInetsForCurrentHost()
return hostIps;
}
+ /**
+ * A network interface returns every IPv6 address with the interface as
scope, which
+ * {@link #isScopedOrMaskingIPv6Address(InetAddress)} rejects. Only a
link-local address needs the scope, so it is
+ * dropped from any other address.
+ *
+ * @param addr the InetAddress as returned by a network interface
+ * @return the address without scope, or the same address if it is
link-local or not an IPv6 address
+ */
+ public static InetAddress dropScopeUnlessLinkLocal(InetAddress addr) throws
UnknownHostException {
+ if (addr instanceof Inet6Address && !addr.isLinkLocalAddress()) {
+ return InetAddress.getByAddress(addr.getAddress());
+ }
Review Comment:
`Inet6Address` is referenced but not imported in this file, which will fail
compilation. Add `import java.net.Inet6Address;` (or fully-qualify the type) to
make this compile.
--
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]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]