wang-jiahua commented on code in PR #10977:
URL: https://github.com/apache/rocketmq/pull/10977#discussion_r3877219401
##########
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:
Fixed — the RuntimeException now carries the original
NoSuchAlgorithmException as its cause (commit a7df129).
##########
proxy/src/main/java/org/apache/rocketmq/proxy/grpc/v2/producer/SendMessageActivity.java:
##########
@@ -311,6 +310,35 @@ protected Map<String, String>
buildMessageProperty(ProxyContext context, apache.
return messageWithHeader.getProperties();
}
+ /**
+ * Length of the UTF-8 encoding of {@code str} without materializing the
byte array.
+ * Matches {@code str.getBytes(StandardCharsets.UTF_8).length}, including
the
+ * single-byte replacement for unpaired surrogates.
+ */
+ protected static int utf8Length(String str) {
Review Comment:
Narrowed to package-private — the test lives in the same package, so no need
to expose it to subclasses (commit a7df129).
--
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]