"Calendars" and "DateFormats" should not be static
2017-02-22 23:57
543 查看
参见:Call to method of static java.text.DateFormat not advisable?
后面这种solution也不能保证安全性,要保证完全安全性只能是使用局部变量进行栈封闭
级别:bug, multi-threading Not all classes in the standard Java library were written to be thread-safe. Using them in a multi-threaded manner is highly likely to cause data problems or exceptions at runtime. This rule raises an issue when an instance of Calendar, DateFormat, javax.xml.xpath.XPath, or javax.xml.validation.SchemaFactory is marked static.
Noncompliant Code Example:
public class MyClass { static private SimpleDateFormat format = new SimpleDateFormat("HH-mm-ss"); // Noncompliant static private Calendar calendar = Calendar.getInstance(); // Noncompliant
Compliant Solution:
public class MyClass { private SimpleDateFormat format = new SimpleDateFormat("HH-mm-ss"); private Calendar calendar = Calendar.getInstance();
后面这种solution也不能保证安全性,要保证完全安全性只能是使用局部变量进行栈封闭
相关文章推荐
- "Calendars" and "DateFormats" should not be static
- "==" and "!=" should not be used when "equals" is overridden
- "enum" fields should not be publicly mutable
- PaodingAnalysis 提示 "dic home should not be a file, but a directory"
- Linux下开发warning:"the `gets' function is dangerous and should not be used"
- "the current fsmo could not be contacted" when change rid role
- java中如何将每个单词的字母反转,就是将"To be or not to be "变成“oT eb ro ton ot eb”
- 快速解决"is marked as crashed and should be repaired"故障以及is marked as crashed and last (automatic?)
- Non-static method cls_image::gd_version() should not be called statically in D:\X\www\ecshop\install
- When should static_cast, dynamic_cast and reinterpret_cast be used?
- 在Linux C++中要区分”>>" 和"> >" ——`>>' should be `> >' within a nested template argument list
- the update-modules command is deprecated and should not be used
- Visual Studio使用"go to definition"出现"A definition for the symbol '<symbolName>' could not be located
- "mkimage" command not found - U-Boot images will not be built
- "The target '__Page' for the callback could not be found or did not implement ICallbackEventHandler."的解决办法
- [MySQL]快速解决"is marked as crashed and should be repaired"故障
- "error: device not found" and "error:device offline"
- Android开发中Layout中明明改了id,但是还出现"cannot be resolved or is not a field"的原因
- "Computer Science" is Not Science and "Software Engineering" is Not Engineering
- "The object cannot be deleted because it was not found in the ObjectStateManager."