自定义、定制findbugs扫描类型,忽略指定类型

编程知识 更新时间:2023-05-02 19:06:08

一、背景介绍
       
在使用findbugs对项目代码进行扫描时,默认findbugs扫描级别较高,部分可以接受bug也会被扫出来,影响项目整体扫描报告,为严重问题的排查及修改增加了难度。

二、配置findbugs忽略文件,排除文件

    排除文件findbugs-exclude-bugs.xml,文件内容如下所示:

<?xml version="1.0" encoding="UTF-8"?>
<FindBugsFilter>
	<Match>
		<!-- 实体赋值静态变量,一般初始化时候的操作,忽略不处理-->
		<!-- Write to static field from instance method-->
		<Package name="~.*" />
		<Bug pattern="ST_WRITE_TO_STATIC_FROM_INSTANCE_METHOD" />
	</Match>

	<Match>
		<!-- 自动装箱的问题,忽略不处理-->
		<!-- Boxing/unboxing to parse a primitive excute(Object)-->
		<Package name="~.*" />
		<Bug pattern="DM_BOXED_PRIMITIVE_FOR_PARSING" />
	</Match>
	<Match>
		<!--自动装箱的问题,忽略不处理 -->
		<!-- Primitive value is boxed then unboxed to perform primitive coercion-->
		<Package name="~.*" />
		<Bug pattern="BX_BOXING_IMMEDIATELY_UNBOXED_TO_PERFORM_COERCION" />
	</Match>
	
	<Match>
		<!--装箱后拆箱紧接着装箱,忽略不处理 -->
		<!-- Boxed value is unboxed and then immediately reboxed-->
		<Package name="~.*" />
		<Bug pattern="BX_UNBOXING_IMMEDIATELY_REBOXED" />
	</Match>
	
	<Match>
		<!--过泛地捕获异常,将多个异常合并成一个父类异常捕获 ,忽略不处理-->
		<!-- Exception is caught when Exception is not thrown-->
		<Package name="~.*" />
		<Bug pattern="REC_CATCH_EXCEPTION" />
	</Match>
	<Match>
		<!--此代码包含文件对象为一个绝对路径名(路径硬编码),忽略不处理-->
		<!-- Code contains a hard coded reference to an absolute pathname-->
		<Package name="~.*" />
		<Bug pattern="DMI_HARDCODED_ABSOLUTE_FILENAME" />
	</Match>
	
	<Match>
		<!--未明确指定编码格式,使用系统默认编码格式,忽略不处理-->
		<!-- Reliance on default encoding -->
		<Package name="~.*" />
		<Bug pattern="DM_DEFAULT_ENCODING" />
	</Match>

	<Match>
		<!--get方法获取的对象,存在可能被修改的问题,忽略不处理-->
		<!--May expose internal representation by returning reference to mutable object -->
		<Package name="~.*" />
		<Bug pattern="EI_EXPOSE_REP" />
	</Match>
	
	<Match>
		<!-- set方法设置的对象存在会被修改的问题,忽略不处理-->
		<!-- May expose internal representation by incorporating reference to mutable object-->
		<Package name="~.*" />
		<Bug pattern="EI_EXPOSE_REP2" />
	</Match>
	
</FindBugsFilter>

三、idea配置findbugs忽略文件,排除文件
 首先需要在idea中添加FindBugs插件,接下来配置findBugs忽略文件:
idea -> File -> Other Settings -> Default Settings -> Other Settings -> FindBugs-IDEA -> Filter -> Exclude filter files

注:具体findbugs-exclude-bugs.xml 配置仅供参考

更多推荐

自定义、定制findbugs扫描类型,忽略指定类型

本文发布于:2023-04-28 04:38:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/ba647ae413e90cadf43a973d41059147.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:类型   自定义   findbugs

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!

  • 107677文章数
  • 27234阅读数
  • 0评论数