Home > Blockchain >  looking for the reason for NPE in LinuxNetworkParams.getDomainName call
looking for the reason for NPE in LinuxNetworkParams.getDomainName call

Time:11-08

We are seeing the NPE in the LinuxNetworkParams.getDomainName call in oshi version 6.1.6. Although I am not able to see any reason for this. Can anyone help me when with the reasons why this can throw NPE?

Caused by: java.lang.NullPointerException
at oshi.software.os.linux.LinuxNetworkParams.getDomainName(LinuxNetworkParams.java:80) ~[oshi-core-6.1.6.jar!/:6.1.6]
at com.airwatch.common.diagnostics.DiagnosticCollector.fetchSystemConfiguration(DiagnosticCollector.java:148) ~[diagnostic-library-2.0.3.jar!/:?]

Here is the code for the method : https://github.com/oshi/oshi/blob/oshi-parent-6.1.6/oshi-core/src/main/java/oshi/software/os/linux/LinuxNetworkParams.java#L79-L80

CodePudding user response:

Looks like info.ai_canonname is null, Try adding null check for ai_canonname or use null safe way to do trim like StringUtils.trim()

public static String trim(final String str) {
    return str == null ? null : str.trim();
}

CodePudding user response:

As @Jishnu-Prathap said in their answer, info.ai_canonname is null.

This value normally returns the "official name of the host" in response to the getaddrinfo() function whose docs state:

If hints.ai_flags includes the AI_CANONNAME flag, then the ai_canonname field of the first of the addrinfo structures in the returned list is set to point to the official name of the host.

This may represent an error in your server configuration; fixing the "official name of the host" will prevent the NPE if you keep the same OSHI version.

However, failing to null-check this value was a bug in earlier versions of OSHI but was fixed in version 6.2.2 and upgrading will also prevent the NPE (but not give you a canonical host name, since it doesn't exist!)

  • Related