[
https://issues.apache.org/jira/browse/LANG-1472?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16906010#comment-16906010
]
Michael Osipov commented on LANG-1472:
--------------------------------------
The method relies on environment variables. The variable {{HOSTNAME}} is not
set. Therefore the NPE.
> SystemUtils.getHostName()获取系统hostname为null
> ------------------------------------------
>
> Key: LANG-1472
> URL: https://issues.apache.org/jira/browse/LANG-1472
> Project: Commons Lang
> Issue Type: Bug
> Components: lang.*
> Affects Versions: 3.9
> Environment: * 操作系统:阿里云提供的Ubuntu 16.04
> root@iZwz99ibpdra8w3j3jcbw7Z:~# hostname
> iZwz99ibpdra8w3j3jcbw7Z
> root@iZwz99ibpdra8w3j3jcbw7Z:~# echo $HOSTNAME
> iZwz99ibpdra8w3j3jcbw7Z
> * 语言:Java 8
> root@iZwz99ibpdra8w3j3jcbw7Z:~# java -version
> java version "1.8.0_191"
> Java(TM) SE Runtime Environment (build 1.8.0_191-b12)
> Java HotSpot(TM) 64-Bit Server VM (build 25.191-b12, mixed mode)
> Reporter: wangrubao
> Priority: Critical
> Attachments: SnowflakeIdWorker.java, error.png, pom.xml
>
>
> SpringBoot 项目获取系统 hostname 为 null 导致 java.lang.NullPointerException 。
> 部分代码:
> private static Long getDataCenterId(){
> int[] ints = StringUtils.toCodePoints(SystemUtils.getHostName());
> int sums = 0;
> for (int i: ints) {
> sums += i;
> }
> return (long)(sums % 32);
> }
--
This message was sent by Atlassian JIRA
(v7.6.14#76016)