Copilot commented on code in PR #911:
URL: https://github.com/apache/ranger/pull/911#discussion_r3060051723
##########
agents-common/src/main/java/org/apache/ranger/plugin/util/RangerRESTUtils.java:
##########
@@ -143,12 +142,22 @@ public String getAppIdFromPluginId(String pluginId) {
return ret;
}
- static {
- try {
- hostname = Hostname.getHostname();
- } catch (Exception e) {
- LOG.error("ERROR: Unable to find hostname for the agent ", e);
- hostname = "unknownHost";
+ private static String getHostname() {
+ String hostname = System.getenv("HOSTNAME");
+
+ if (StringUtils.isEmpty(hostname)) {
+ hostname = System.getenv("COMPUTERNAME");
+
+ if (StringUtils.isBlank(hostname)) {
Review Comment:
`getHostname()` uses `StringUtils.isEmpty()` for the `HOSTNAME` env var,
which treats whitespace-only values as non-empty and would return a
blank/invalid hostname. Use `StringUtils.isBlank()` (and consider trimming) for
`HOSTNAME` as well so the fallback path is taken when the env var is present
but blank.
--
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]