解决Call to method of static java.text.DateFormat
2013-05-20 11:19
471 查看
今天解决了一个findbug的错误:
Call to method of static java.text.DateFormat in com.pbn.oss.resource.template.input.ws.service.InputTemplateWSServiceImpl.formatDate(Date)
As the JavaDoc states, DateFormats are inherently unsafe for multithreaded use. The detector has found a call to an instance of DateFormat that has been obtained via a static field. This looks suspicous.
初始代码如下:
[java]
view plaincopyprint?
private static final SimpleDateFormat format = new SimpleDateFormat("dd/MM/yyyy");
format.format(new Date());
同一个format 多次调用会导致线性不安全,
可以改为:
[java]
view plaincopyprint?
private static final String COMMON_DATE = "dd/MM/yyyy";
SimpleDateFormat format = new SimpleDateFormat(COMMON_DATE);
format.format(new Date());
Call to method of static java.text.DateFormat in com.pbn.oss.resource.template.input.ws.service.InputTemplateWSServiceImpl.formatDate(Date)
As the JavaDoc states, DateFormats are inherently unsafe for multithreaded use. The detector has found a call to an instance of DateFormat that has been obtained via a static field. This looks suspicous.
初始代码如下:
[java]
view plaincopyprint?
private static final SimpleDateFormat format = new SimpleDateFormat("dd/MM/yyyy");
format.format(new Date());
同一个format 多次调用会导致线性不安全,
可以改为:
[java]
view plaincopyprint?
private static final String COMMON_DATE = "dd/MM/yyyy";
SimpleDateFormat format = new SimpleDateFormat(COMMON_DATE);
format.format(new Date());
相关文章推荐
- 解决Call to method of static java.text.DateFormat
- Call to method of static java.text.DateFormat
- FindBug:Call to static DateFormat
- [置顶] 解决:Failed to convert value of type 'java.lang.String' to required type 'java.util.Date';
- FindBugs分析记录][H STCAL]Call to static DateFormat
- Call to static DateFormat
- FindBug:Call to static DateFormat
- Call to static DateFormat
- 关于Call to static DateFormat 的Findbug警告思考
- FindBugs分析记录[H STCAL]Call to static DateFormat
- 解决:Failed to convert value of type 'java.lang.String' to required type 'java.util.Date';
- 【Findbugs缺陷库】Call to static DateFormat
- Call to static DateFormat
- cocos JniHelper调用java时总是报 Failed to find static method id of
- Error when passing date to create solr date format.java.text.ParseException: Unparseable date: "We 4000 d
- findbugs异常(4):Call to static DateFormat
- How to call getClass() from a static method in Java?
- java.lang.NoClassDefFoundError: Failed resolution of: Landroid/icu/text/SimpleDateFormat;
- HBASE遇到的java.lang.OutOfMemoryError: unable to create new native thread解决方法
- Invocation of init method failed; nested exception is java.lang.NoSuchMethodError:问题解决