CheckStyle
修改订单功能
- Sun:
-
MallAdminApplication
-
OmsOrderSettingController:
-
OmsOrderSettingService
-
OmsOrderSettingServiceImpl
-
OmsOrderSetting
-
MallAdminApplication
-
OmsOrderSettingController:
-
OmsOrderSettingService
-
OmsOrderSettingServiceImpl
-
OmsOrderSetting
FindBugs
-
correctness
DMI_INVOKING_TOSTRING_ON_ARRAY翻译
Invocation of toString on … in …
The code invokes toString on an array, which will generate a fairly useless result such as [C@16f0472. Consider using Arrays.toString to convert the array into a readable String that gives the contents of the array. See Programming Puzzlers, chapter 3, puzzle 12.
在一个array数组上调用toString将返回如C@16f0472等无意义的结果,可以使用Arrays.toString方法来将数组转换为可读的字符串。原因
大多数这个问题出在直接打印某个数组是否为空,这种直接打印的方法会默认调用对象的toString方法,输出对象的内存地址,也不排除其他情况。因为这里pic的定义是:
private byte[] pic;
-
Bad practice
-
一
Nm: Class names should start with an upper case letter (NM_CLASS_NAMING_CONVENTION)
Class names should be nouns, in mixed case with the first letter of each internal word capitalized. Try to keep your class names simple and descriptive. Use whole words-avoid acronyms and abbreviations (unless the abbreviation is much more widely used than the long form, such as URL or HTML).
翻译:
Nm:类名应以大写字母开头(NM_CLASS_NAMING_CONVENTION)
类名应为名词,大小写混合,每个内部单词的首字母应大写。尝试使您的类名称保持简单和描述性。请使用整个单词,避免使用首字母缩写词和缩写词(除非缩写词比长格式(如URL或HTML)使用得更广泛)。原因:
这里的是fileController,开头没大写 -
二
Nm: Method names should start with a lower case letter (NM_METHOD_NAMING_CONVENTION)
Methods should be verbs, in mixed case with the first letter lowercase, with the first letter of each internal word capitalized.Nm:方法名称应以小写字母开头(NM_METHOD_NAMING_CONVENTION)
方法应为动词,首字母小写混合,每个内部单词的首字母大写。原因:
这里的是BindingResult,方法开头大写了
-
Dodgy code
ICAST: Result of integer multiplication cast to long (ICAST_INTEGER_MULTIPLY_CAST_TO_LONG)
翻译:
ICAST:整数乘法的结果强制转换为long(ICAST_INTEGER_MULTIPLY_CAST_TO_LONG)原因:
// 文件大小 long maxSize = ALIYUN_OSS_MAX_SIZE * 1024 * 1024;
-
Malicious code vulnerability
-
一
a
EI: May expose internal representation by returning reference to mutable object (EI_EXPOSE_REP)
Returning a reference to a mutable object value stored in one of the object’s fields exposes the internal representation of the object. If instances are accessed by untrusted code, and unchecked changes to the mutable object would compromise security or other important properties, you will need to do something different. Returning a new copy of the object is better approach in many situations.翻译:
EI:可以通过返回对可变对象(EI_EXPOSE_REP)的引用来公开内部表示形式
返回对存储在对象字段之一中的可变对象值的引用将暴露该对象的内部表示。如果实例是由不受信任的代码访问的,并且对可变对象的未经检查的更改会损害安全性或其他重要属性,则您需要做一些不同的事情。在许多情况下,返回对象的新副本是更好的方法。b
同上的错误
-
二
a
public void setCreateTime(Date createTime) { this.createTime = createTime; }
和上面一样的提示
b
public void setCreateTime(Date createTime) { this.createTime = createTime; }
和上面一样的提示
PMD
总概览:
-
bestpractices:
这个抽象类没有抽象方法 -
codestyle:
每个类必须有一个构造函数 -
design
这里推荐用Final修饰UmsAdmin,因为只被初始化一次 -
documentation
需要对 message 字段注释 -
errorprone
避免使用LiteralsInlfCondition。通过将条件语句声明为静态变量来避免在条件语句中使用硬编码文本,或者使用描述性名称的私有成员可维护性得到增强 -
multithreading
由于Java5带来了为多线程访问而设计的Map的新实现,您可以在不阻塞其他线程的情况下执行高效的Map读取
如果您在Java5或更新版本中运行并且具有并发访问权限,那么应该使用ConcurrentHashMap实现 -
performance
Consecutive calls to StringBuffer/StringBuilder .append should be chained, reusing the target object. This can improve the performance by producing a smaller bytecode, reducing overhead and improving inlining. A complete analysis can be found.应当连续调用StringBuffer / StringBuilder .append,以重新使用目标对象。通过产生较小的字节码,减少开销和改进内联,可以提高性能。
推荐多个append连用
修改订单的三工具分析结果对比
工具 | Warning数 | 较多Warning的详情描述 |
---|---|---|
CheckStyle(sun) | 4+20+8+7+31=70 | 本行字符数要求不超过80个 |
FindBugs | 0 | 无 |
PMD | 3+14+2+9+46=74 | ShortVariable. Fields, local variables, or parameter names that are very short are not helpful to the reader(简称变量太短) |
-
FindBugs:
我们以包的分组查看错误,结果如下:
打开controller,可以看到不是有关修改订单操作OmsOrderSettingController的错误
再看service.impl:
也不是OmsOrderSettingServiceImpl的错误最后看entity,但是entity的文件太多,我们再以class的分组查看,发现没有一个是OmsOrderSetting:
综上findbugs找到的关于修改订单的warning数是0 -
PMD:
分别对修改订单的几个部分使用MallAdminApplication:
OmsOrderSettingController:
OmsOrderSettingService:
OmsOrderSettingServiceImpl:
OmsOrderSetting: