系列文章目录:

    使用Fortify进行代码静态分析(系列文章)

Unused Method(不再使用的方法)

   示例: 

 private bool checkLevel(string abilitySeqno, string result)
{
return hrDutyexamProjectAbilityDS.CheckImportLevel(abilitySeqno, result);
}

  Fortify解释:

The method checkLevel() in AbilityImport..cs is not reachable from any method outside the class. It is dead code. Dead code is defined as code that is never directly or indirectly executed by a public method,or is only called from other dead code.

AbilityImport.cs类的checkLevel() 方法从类外的任何方法都不可达,它是死亡的代码。死亡代码是从未被公共方法直接或间接的调用,或者被其他的死亡代码调用。    

  Fortify示例1:    

 public class Dead {
private void DoWork() {//永远不会被调用
Console.Write("doing work");
}
public static void Main(string[] args) {
Console.Write("running Dead");
}
}

   Fortify示例2:

 public class DoubleDead {
private void DoTweedledee() {
DoTweedledumb();
}
private void DoTweedledumb() {
DoTweedledee();
}
public static void Main(string[] args) {
Console.Write("running DoubleDead");
}

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.

在这个类中,两个私有方法相互调用,但是它们其中任意一个都没有被其他的类调用,它们是死亡代码.

A dead method may indicate a bug in dispatch code.

死亡方法可能意味着在分支代码中存在BUG。

Fortify示例:

 public ScaryThing GetScaryThing(char st) {
switch(st) {
case 'm':
return GetMummy();
case 'w':
return GetMummy();
default:
return GetBlob();
}
}

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().

如果类中的死亡方法 GetWitch() 也存在上面的分支代码逻辑,有可能这是复制粘贴代码时造成的错误,当case匹配w时,应该调用GetWitch() 而不是GetMummy()方法。

In general, you should repair or remove dead code. To repair dead code, execute the dead code directly or indirectly through a public method. Dead code causes additional complexity and maintenance burden without contributing to the functionality of the program.

通常,你应该修复或者移除死亡代码,你可以通过在公共方法直接或间接执行这个方法来修复它。死亡代码增加了复杂性和维护的工作量,同时对系统的功能无所裨益。

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.)

值得注意的是,这个问题(死亡代码)有可能是个伪命题,因为有可能这个方法是通过反射来调用的。(这是不规范的实践,只通过反射调用的私有方法应该有很好的记录来说明。)

Unused Method(不再使用的方法)——Dead Code(死亡代码)的更多相关文章

  1. myeclipse 写java代码提示 dead code 原因

    经常使用MyEclipse要么Eclipse编辑写java程序猿代码.您可能经常会遇到一个黄色警戒线:dead code:一般程序猿遇到这些问题都会置之不理,反正也不影响程序的编译运行.对,这不是bu ...

  2. java 异常 之 实战篇(trows 和 try catch Dead Code)

    一:throws 和 trycatch 差别 (1)比如.publicFileWriter(String fileName) throws IOException{} 我在mian中创建一个FileW ...

  3. ASM(四) 利用Method 组件动态注入方法逻辑

    这篇继续结合样例来深入了解下Method组件动态变更方法字节码的实现.通过前面一篇,知道ClassVisitor 的visitMethod()方法能够返回一个MethodVisitor的实例. 那么我 ...

  4. myeclipse 编写java代码提示 dead code 原因

    经常使用MyEclipse或Eclipse编辑器编写java代码的程序员,可能经常遇到一个黄线警告提示:dead code:一般程序员遇到这些问题都会置之不理,反正也不影响程序的编译执行.对,这不是b ...

  5. 35.按要求编写Java程序: (1)编写一个接口:InterfaceA,只含有一个方法int method(int n); (2)编写一个类:ClassA来实现接口InterfaceA,实现int method(int n)接口方 法时,要求计算1到n的和; (3)编写另一个类:ClassB来实现接口InterfaceA,实现int method(int n)接口 方法时,要求计算n的阶乘(n

      35.按要求编写Java程序: (1)编写一个接口:InterfaceA,只含有一个方法int method(int n): (2)编写一个类:ClassA来实现接口InterfaceA,实现in ...

  6. SSIS Error The Execute method on the task returned error code 0x80131621

    Error Message: The Execute method on the task returned error code 0x80131621 (Mixed mode assembly is ...

  7. 查找无用代码Dead Code的一些心得

    博客搬到了fresky.github.io - Dawei XU,请各位看官挪步.最新的一篇是:查找无用代码Dead Code的一些心得.

  8. JAVA进阶之旅(二)——认识Class类,反射的概念,Constructor,Field,Method,反射Main方法,数组的反射和实践

    JAVA进阶之旅(二)--认识Class类,反射的概念,Constructor,Field,Method,反射Main方法,数组的反射和实践 我们继续聊JAVA,这次比较有意思,那就是反射了 一.认识 ...

  9. Knowledge Point 20180308 Dead Code

    不知道有没有前辈注意过,当你编写一段“废话式的代码时”会给出一个Dead Code警告,点击警告,那么你所写的废物代码会被编译器消除,那么如果你不理睬这个警告呢?编译后会是什么样的呢?下面我们写点代码 ...

随机推荐

  1. Expo大作战(二十)--expo中的Release channels(不重要*)

    简要:本系列文章讲会对expo进行全面的介绍,本人从2017年6月份接触expo以来,对expo的研究断断续续,一路走来将近10个月,废话不多说,接下来你看到内容,讲全部来与官网 我猜去全部机翻+个人 ...

  2. [我的阿里云服务器] —— WordPress Permalink Settings

    前言: 固定链接(Permalink)是博客日志.分类及其他博客内容列表的永久URL. 别人可以通过固定链接链接到你的文章上,你也可以在email中发送某篇日志的链接. 所有日志的URL应为永久性.固 ...

  3. LeetCode题解之Merge k Sorted Lists 解法二

    1.题目描述 2.分析 利用 vector 存储指针,同时合并k个链表. 3.代码 ListNode* mergeKLists(vector<ListNode*>& lists) ...

  4. textbox只允许输入数字

    private void txtUserId_KeyPress(object sender, KeyPressEventArgs e) { //如果输入的不是数字键,也不是回车键.Backspace键 ...

  5. 为什么Sql Server的查询有时候第一次执行很慢,第二次,第三次执行就变快了

    老外提问: Hi, I have an sql query which takes 8 seconds in the first run. The next run there after takes ...

  6. 虚拟机克隆linux centos 6.5 系统网卡配置

    作为一个刚刚接触linux系统的小白来说,VMware虚拟机安装好CentOS6.5系统后,纯净的系统多克隆几份出来方便后期做试验.克隆步骤很简单,克隆后出现的问题是克隆后的网卡MAC地址和原系统MA ...

  7. MySQL案列之主从复制出错问题以及pt-slave-restart工具的使用

    今天主从复制遇到一个问题,主库上插入了几百行万数据,后来又删除了这些数据,原因就是主库删除的表从库中不存在,导致从库在遇到删除不存在表的错误无法继续同步. MySQL [(none)]> sho ...

  8. 【项目 · Wonderland】预则立 && 他山之石

    [软 工 实 践 · 团 队 作 业] 预则立&&他山之石 标签:WonderLand Part 0 · 简要目录 Part 1 · 团队计划 Part 2 · 团队访谈 Part 3 ...

  9. MYSQL一次千万级连表查询优化(二) 作为一的讲解思路

    这里摘自网上,仅供自己学习之用,再次鸣谢 概述: 交代一下背景,这算是一次项目经验吧,属于公司一个已上线平台的功能,这算是离职人员挖下的坑,随着数据越来越多,原本的SQL查询变得越来越慢,用户体验特别 ...

  10. 列表操作方法,元祖,for循环嵌套

    li = ['alex','wusir''女神']增 1.增加到列表末位 li.append() 连续增加,输入q停止 li = ['alex','wusir''女神'] while 1: s = i ...