Copilot commented on code in PR #10977:
URL: https://github.com/apache/rocketmq/pull/10977#discussion_r3870571596


##########
common/src/main/java/org/apache/rocketmq/common/utils/BinaryUtil.java:
##########
@@ -23,13 +23,21 @@
 import org.apache.commons.codec.binary.Hex;
 
 public class BinaryUtil {
-    public static byte[] calculateMd5(byte[] binaryData) {
-        MessageDigest messageDigest = null;
+    /**
+     * MessageDigest is not thread safe, so keep one instance per thread 
instead of
+     * looking it up from the provider on every call.
+     */
+    private static final ThreadLocal<MessageDigest> MD5_DIGEST = 
ThreadLocal.withInitial(() -> {
         try {
-            messageDigest = MessageDigest.getInstance("MD5");
+            return MessageDigest.getInstance("MD5");
         } catch (NoSuchAlgorithmException e) {
             throw new RuntimeException("MD5 algorithm not found.");

Review Comment:
   The new RuntimeException message drops the original cause 
(`NoSuchAlgorithmException`), which makes diagnosing provider/algorithm issues 
harder. Prefer throwing an exception that preserves the cause (e.g., 
`IllegalStateException`) and include the algorithm name in the message.



-- 
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]

Reply via email to