1)NP_ALWAYS_NULL: Null pointer dereference

A null pointer is dereferenced here. This will lead to a NullPointerException when the code is executed.

解释:有一条语句的分支,如果执行该分支,则将引用空值,这将在执行代码时生成NullPointerException。当然,可能出该分支或语句不可行,并且永远不会造成空指针异常。认为这超出了FindBugs的能力。

错误代码:

 public static String testl(String str) {if(str!=null){return "";}// doSomething}
2)RCN_REDUNDANT_NULLCHECK_WOULD_HAVE_BEEN_A_NPE: Nullcheck of value previously dereferenced

A value is checked here to see whether it is null, but this value can’t be null because it was previously dereferenced and if it were null a null pointer exception would have occurred at the earlier dereference. Essentially, this code and the previous dereference disagree as to whether this value is allowed to be null. Either the check is redundant or the previous dereference is erroneous.

解释:这里会检查一个值是否为空,但是这个值不能为空,因为它之前已经被引用,如果它是空的,那么空指针异常会在之前的取消引用时发生。本质上,对于是否允许该值为null,此代码和前面的取消引用不一致。要么检查是多余的,要么前面的引用是错误的。

错误代码:

myView.setVisibility(View.VISIBLE);if (null == banner) {// doSomething}
3)DM_DEFAULT_ENCODING: Reliance on default encoding

Found a call to a method which will perform a byte to String (or String to byte) conversion, and will assume that the default platform encoding is suitable. This will cause the application behaviour to vary between platforms. Use an alternative API and specify a charset name or Charset object explicitly.

解释:找到一个方法的调用,该方法将执行一个字节到字符串(或字符串到字节)的转换,并假设默认的平台编码是合适的。这将导致不同平台之间的应用程序行为不同。使用替代API并显式指定charset名称或charset对象。
错误代码:

// example 1
MessageDigest mdTemp = MessageDigest.getInstance("MD5");
mdTemp.update(string.getBytes());
// example 2
private OutputStream outStream = null;
outStream.write(str.getBytes());
// example 3
String string = new String(bytes);

修改:

// example 1
MessageDigest mdTemp = MessageDigest.getInstance("MD5");
mdTemp.update(string.getBytes(Charset.forName("UTF-8")));
// example 2
private OutputStream outStream = null;
outStream.write(str.getBytes(StandardCharsets.UTF_8));
// example 3
String string = new String(bytes, StandardCharsets.UTF_8);

注:Charset.forName(“UTF-8”) 与 StandardCharsets.UTF_8都可以,第二个要求minAPI 19

4)MS_SHOULD_BE_FINAL: Field isn’t final but should be

This static field public but not final, and could be changed by malicious code or by accident from another package. The field could be made final to avoid this vulnerability.

解释:这个静态字段是公共的,但不是final的,可能被恶意代码或意外地从另一个包中更改。

5)DM_BOXED_PRIMITIVE_FOR_PARSING: Boxing/unboxing to parse a primitive

A boxed primitive is created from a String, just to extract the unboxed primitive value. It is more efficient to just call the static parseXXX method.

学习:Integer.parseInt(s)与Integer.valueOf(s)的区别详解

6)ST_WRITE_TO_STATIC_FROM_INSTANCE_METHOD: Write to static field from instance method

This instance method writes to a static field. This is tricky to get correct if multiple instances are being manipulated, and generally bad practice.

解释:此实例方法写入静态字段。如果操作了多个实例,则很难纠正这种错误,而且通常是不好的实践。
即一个静态变量在普通方法中被赋值,可能多次更改达到不想得到的结果。

7)UC_USELESS_VOID_METHOD: Useless non-empty void method

Our analysis shows that this non-empty void method does not actually perform any useful work. Please check it: probably there’s a mistake in its code or its body can be fully removed.
We are trying to reduce the false positives as much as possible, but in some cases this warning might be wrong. Common false-positive cases include:
/ - The method is intended to trigger loading of some class which may have a side effect.
/ - The method is intended to implicitly throw some obscure exception.

解释:我们的分析表明,这个非空void方法实际上没有执行任何有用的工作。请检查:可能是它的代码有错误,或者它的主体可以被完全删除。

我们试图尽可能地减少误报,但在某些情况下,这个警告可能是错误的。常见的假阳性病例包括:

-该方法旨在触发加载某些类,可能有副作用。

-该方法的目的是隐式抛出一些模糊的异常。

findbugs问题解决相关推荐

  1. findbugs 接口文档_Java代码审查工具findbugs的使用总结

    findbugs简介 Findbugs是一个Java代码静态分析工具,可以用它来检查源代码中可能出现的问题,以期尽可能在项目的初始阶段将代码问题解决. FindBugs检查的是类或者JAR文件即字节代 ...

  2. Java代码审查工具findbugs的使用总结

    findbugs简介 Findbugs是一个Java代码静态分析工具,可以用它来检查源代码中可能出现的问题,以期尽可能在项目的初始阶段将代码问题解决. FindBugs检查的是类或者JAR文件即字节代 ...

  3. undefined reference to 'pthread_create'问题解决(转)

    undefined reference to 'pthread_create' undefined reference to 'pthread_join' 问题原因:     pthread 库不是 ...

  4. mysql 4.0.27 下载,CentOS编译Mysql 4.0.27数据库问题解决

    CentOS编译Mysql 4.0.27数据库问题解决以下文字资料是由(历史新知网www.lishixinzhi.com)小编为大家搜集整理后发布的内容,让我们赶快一起来看一下吧! 现在好多人都用起了 ...

  5. oracle实例没有连到监听上6,oracle LISTENER未监听到oracle实例问题解决

    oracle LISTENER未监听到oracle实例问题解决 LISTENER = (DESCRIPTION_LIST = (DESCRIPTION = (ADDRESS = (PROTOCOL = ...

  6. linux+bin+写入引导区,CentOS 6.4 U盘启动盘制作、安装及遇到的问题解决

    用UltraISO Premium Edition  9.3 制作的CentOS 6.4 U盘安装盘, 安装时提示Press the key to begin the installation pro ...

  7. Oracle不能在本地计算机启动,Windows 不能在本地计算机启动 OracleDBConsoleorcl的问题解决方法...

    解决步骤如下: 1.开始->运行cmd 2.执行 emctl start dbconsole 输入:C:\Documents and Settings\xcl>emctl start db ...

  8. 【python】 OSError:sift not found 问题解决

    [python] OSError: XXXX.sift not found 问题解决 在python环境下通过sift描述子对图像进行特征匹配时出现错误(心累):mpire.sift not foun ...

  9. VS 打开No EditorOptionDefinition export found for the given option name问题解决

    打开vs项目文件时,无法加载解决方案,报错如下: 解决方法: 1.关闭VS 2.找到ComponentModelCache所在文件夹%LocalAppData%\Microsoft\VisualStu ...

最新文章

  1. keras.layers 各种层介绍
  2. 【Linux基础】查看硬件信息-内存和硬盘
  3. scanf格式控制符
  4. 口语学习Day7:今天聊聊美国超市的物价
  5. 成功解决ERROR: Unable to find the development tool `cc` in your path; please make sure that you have the
  6. 1362. 健康的荷斯坦奶牛【难度: 一般 / 二进制枚举】
  7. 计算机u打字,win7电脑打字打不出来怎么办
  8. 2021衢二中高考成绩查询入口,2021衢州市地区高考成绩排名查询,衢州市高考各高中成绩喜报榜单...
  9. FCKeditor + smarty
  10. JavaScript原生对象属性和方法详解——Array对象
  11. 7. 堆(宋红康笔记)
  12. java 文件比对(三)-- 使用 xmlUnit
  13. 【星座】十二星座会因为什么变穷
  14. 我从《阿里云:人工智能应用实践与趋势》白皮书学到了什么?
  15. 从网卡中截获sql server的sql语句
  16. 【优化】拉格朗日(Lagrange)乘子法超简说明
  17. 何新生的英语史(三)—有干劲、入门阶段
  18. c语言编程电机星三角启动,三相异步电动机星三角减压启动控制plc编程实例
  19. git 远程仓库操作
  20. CocoaPods添加和删除某个库

热门文章

  1. Linux小小白入门教程(五):显示和进入文件夹
  2. 2021我上岸了!分享我的招银网络科技 一二三面面经,希望对大家有帮助!
  3. 海马T1团餐机副屏显示系统设置中,请前往前屏操作
  4. Android实例——拼图游戏
  5. 就这一次,用20张图带你彻底击溃Redis跳表,java反射机制原理
  6. 微信bug二维码崩溃漏洞?poc来了! 生成你们自己的二维码
  7. @Component注解的含义
  8. Ubuntu中文输入法安装
  9. Ubuntu中文输入法
  10. 【Linux】找不到ensss IP地址 或者连接不上ssh解决方法