CWE-366 应用程序正在以某种方式使用共享资源 MessageFormat.format,这不是线程安全的

问题描述 投票:0回答:0

分析代码质量的工具抱怨 MessageFormat.format 不是线程安全的。示例如下:

@Override
public String toString() {
   return MessageFormat.format("Person'{'name={0}, address = {1}'}'",
 name, address);                   
}       

MessageFormat.format的代码如下

public static String format(String pattern, Object ... arguments) {
    MessageFormat temp = new MessageFormat(pattern);
    return temp.format(arguments);
}

我可以看到每次格式化字符串时都会创建一个新的 MessageFormat。

我是不是遗漏了什么或者工具有误?

java owasp java-threads
© www.soinside.com 2019 - 2024. All rights reserved.