ImageVerifierCode 换一换
格式:DOCX , 页数:16 ,大小:140.12KB ,
资源ID:9612450      下载积分:3 金币
快捷下载
登录下载
邮箱/手机:
温馨提示:
快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。 如填写123,账号就是123,密码也是123。
特别说明:
请自助下载,系统不会自动发送文件的哦; 如果您已付费,想二次下载,请登录后访问:我的下载记录
支付方式: 支付宝    微信支付   
验证码:   换一换

加入VIP,免费下载
 

温馨提示:由于个人手机设置不同,如果发现不能下载,请复制以下地址【https://www.bdocx.com/down/9612450.html】到电脑端继续下载(重复下载不扣费)。

已注册用户请登录:
账号:
密码:
验证码:   换一换
  忘记密码?
三方登录: 微信登录   QQ登录  

下载须知

1: 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。
2: 试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。
3: 文件的所有权益归上传用户所有。
4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
5. 本站仅提供交流平台,并不能对任何下载内容负责。
6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

版权提示 | 免责声明

本文(课题修改PMD总结.docx)为本站会员(b****8)主动上传,冰豆网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知冰豆网(发送邮件至service@bdocx.com或直接QQ联系客服),我们立即给予删除!

课题修改PMD总结.docx

1、课题修改PMD总结修改PMD总结1.Avoid unnecessary Comparisons in Boolean exception.(Boolean类型重复判断)错误 例子: if(null! = a & a.size0) 正确 if(null! = a & false = a.IsEmpay()2. Avoid Using implementation types like (ArrayList HashMap/ LinkedHashMap) ,use the interface instand.(用数组的接口类型) 错误 例子:ArrayList arraylist=new Arra

2、yList(); 正确 List list=new ArrayList();错误 例子: private static HashMap map=new HashMap(); 正确 private static Map map=new HashMap(); 错误 例子: private static LinkedHashMap map=new LinkedHashMap(); 正确 private static Map map=new LinkedHashMap(); 3. Method names should not start with capital letters(方法名不能以大写开头

3、)。错误 例子: public class Start()正确 public class start() 可以用快捷键 Alt+shift+R全部替4.varivable that are final and static should be in all caps.(定义的参数必须大写)错误 例子:public static final String root正确 public static final String ROOT5.Avoid appending charcutars as Strings in StringBuffer append (避免在StringBuffer里附加单个

4、字符时附加成String类型)错误 例子: buf.append(“)”)或者buf.append(“a”)正确 buf.append()或者 buf.append(a)6.use ArrayList instanded of vector(使用ArrayList替换vector后还是会报错,所以直接改成是以它的接口形式替换)错误 例子: vector keys = new vector(ELE);正确 List keys = new ArrayList(ELE); 7. Variables that are not final should not contain underscores (

5、except for underscores in standard prefix/suffix) (变量不是final类型的不能包含下划线)错误 例子: private int DEAULT_PORT = 8001;正确 private int DEAULTPORT = 8001;(调用它的所有类都需要改动)8. Variables should start with a lowercase character(参数必须要以小写开始)错误 例子: private static int HANDLE_MAX = 200;正确 private static int handleMax = 200

6、; 9. Using equalsIgnoreCase() is cleaner than using toUpperCase/toLowerCase().equals().错误 例子: 正确10. Unnecessary wrapper object creation 错误 例子: intCurPage = Integer.valueOf(curPage).intValue();正确 intCurPage = Integer.parseInt(curPage);11. This is an inefficient use of StringBuffer.toString; call Stri

7、ngBuffer.length instead. 错误 If(newPartLen+smsMOCommondArr.toString().getBytes(DB_CHARSET).length DB_VERCHAR_MAX_LEN + 1) 正确 if(newPartLen+(smsMOCommondArr.toString().getBytes(DB_CHARSET).length DB_VERCHAR_MAX_LEN + 1) 12. This final field could be made static错误 例子: private final String urlPrefix = h

8、ttp:/;正确 private static final String URL_PREFIX = http:/;13. The field name indicates a constant but its modifiers do not错误 例子: private static String CONF_NAME = version;正确 private static final String CONF_NAME = version;14. System.out.print is used错误 例子: System.out.println(PartalOneAppender-message

9、=+message+);正确 /System.out.println(PartalOneAppender-message=+message+);15. Switch statements should have a default label错误 例子: switch (Type) case USER: displayType = USER; break; case ADMIN: displayType = ADMIN; break; 正确 switch (Type) case USER: displayType = USER; break; case ADMIN: displayType =

10、 ADMIN; break; default: 16. Substitute calls to size() = 0 (or size() != 0) with calls to isEmpty()错误 例子: if(null=Handlers | 0 =Handlers.size()正确 if (null=Handlers | Handlers.isEmpty()17. Return an empty array rather than null.错误 例子: if (null != g & g.length 0) String cloneGroups = new Stringg.lengt

11、h; System.arraycopy(g, 0, cloneGroups, 0, g.length); return cloneGroups; return null;正确 if (null != g & g.length 0) String cloneGroups = new Stringg.length; System.arraycopy(g, 0, cloneGroups, 0, g.length); return cloneGroups; return new String0;18. Deeply nested if.then statements are hard to read原

12、因: 深嵌套的if循环很难读懂。报错例子 if (null != portalScriptionInfo & null != portalScriptionInfo.getChargeInfo()if(productId.equals(portalScriptionInfo.getChargeInfo().getSourceChargeId()/ 构造orderInfo 对象portalOrderInfo.setProductId(productId);productName = chargeInfo.getProductName();break; 修改后的例子 if (null != por

13、talScriptionInfo& null !=portalScriptionInfo.getChargeInfo()& (productId.equals(portalScriptionInfo.getChargeInfo() .getSourceChargeId() portalOrderInfo.setProductId(productId); productName = chargeInfo.getProductName(); break;19. Caught exception is rethrown, original stack trace may be lost原因: 捕捉一

14、个异常后,再从新把异常扔出去,会把以前的异常信息丢掉。修改: 可以把在此扔出的异常信息以Log日志的形式打印出来。 例如: (错误) catch (IOException ioe) String msg = Cant open config file: + xmlFile + due to: + ioe; throw new IOException(msg); 改正后:catch (IOException ioe) String msg = Cant open config file: + xmlFile + due to: + ioe;LogFactory.getInstance().log

15、Action(msg); 20.Avoid throwing raw Exception types(避免抛出一个生疏的异常类型)错误 例子: catch (IOException ioe) ioe.printStackTrace();String msg = Cant open config file: + xmlFile.getAbsolutePath()+ due to: + ioe; throw new Exception(msg);正确 catch (IOException ioe) ioe.printStackTrace();String msg = Cant open confi

16、g file: + xmlFile.getAbsolutePath()+ due to: + ioe;LogFactory.getInstance().logAction(msg); 21. Method call on object which may be null错误 例子: if (GroupList = null & GroupList.size() 1)正确 if (GroupList.isEmpty()22. It is somewhat confusing to have a field name with the same name as a method.原因:A getX

17、() method which returns a boolean should be named isX() 属性名与方法名称相似。修改:错误 private boolean stopServer; public void stopServer() this.stopServer = true; 正确 可以把方法名称该换一个名字! 23. Do not use if statements that are always true or always false原因: 不要总使用If循环条件是true或者是false。修改: (错误的)String NameKey = request.getP

18、arameter(NameKey);if (true) request.setAttribute(NameKey, nameKey); ReleaseContent releaseContent = new ReleaseContent(); releaseContent.setCatalogId(catalogId); User user= super.getUser(request); int userType = userInfo.getUserType(); (正确的)ift条件是真的就可以去掉if(true) String NameKey = request.getParameter

19、(NameKey);/if (true) request.setAttribute(NameKey, nameKey); ReleaseContent releaseContent = new ReleaseContent(); releaseContent.setCatalogId(catalogId); User user= super.getUser(request); int userType = userInfo.getUserType(); 24. System.arraycopy is more efficient报错的例子: for (int i1 = 0; i1 tmpabc

20、de.length; i1+) tmpabcdei1 = digestInti1; 修改成 for (int i1 = 0; i1 tmpabcde.length; i1+) / tmpabcdei1 = digestInti1; System.arraycopy(digestInt, i1, tmpabcde, i1, 1); * arraycopy(Objectsrc, intsrcPos, Objectdest, intdestPos, intlength) 从指定源数组中复制一个数组,复制从指定的位置开始,到目标数组的指定位置结束。参数: src - 源数组。 srcPos - 源数组

21、中的起始位置。 dest - 目标数组。 destPos - 目标数据中的起始位置。 length - 要复制的数组元素的数量。 25.use aslist instended of tight loops()原因 for (int i = 0; i type.length; i+) List.add(type i); 修改: List = Arrays.asList(type);* 提供了一个创建固定长度的列表的便捷方法,该列表被初始化为包含多个元素:List list= Arrays.asList(Larry, Moe, Curly);参数:Larry : 存放的类型 Moe: 有效性 c

22、urly:26.Avoid empty if statements() 原因:在if循环中没有大括号。做法:错误 例子: if (mlang = null) mlang = LanguageUtil.getDefaultLanguage(); return _ + mlang.getLanguage().toUpperCase() + _ + mlang.getCountry().toUpperCase();正确 if (mlang = null) mlang = LanguageUtil.getDefaultLanguage(); return _ + mlang.getLanguage()

23、.toUpperCase() + _ + mlang.getCountry().toUpperCase();27. Avoid using (if.else/ if/ for/ while) statements without curly braces原因: 避免使用(if.else/ if/ for/ while)循环时没有波形括号(基本的语法错误)修改: 应该加括号的地方加上括号。28. Avoid using exceptions as flow control.原因: 避免使用异常来控制流程修改: 报出的异常信息基本上都是在try。catch。的catch语句块中,可以把在catch

24、语句块中抛出的异常信息,用log日志来代替输出信息。29. Avoid unnecessary if.then.else statements when returning a Boolean原因: 在返回值是Boolean类型时,避免不必要的使用if.then.else修改: 错误的:if (UserConstant.TYPE_SP = getUser(request).getUserType() return true; else return false; 正确的:if (UserConstant.TYPE_SP = getUser(request).getUserType() retu

25、rn true; return false; 30. Avoid unnecessary constructors - the compiler will generate these for you.原因: 产生了一个多余的构造器,编辑器将为你产生它们。做法: 一个公有的抽象类,不需要自己在写一个构造器,因为它本身自己就可以提供构造方法。删除多余的私有构造方法。31. Avoid instantiating Boolean objects; reference Boolean.TRUE or Boolean.FALSE or call Boolean.valueOf() instead.错误

26、 例子: request.setAttribute(productNotFound, Boolean.valueOf(true);正确 request.setAttribute(productNotFound, Boolean.TRUE);*Boolean类型的值不需要值类型转换,直接可以赋以true或者是false;32. Avoid catching NullPointerException; consider removing the cause of the NPE.原因:避免捕捉产生的空指针(排除由它造成的NPE原因)做法: 删除语句块中抛出的异常信息,由Log日志来带它打印信息33

27、. Avoid calling toString() on String objects; this is unnecessary.错误 例子: String result = ;return result.toString();正确 return result;* 本来就是String类型不需要再toString()转换;34. An empty statement (semicolon) not part of a loop.原因: if (is != null) try is.close(); catch (Throwable u) ; 正确 如果该方法没有任何的代码,你就可以使用日志来

28、记录它的异常信息。35. A throw statement in a finally block makes the control flow hard to understand.原因:不要在finally语句块中抛出异常,会造成一个很难理解的控制流。做法:可以把抛出的异常信息,用log日志的形式来替换。36. Avoid really (long/short) parameter lists.原因:方法参数名太长。 做法:37. No need to import a type that lives in the same package原因:不需要导入类型相识的架包。做法:使出这个多余

29、的架包。 38. No need to call String.valueOf to append to a string.原因: 它把String类型的值再一次转化为String类型的值,是多余的。做法: 不用转化它的值类型,因为它本身就是String类型的值。 39. A method/constructor shouldnt explicitly throw java.lang.Exception原因:方法不能扔出一个不具体的异常信息。做法:根据具体的代码,抛出具体的异常信息。40. Avoid using implementation typelike( TreeMap/java.ut

30、il.HashSet/java.util.HashSet) use the interface instead错误 例子:TreeMap map=NEW TreeMap();正确 Map map=NEW TreeMap();41. Avoid unused imports such as org.apache.struts.action.ActionMessages原因: 导入了多余的架包,例如:org.apache.struts.action.ActionMessages做法:删除掉。同时也可以用快捷键先ctrl+A,再ctrl+shift+o就可以了。 42. Avoid returning from a finally block原因: 返回信息在fina

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1