java-check-spotbugs
Skill8 starsChanged 16 days agoApache-2.0View on GitHub
使用 SpotBugs(含 Find Security Bugs、fb-contrib)对 Java 字节码做缺陷与安全分析。适用于 Java 项目缺陷排查、安全审计、CI 集成。
In this repository32 other files it gives its agents.
- AGENTS.mdAGENTS.md
- ast-grep-blockSkill
- code-deconstructSkill
- code-detect-dupSkill
- code-detect-problemSkill
- code-part-modificationSkill
- code-refactorSkill
- code-reviewSkill
- cpp-checkSkill
- cpp-clang-tidySkill
- cpp-tscancodeSkill
- full-analysisSkill
- gdb-heap-analysisSkill
- java-asprofSkill
- java-check-pmdSkill
- java-coverageSkill
- java-envSkill
- java-g2mSkill
- jmh-benchSkill
- lets-loopSkill
- long-term-taskSkill
- md2pdfSkill
- merge-agents-mdSkill
- qualitative-assessmentSkill
- requirement-collectSkill
- rust-clippySkill
- rust-flamegraphSkill
- shell-checkSkill
- sql-extractSkill
- sync-dev-specSkill
- sync-repo-docsSkill
- vbox-test-envSkill
The file
Files
SpotBugs Java静态分析技能
本文件中的
templates/...均指本技能目录下的templates/子目录。
版本兼容性
- SpotBugs 4.7.3:最高支持Java 17(class文件major version 61)
- Java 25不兼容,需使用Java 17或更早版本运行分析
java -version
javap -verbose target/classes/com/example/Test.class | grep major工具位置
SPOTBUGS_HOME=~/app/spotbugs-4.7.3
SPOTBUGS_JAR=$SPOTBUGS_HOME/lib/spotbugs.jar
FIND_SEC_BUGS_SRC=${HOME}/open_source/github/find-sec-bugs/
FB_CONTRIB_SRC=${HOME}/open_source/github/fb-contrib/执行流程
步骤1:准备字节码
mvn compile # Maven
gradle classes # Gradle
javac -d target/classes src/*.java # 手动步骤2:执行分析
# 基础分析
java -jar $SPOTBUGS_JAR -textui -output spotbugs-basic.txt target/classes/
# 含安全检测
java -jar $SPOTBUGS_JAR -textui -output spotbugs-security.txt \
-pluginList $FIND_SEC_BUGS_JAR target/classes/
# 完整分析(所有插件)
java -jar $SPOTBUGS_JAR -textui -output spotbugs-full.txt \
-pluginList $FIND_SEC_BUGS_JAR:$FB_CONTRIB_JAR target/classes/步骤3:特定检测器
# 仅安全漏洞
java -jar $SPOTBUGS_JAR -textui -output security-only.txt \
-pluginList $FIND_SEC_BUGS_JAR -onlyAnalyze ".*Security.*" target/classes/
# 性能和资源问题
java -jar $SPOTBUGS_JAR -textui -output performance.txt \
-effort:max -visitors "FindDeadLocalStores,FindUnconditionalWait,FindReturnRef" target/classes/步骤4:生成报告
使用模板 templates/report.md 输出分析报告。
配置与过滤
使用模板 templates/filter.xml 自定义过滤器:
java -jar $SPOTBUGS_JAR -textui -output filtered.txt \
-exclude filter.xml target/classes/输出格式
| 格式 | 命令参数 | 用途 |
| 文本 | -textui | 默认,终端查看 |
| XML | -xml | CI集成 |
| HTML | -html | 可视化报告 |
检测器分类
| 插件 | 主要检测 | 典型Pattern |
| SpotBugs核心 | 空指针、资源泄漏、并发、性能 | IC_SUPERCLASS_USES_SUBCLASS |
| Find Security Bugs | SQL注入、XSS、命令注入 | SQL_INJECTION, COMMAND_INJECTION |
| fb-contrib | 代码坏味道、命名规范 | LOOP_CAN_BE_WHILE |
常用命令
| 场景 | 命令 |
| 查看所有检测器 | java -jar $SPOTBUGS_JAR -textui -list |
| 分析特定类 | java -jar $SPOTBUGS_JAR -textui -onlyAnalyze "com.example.security.*" target/classes/ |
| 低阈值(更多问题) | java -jar $SPOTBUGS_JAR -textui -low target/classes/ |
| 高阈值(仅严重) | java -jar $SPOTBUGS_JAR -textui -high target/classes/ |
CI/CD集成
Maven
<plugin>
<groupId>com.github.spotbugs</groupId>
<artifactId>spotbugs-maven-plugin</artifactId>
<version>4.7.3.0</version>
<configuration>
<effort>Max</effort>
<threshold>Low</threshold>
</configuration>
</plugin>Gradle
plugins {
id "com.github.spotbugs" version "5.0.14"
}
spotbugs {
toolVersion = '4.7.3'
effort = 'max'
reportLevel = 'low'
}故障排除
| 问题 | 解决方案 |
| Unsupported class file major version | 使用Java 17或更早版本 |
| ClassNotFoundException | 检查类路径 |
| No classes specified | 确认编译后字节码存在 |
| 插件加载失败 | 检查插件JAR路径和版本 |
版本兼容性解决:
export JAVA_HOME=/path/to/java17
java -jar $SPOTBUGS_JAR -textui target/classes/技能版本: 1.0.0 工具版本: SpotBugs 4.7.3 + Find Security Bugs + fb-contrib 适用项目: Java 17及以下版本项目
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

