AgentStack
Browse Sign in
Browse Why AgentStack Sell Docs
Sign in
SKILL verified Apache-2.0 Self-run

Java Check Spotbugs

skill-hellyguo-self-ai-spec-java-check-spotbugs · by hellyguo

SpotBugs静态分析技能:使用SpotBugs、Find Security Bugs、fb-contrib进行Java代码缺陷和安全分析

No reviews yet
0 installs
21 views
0.0% view→install

Install

$ agentstack add skill-hellyguo-self-ai-spec-java-check-spotbugs

✓ scanned · ✓ verified, works with Claude Code, Cursor, and more.

Security review

✓ Passed

No issues found. Passed automated security review. · v0.1.0 How review works →

  • Prompt-injection patterns
  • Secret / credential exfiltration
  • Dangerous shell & filesystem operations
  • Untrusted network calls
  • Known-malicious package signatures

What it can access

  • Network access No
  • Filesystem access No
  • Shell / process execution No
  • Environment & secrets No
  • Dynamic code execution No

From automated source analysis of v0.1.0. “Used” means the capability is present in the source — more access means more to trust, not that it’s unsafe.

View the full security report →

Verified badge

Passed review? Show it. Paste this badge into your README, it links to the public security report.

AgentStack Verified badge Links to your public security report.
[![AgentStack Verified](https://agentstack.voostack.com/badges/verified.svg)](https://agentstack.voostack.com/security/report/skill-hellyguo-self-ai-spec-java-check-spotbugs)

Reliability & compatibility

Security review passed
0 installs to date
no reviews yet
2mo ago

Declared compatibility

Claude CodeClaude Desktop

Compatibility is declared by the source manifest. End-to-end runtime verification is coming, see below.

Preview Execution monitoring

We're building live execution health for every listing: tool-call success rate, median latency, uptime, and last-checked timestamps, measured, not self-reported. It isn't live yet, so we don't show numbers we can't stand behind.

How agent discovery & health will work →
Are you the author of Java Check Spotbugs? Claim this listing to set pricing, connect Stripe payouts, and keep 70% of every sale.
Sign up to claim

About

SpotBugs Java静态分析技能

概述

SpotBugs(原FindBugs)是Java静态分析工具,可检测200+种代码缺陷模式。本技能整合了:

  • SpotBugs 4.7.3:基础缺陷检测
  • Find Security Bugs:安全漏洞检测
  • fb-contrib:额外检测规则

版本兼容性说明

Java版本支持

  • SpotBugs 4.7.3:最高支持到Java 17(class文件major version 61)
  • 当前Java运行时:Java 25(class文件major version 69)→ 不兼容
  • 解决方案:使用Java 17或更早版本的JDK运行SpotBugs分析

兼容性检查

# 检查Java版本
java -version

# 检查class文件版本
javap -verbose target/classes/com/example/Test.class | grep major

工具位置

# SpotBugs主工具
SPOTBUGS_HOME=~/app/spotbugs-4.7.3
SPOTBUGS_JAR=$SPOTBUGS_HOME/lib/spotbugs.jar

# 插件位置(源码位置)
FIND_SEC_BUGS_SRC=/home/helly/open_source/github/find-sec-bugs/
FB_CONTRIB_SRC=/home/helly/open_source/github/fb-contrib/

使用场景

1. 常规缺陷检测

检测空指针异常、资源泄漏、并发问题等常见缺陷。

2. 安全漏洞扫描

检测SQL注入、XSS、命令注入等安全漏洞。

3. 代码质量分析

检测代码坏味道、潜在的性能问题。

执行流程

步骤1:准备Java字节码

# 编译Java项目
mvn compile  # Maven项目
gradle classes  # Gradle项目
javac -d target/classes src/*.java  # 手动编译

步骤2:执行SpotBugs分析

# 基本分析(只使用SpotBugs核心规则)
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/

配置文件

自定义过滤器(filter.xml)


  
  
    
  
  
  
  
    
  
  
  
  
    
  

使用过滤器

java -jar $SPOTBUGS_JAR -textui -output filtered.txt \
  -exclude filter.xml \
  target/classes/

检测器分类

安全检测器(Find Security Bugs)

| 检测器 | 检测问题 | 严重等级 | |--------|----------|----------| | SQLINJECTION | SQL注入漏洞 | 高危 | | COMMANDINJECTION | 命令注入 | 高危 | | XSSREQUESTPARAMETERTOSENDERROR | XSS漏洞 | 高危 | | WEAKMESSAGEDIGEST | 弱哈希算法 | 中危 | | INSECURECOOKIE | 不安全Cookie设置 | 中危 |

性能检测器(fb-contrib)

| 检测器 | 检测问题 | 建议 | |--------|----------|------| | LOOPCANBEWHILE | 可简化的循环 | 优化循环结构 | | UNNECESSARYSTOREBEFORERETURN | 不必要的变量存储 | 直接返回 | | METHODNAMINGCONVENTION | 方法命名规范 | 遵循命名约定 |

基础检测器(SpotBugs核心)

| 类别 | 检测器数量 | 主要检测问题 | |------|------------|--------------| | 正确性 | 45+ | 空指针、资源泄漏 | | 不良实践 | 30+ | 异常处理、序列化 | | 多线程 | 25+ | 同步、死锁 | | 性能 | 20+ | 冗余操作、低效算法 | | 安全 | 15+ | 硬编码密码、不安全反射 |

输出格式

1. 文本格式(默认)

M B IC: Incorrect check of compare result in com.example.Test.compare() 
  At Test.java:[line 45]
  Pattern: IC_SUPERCLASS_USES_SUBCLASS_DURING_INITIALIZATION
  Rank: Scary (15)

2. XML格式(用于集成)

java -jar $SPOTBUGS_JAR -xml -output spotbugs.xml target/classes/

3. HTML报告(可视化)

java -jar $SPOTBUGS_JAR -html -output spotbugs.html target/classes/

集成到CI/CD

Maven集成


  com.github.spotbugs
  spotbugs-maven-plugin
  4.7.3.0
  
    Max
    Low
    
      
        com.h3xstream.findsecbugs
        findsecbugs-plugin
        1.12.0
      
    
  

Gradle集成

plugins {
  id "com.github.spotbugs" version "5.0.14"
}

dependencies {
  spotbugsPlugins 'com.h3xstream.findsecbugs:findsecbugs-plugin:1.12.0'
}

spotbugs {
  toolVersion = '4.7.3'
  effort = 'max'
  reportLevel = 'low'
}

常用命令参考

查看所有检测器

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/

分析结果处理

1. 结果解析脚本示例

#!/bin/bash
# 解析SpotBugs输出,提取关键问题
grep -E "(HIGH|Scary|Scariest)" spotbugs.txt | head -20
grep -i "sql_injection\|xss\|command_injection" spotbugs.txt

2. 问题分类统计

# 统计各类问题数量
cat spotbugs.txt | grep "Pattern:" | sort | uniq -c | sort -nr

3. 生成摘要报告

# 生成问题摘要
echo "=== SpotBugs分析报告 ===" > summary.txt
echo "分析时间: $(date)" >> summary.txt
echo "总问题数: $(grep -c "Pattern:" spotbugs.txt)" >> summary.txt
echo "高危问题: $(grep -c "Rank: Scary\|Rank: Scariest" spotbugs.txt)" >> summary.txt
echo "安全漏洞: $(grep -i "sql_injection\|xss\|command_injection" spotbugs.txt | wc -l)" >> summary.txt

最佳实践

1. 定期执行

  • 每次代码提交前运行基础检查
  • 每周运行完整安全扫描
  • 发布前运行所有检测器

2. 结果处理

  • 高危问题必须立即修复
  • 中危问题应在迭代内修复
  • 低危问题可记录技术债务

3. 团队协作

  • 将SpotBugs纳入代码审查流程
  • 培训团队理解检测结果
  • 建立问题修复SLA

注意事项

  1. 误报率:静态分析工具存在误报,需要人工确认
  2. 覆盖范围:只能分析字节码,无法分析动态行为
  3. 性能影响:完整分析可能较慢,建议增量分析
  4. 版本兼容:确保工具版本与Java版本兼容

故障排除

常见问题

  1. ClassNotFoundException:确保类路径正确
  2. No classes specified:确认编译后的字节码存在
  3. 插件加载失败:检查插件JAR路径和版本
  4. Unsupported class file major version:Java版本不兼容,使用Java 17或更早版本

版本兼容性解决方法

# 方法1:使用Java 17或更早版本
# 设置JAVA_HOME指向兼容版本
export JAVA_HOME=/path/to/java17
java -jar $SPOTBUGS_JAR -textui target/classes/

# 方法2:使用容器运行
docker run -v $(pwd):/code openjdk:17-jdk \
  java -jar /path/to/spotbugs.jar -textui /code/target/classes/

# 方法3:升级到支持Java 25的SpotBugs版本
# 需要下载SpotBugs 5.0+版本

技能版本: 1.0.0 工具版本: SpotBugs 4.7.3 + Find Security Bugs + fb-contrib 适用项目: Java 17及以下版本项目 Java兼容性: 最高支持Java 17(class文件major version 61) 输出位置: 当前目录下的spotbugs-*.txt文件

Source & license

This open-source skill is cataloged on AgentStack and links to its original source — we do not rehost the code.

Install and usage instructions live in the source repository linked above.

Reviews

No reviews yet, be the first.

Versions

  • v0.1.0 Imported from the upstream source.