Unused Method(不再使用的方法)——Dead Code(死亡代码)
系列文章目录:
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(死亡代码)的更多相关文章
- myeclipse 写java代码提示 dead code 原因
经常使用MyEclipse要么Eclipse编辑写java程序猿代码.您可能经常会遇到一个黄色警戒线:dead code:一般程序猿遇到这些问题都会置之不理,反正也不影响程序的编译运行.对,这不是bu ...
- java 异常 之 实战篇(trows 和 try catch Dead Code)
一:throws 和 trycatch 差别 (1)比如.publicFileWriter(String fileName) throws IOException{} 我在mian中创建一个FileW ...
- ASM(四) 利用Method 组件动态注入方法逻辑
这篇继续结合样例来深入了解下Method组件动态变更方法字节码的实现.通过前面一篇,知道ClassVisitor 的visitMethod()方法能够返回一个MethodVisitor的实例. 那么我 ...
- myeclipse 编写java代码提示 dead code 原因
经常使用MyEclipse或Eclipse编辑器编写java代码的程序员,可能经常遇到一个黄线警告提示:dead code:一般程序员遇到这些问题都会置之不理,反正也不影响程序的编译执行.对,这不是b ...
- 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 ...
- 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 ...
- 查找无用代码Dead Code的一些心得
博客搬到了fresky.github.io - Dawei XU,请各位看官挪步.最新的一篇是:查找无用代码Dead Code的一些心得.
- JAVA进阶之旅(二)——认识Class类,反射的概念,Constructor,Field,Method,反射Main方法,数组的反射和实践
JAVA进阶之旅(二)--认识Class类,反射的概念,Constructor,Field,Method,反射Main方法,数组的反射和实践 我们继续聊JAVA,这次比较有意思,那就是反射了 一.认识 ...
- Knowledge Point 20180308 Dead Code
不知道有没有前辈注意过,当你编写一段“废话式的代码时”会给出一个Dead Code警告,点击警告,那么你所写的废物代码会被编译器消除,那么如果你不理睬这个警告呢?编译后会是什么样的呢?下面我们写点代码 ...
随机推荐
- chromium os系统编译与环境搭建
官方网址:http://www.chromium.org/chromium-os chromium os是google自2009年开启的项目,是一款开源的电脑操作系统,用于开发chromium/chr ...
- Silverlight提示“Load 操作失败。远程服务器返回了错误: NotFound”
调试时出现“Load 操作失败.远程服务器返回了错误: NotFound”: 一定要注意此错误之前的错误是什么?基本就是用户Cookie的问题,用户没有登录. 有时需要设置成Any CPU 有时重新编 ...
- WebView动态注入JavaScript脚本
Demo地址:https://gitee.com/chenyangqi/YouMeDai 背景介绍 在Android与JavaScript交互一文中学习了原生和JS交互,但是如果我们想和别人开发好的w ...
- Charles抓取https请求
最近公司将Windows产品的http请求,替换成https请求了,当https请求超过5次失败,就自动切换回http请求.测试时使用Charles抓包测试. 一.http抓包 http抓包比较简单, ...
- TFS命令行操作
前言 本文主要介绍如何通过TFS(Team Foundation Server)命令行强制解锁(UnDo)项目成员对项目文件的占用. 正文 在多人同时开发项目的时候,如果遇到项目组成员独占签出文件后未 ...
- memcached编译安装报错 ,提示checking build system type... Invalid configuration `x86_64-unknown-linux-': machine `x86_64-unknown-linux' not recognized configure: error: /bin/sh ./config.sub x86_64-unknown-linu
- 无法获取链接服务器 "XXX" 的 OLE DB 访问接口 "SQLNCLI10" 的架构行集 "DBSCHEMA_TABLES_INFO"。该访问接口支持该接口,但使用该接口时返回了失败代码。
1. SQL 2000 下载补丁 SQL2KSP4 ,进行安装 2.找到SQL2KSP4\install\instcat.sql 并在sql2000 中打开查询分析器中执行
- chromedriver与chrome各版本及下载地址
Selenium从2升级到3之后呢,Selenium 3 相较于2最大的变化就是更加的标准化,可以支持更多的浏览器.那我们做自动化的时候如果用的是selenium3的话,首先要坐的就是下载不同浏览器的 ...
- November 10th, 2017 Week 45th Friday
A little bit of mercy makes the world less cold and more just. 多一点怜悯就可以让这个世界少一点冷酷而多一点正义. Maybe there ...
- 阿里八八Alpha阶段Scrum(11/12)
今日进度 叶文滔: 合并日程界面debug成功,但是目前出现了新的问题,日程界面一些控件无法适配屏幕,正在排查问题 李嘉群: 尝试用okhttp的方式发送请求 王国超: 今天开始进行recycerli ...