Commit 52be6d5f authored by zengtianlai3's avatar zengtianlai3

解决null引用

parent 6bef9021
...@@ -46,7 +46,10 @@ public class BalanceManager { ...@@ -46,7 +46,10 @@ public class BalanceManager {
} catch (NoSuchAlgorithmException e) { } catch (NoSuchAlgorithmException e) {
log.error("SecureRandom 不可用"); log.error("SecureRandom 不可用");
} }
int index = secureRandom.nextInt(count); int index = 0;
if (secureRandom != null) {
index = secureRandom.nextInt(count);
}
List<Server> servers = new ArrayList<>(allServers.values()); List<Server> servers = new ArrayList<>(allServers.values());
return servers.get(index); return servers.get(index);
} }
......
...@@ -22,7 +22,7 @@ public class CommonUtil { ...@@ -22,7 +22,7 @@ public class CommonUtil {
*/ */
public static String genRandomNum(int length) { public static String genRandomNum(int length) {
int maxNum = 36; int maxNum = 36;
int i; int i = -1;
int count = 0; int count = 0;
char[] str = { 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', char[] str = { 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S',
'T', 'U', 'V', 'W', 'X', 'Y', 'Z', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9' }; 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9' };
...@@ -34,7 +34,9 @@ public class CommonUtil { ...@@ -34,7 +34,9 @@ public class CommonUtil {
log.error("随机生成字符串失败"); log.error("随机生成字符串失败");
} }
while (count < length) { while (count < length) {
if (secureRandom != null) {
i = Math.abs(secureRandom.nextInt(maxNum)); i = Math.abs(secureRandom.nextInt(maxNum));
}
if (i >= 0 && i < str.length) { if (i >= 0 && i < str.length) {
pwd.append(str[i]); pwd.append(str[i]);
count++; count++;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment