Fortify分析翻译3

  7. Poor style:Confusing naming(Structural):
7.1.BPCodeConstants.java
    private static  final String RATING_BP_CODE = "WF001";
    public static String RATING_BP_CODE() {}
7.2.The class contains a field and a method with the same name.
该类包含相同名字的属性和方法。
7.3.EXPLANATION 解释
It is confusing to have a member field and a method with the same name.
It makes it easy for a programmer to accidentally call the method
when attempting to access the field or vice versa.
它是让人迷惑的,一个成员属性和一个方法有相同的名字。
当准备检查属性或者缺陷的时候,它可以使程序员调用方法更加容易。
Example 1:
public class Totaller {
  private int total;
  public int total() {
    ...
  }
}
7.4.RECOMMENDATIONS 建议
Rename either the method or the field. If the method returns the field,
consider following the standard getter/setter naming convention.
Example 2: The code in Example 1 could be rewritten in the following way:
不管是重命名方法还是属性,如果方法返回这个属性,
考虑采用标准的getter/setter命名惯例。
例子2:在例子1中的代码在下面将被覆盖:
public class Totaller {
  private int total;
  public int getTotal() {
    ...
  }
}
8. Dead code:unused field(Structural):   
8.1.BaseWFBO.java  
    BaseWFBO.java   private Map historyInfo;   
8.2.This field is never used.   
    属性没有使用。   
8.3.EXPLANATION 解释
This field is never accessed, except perhaps by dead code.
It is likely that the field is simply vestigial,
but it is also possible that the unused field points out a bug.
这个属性没有入口,应该是一段死代码。
也有可能,这个属性是一个简单的属性,
但是也有可能,这个没有用到的属性是一个缺陷。
Example 1: The field named glue is not used in the following class.
The author of the class has accidentally put quotes around the field name,
transforming it into a string constant.
例子1:这个叫glue的属性在下面的类中没有用到。
类的作者,不小心使用一个引用来定义属性的名称,
应该将它转换成一个字符串常量。
public class Dead {
  String glue;
  public String getGlue() {
    return "glue";
  }
}
Example 2: The field named glue is used in the following class,
but only from a method that is never called.
例子2:在下面的类中,属性glue被使用了,
但是仅仅用来一个从不被调用的类中。
public class Dead {
  String glue;
  private String getGlue() {
    return glue;
  }
}
8.4.RECOMMENDATIONS 建议
In general, you should repair or remove dead code.
It causes additional complexity and maintenance burden
without contributing to the functionality of the program.
通常,你应该修改或者去掉死代码。
它会使程序增加额外的复杂度,
而且在对程序的功能没有任何贡献的情况下增加负担。
9. Dead code:unused method(Structural):   
9.1.BaseBackingBean.java  
    private static ValueBinding getValueBinding(String el)
9.2.This method is not reachable from any method outside the class.   
    这个方法不能被类外面的方法调用。
9.3.EXPLANATION 解释
This method is never called or is only called from other dead code.
这个方法是不能被调用的,或者只能从其它的死代码中调用。
Example 1: In the following class, the method doWork() can never be called.
例子1:在下面的类中,方法doWork()不能被调用。
public class Dead {
  private void doWork() {
    System.out.println("doing work");
  }
  public static void main(String[] args) {
    System.out.println("running Dead");
  }
}
Example 2: In the following class, two private methods call each other,
but since neither one is ever invoked from anywhere else, they are both dead code.
例子2:在下面的类中,两个私有方法相互调用,
但是没有一个可以从其它的地方来调用,它们都是死代码。
public class DoubleDead {
  private void doTweedledee() {
    doTweedledumb();
  }
  private void doTweedledumb() {
    doTweedledee();
  }
  public static void main(String[] args) {
    System.out.println("running DoubleDead");
  }
}
(In this case it is a good thing that the methods are dead:
invoking either one would cause an infinite loop.)
(在这个例子中,方法是死的:调用任何一个都将导致死循环。)
9.4.RECOMMENDATIONS 建议
A dead method may indicate a bug in dispatch code.
一个死方法暴露一个分支代码中的缺陷。
Example 3: If method is flagged as dead named getWitch() in a class
that also contains the following dispatch method,
it may be because of a copy-and-paste error.
The 'w' case should return getWitch() not getMummy().
例子3:如果一个标记为死代码的方法getWitch(),并且getWitch()
包含下面的调度方法。它可能是因为一个复制粘贴错误。
这个'w'的情况会返回getWitch()而不是getMummy().
public ScaryThing getScaryThing(char st) {
  switch(st) {
    case 'm':
      return getMummy();
    case 'w':
      return getMummy();
    default:
      return getBlob();
  }
}
In general, you should repair or remove dead code.
It causes additional complexity and maintenance burden
without contributing to the functionality of the program.
通常,你应该修改或者去掉死代码。
它会使程序增加额外的复杂度,
而且在对程序的功能没有任何贡献的情况下增加负担。
9.5.TIPS 提示
   This issue may be a false positive if the program uses reflection to access private methods.
(This is a non-standard practice.
Private methods that are only invoked via reflection should be well documented.)
这个问题应该不是值得肯定的,如果程序使用反射来访问私有方法。
(这是一个非标准的习惯。使用反射调用的私有方法可以被很好的记录下来。)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值