From 0c61c5d5eb01fee5c06d20ea771af91bfae6438e Mon Sep 17 00:00:00 2001 From: liushaoyu-soft <455028117@qq.com> Date: Thu, 11 Aug 2022 14:32:50 +0800 Subject: [PATCH] [ISSUES#8905]simplify some code (#8908) --- .../com/alibaba/nacos/common/utils/MD5Utils.java | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/common/src/main/java/com/alibaba/nacos/common/utils/MD5Utils.java b/common/src/main/java/com/alibaba/nacos/common/utils/MD5Utils.java index ae9fb6ab9..26a674afc 100644 --- a/common/src/main/java/com/alibaba/nacos/common/utils/MD5Utils.java +++ b/common/src/main/java/com/alibaba/nacos/common/utils/MD5Utils.java @@ -30,16 +30,13 @@ public class MD5Utils { private static final char[] DIGITS_LOWER = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'}; - private static final ThreadLocal MESSAGE_DIGEST_LOCAL = new ThreadLocal() { - @Override - protected MessageDigest initialValue() { - try { - return MessageDigest.getInstance("MD5"); - } catch (NoSuchAlgorithmException e) { - return null; - } + private static final ThreadLocal MESSAGE_DIGEST_LOCAL = ThreadLocal.withInitial(() -> { + try { + return MessageDigest.getInstance("MD5"); + } catch (NoSuchAlgorithmException e) { + return null; } - }; + }); /** * Calculate MD5 hex string.