/java-skills:commons-patternsfrom java-skills
Provides best practices for Apache Commons libraries (Lang3, IO, Collections4) including StringUtils null-safety, file I/O patterns, and collection operations. Corrects common LLM misuses like confusing isBlank vs isEmpty or using the wrong package name.
Ships in java-skills. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them.
| 场景 | Commons | Guava | Hutool | 优先选 |
|---|---|---|---|---|
| 字符串判空/截断/填充 | ⭐⭐⭐ | ⭐⭐ | ⭐⭐⭐ | 任意(团队约定) |
| 文件复制/删除/读行 | ⭐⭐⭐ | ⭐ | ⭐⭐ | Commons IO |
| 文件名/路径处理 | ⭐⭐⭐ | — | ⭐⭐ | Commons IO |
| 集合运算(交/并/差) | ⭐⭐⭐ | ⭐⭐⭐ | ⭐⭐⭐ | 任意 |
| 日期处理(旧Date) | ⭐ | — | ⭐⭐⭐ | Java8 Time |
| 随机字符串 | ⭐⭐⭐ | — | ⭐⭐ | Commons Lang3 |
| HTML/XML转义 | ⭐⭐⭐ | — | ⭐ | Commons Lang3 |
| 数学/统计 | ⭐⭐⭐ | — | ⭐ | Commons Math |
// ✅ isEmpty: null 或 "" → true (不含空格)
StringUtils.isEmpty(null); // true
StringUtils.isEmpty(""); // true
StringUtils.isEmpty(" "); // false ← 注意!
StringUtils.isEmpty("abc"); // false
// ✅ isBlank: null 或 空白字符 → true
StringUtils.isBlank(null); // true
StringUtils.isBlank(""); // true
StringUtils.isBlank(" "); // true ← 含空格也true
StringUtils.isBlank("abc"); // false
// ✅ 选择规则: 表单验证用isBlank(不接受空白输入),集合判空用isEmpty
// ✅ defaultString: null安全取值
StringUtils.defaultString(str, ""); // null → ""
StringUtils.defaultIfBlank(str, "N/A"); // null/""/" " → "N/A"
// ✅ 填充与截断
StringUtils.leftPad("1", 3, '0'); // "001"
StringUtils.abbreviate("very long text", 10); // "very lo..."
// ✅ 读取整个文件(小文件,<10MB)
String content = FileUtils.readFileToString(file, StandardCharsets.UTF_8);
List<String> lines = FileUtils.readLines(file, StandardCharsets.UTF_8);
// ✅ 逐行读(大文件) — LineIterator 模式
LineIterator it = FileUtils.lineIterator(file, "UTF-8");
try { while (it.hasNext()) { String line = it.nextLine(); /* 处理 */ }
} finally { LineIterator.closeQuietly(it); }
// ✅ 流操作(需手动关流)
InputStream in = new URL("https://example.com").openStream();
try { String result = IOUtils.toString(in, StandardCharsets.UTF_8); }
finally { IOUtils.closeQuietly(in); }
// ❌ 反模式: IOUtils.toString() 读 1GB 文件 → 尝试创建1GB String → OOM
// ✅ 写入/复制/删除
FileUtils.writeStringToFile(file, content, StandardCharsets.UTF_8);
FileUtils.copyFile(src, dest);
FileUtils.forceMkdir(dir); // 递归创建目录
FileUtils.deleteDirectory(dir); // 递归删除
// ✅ 文件名处理
FilenameUtils.getExtension("archive.tar.gz"); // "gz" (最后一个.)
FilenameUtils.getBaseName("/path/file.txt"); // "file"
String normalized = FilenameUtils.normalize("C:/a/../b/file.txt"); // "C:/b/file.txt"
// ❌ 旧包名 — 不要用
import org.apache.commons.lang.StringUtils;
// ✅ 新包名(3.0+) — 必须用
import org.apache.commons.lang3.StringUtils;
// Maven坐标
// groupId: commons-lang → org.apache.commons
// artifactId: commons-lang → commons-lang3
// ⚠️ Commons Lang 3.0 变化: Validate 校验 null 抛 NullPointerException
// (对齐JDK标准行为,以前抛 IllegalArgumentException)
Validate.notNull(obj, "参数不能为空: %s", name); // 抛 NPE
Validate.isTrue(age > 0, "年龄必须>0"); // 抛 IllegalArgumentException
// 注意:验证null用Validate.notNull,验证状态用Validate.isTrue
// ✅ 随机字母数字(验证码/Token)
RandomStringUtils.randomAlphanumeric(6); // "a3Bx9K"
RandomStringUtils.randomAlphanumeric(32); // 32位Token
// ✅ 随机数字
RandomStringUtils.randomNumeric(6); // "482931"
// ✅ 随机字母
RandomStringUtils.randomAlphabetic(8); // "AbCdEfGh"
// ⚠️ 包名: org.apache.commons.collections4 (不是 collections)
CollectionUtils.isEmpty(coll);
CollectionUtils.union(list1, list2); // 并集
CollectionUtils.intersection(list1, list2); // 交集
CollectionUtils.subtract(list1, list2); // 差集(list1 - list2)
MapUtils.getString(map, "key", "default"); // null安全取值
本技能不收集、存储或传输任何用户数据。
What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
Other plugins' skills for the same job
Generated from the plugin's indexed repository (full-stack-skills/java-skills) — no native marketplace selected
npx claudepluginhub p/full-statck-skills-java-skills39 skills in this plugin
/caffeine-patternsCaffeine JVM 本地缓存技能。覆盖本地缓存 vs 远程缓存(Redis)选择决策树、expireAfterWrite vs expireAfterAccess vs refreshAfterWrite 三种过期策略对比与组合规则(refresh < expire)、CacheLoader加载与reload异步刷新模式、Spring Cache @Cacheable集成、maximumSize驱逐策略、recordStats缓存统计。 纠正 LLM:用 ConcurrentHashMap+手动过期、所有缓存走Redis、refreshAfterWrite > expireAfterWrite导致永远不刷新、CacheLoader返回null导致缓存穿透。/easy4j-deployeasy4j 组织标准发布流程与多分支 Maven 发布规范。适用于 io.github.easy4j 仓库(如 openclaw-java-sdk、okhttp3-extension 及其他 easy-4-java 组织组件)的以下场景:(1) SDK 三分支正式版发布(标准流程:创建 tag → 发布 Maven Central → bump SNAPSHOT,支持子智能体并行编排),(1b) xxx-spring-boot-starter 十分支发布(依赖 SDK 先转正式版 + tag + Central + bump),(2) 发布阿里云私有库 SNAPSHOT,(3) 三分支(feature/1.0.x JDK 8、feature/2.0.x JDK 17、feature/3.0.x JDK 21)源码同步,(4) 发布前 CVE 扫描与依赖升级(Jackson BOM 版本控制规则、JDK 依赖天花板),(5) 发布故障排查(409 冲突、Central 拒绝 SNAPSHOT 依赖、argLine 问题)。触发词:发布、上线、deploy、release、发版、发布正式版、同步分支、版本号升级。/easyexcel-fill基于 Alibaba EasyExcel(com.alibaba:easyexcel:4.0.3)的 Excel 模板填充技能。覆盖简单对象填充、列表填充({.}+forceNewRow)、横向多列组合填充(FillWrapper+WriteDirectionEnum.HORIZONTAL)、复杂填充(含合计行/统计行/先 fill 后 write)、Spring Boot 集成、模板设计规范、转义字符、03版/07版差异、性能优化(分次 fill、文件缓存)。当用户需要把 Java 对象或 Map 数据按预制 .xlsx 模板(变量语法 {var}、{.}、{prefix.})填充生成报表(工资条/合同/对账单/发票/财务报表/统计表/汇总表)时使用此技能,不适用于不基于模板的"程序生成 Excel"场景(改用 easyexcel-write)。/easyexcel-read基于 Alibaba EasyExcel(com.alibaba:easyexcel:4.0.3)的 Excel 数据读取技能。覆盖监听器模式(ReadListener/AnalysisEventListener/PageReadListener)、同步读取(doReadSync)、多 Sheet 读取、@ExcelProperty(index/name)匹配、多行表头(headRowNumber)、日期数字自定义转换器(@DateTimeFormat/@NumberFormat/Converter)、监听器异常处理(onException + ExcelDataConvertException)、额外信息读取(批注/超链接/合并单元格,extraRead + CellExtra)、公式和单元格类型(CellData<T>)、不创建对象的读(ReadListener<Map<Integer,String>>)、Web 上传读取(MultipartFile→InputStream)。当用户需要解析 Excel(导入数据/批量入库/对账文件/用户上传/Excel 转对象/Excel 转 Map)时使用此技能,不适用于按预制模板填充(改用 easyexcel-fill)、不适用于程序化生成 Excel(改用 easyexcel-write)。/easyexcel-write基于 Alibaba EasyExcel(com.alibaba:easyexcel:4.0.3)的 Excel 数据写入技能。覆盖最简写入(3 种写法)、复杂表头(多级)、@ExcelProperty/@ExcelIgnore/@DateTimeFormat/@NumberFormat 注解、includeColumn/excludeColumn 选择列、@ColumnWidth/@ContentRowHeight 样式注解、@HeadStyle/@ContentStyle 自定义样式、合并单元格(@ContentLoopMerge/LoopMergeStrategy)、图片导出(File/InputStream/URL/byte[])、超链接/批注/公式/富文本(WriteCellData)、动态表头、自动列宽、自定义拦截器(CellWriteHandler/SheetWriteHandler/RowWriteHandler)、分页分批写入、Web 下载直接写 OutputStream、03/07 版兼容。当用户需要程序化生成 Excel(无预制模板)导出订单/用户/财务/库存/报表/对账单/审批单等结构化数据时使用此技能,不适用于按预制模板填充(改用 easyexcel-fill)、不适用于读取 Excel(改用 easyexcel-read)。/guava-patternsGoogle Guava 最佳实践模式。从官方 wiki 提炼,覆盖 Immutable集合的 of/copyOf/builder 三模式与防御性拷贝规则、Cache 选择决策(LoadingCache vs Cache vs Caffeine)、Joiner/Splitter 不可变流水线、CharMatcher 替代正则、Preconditions 格式化消息校验、CaseFormat 命名互转。 纠正 LLM 误用:手写不可变集合、ConcurrentHashMap 替代 Cache、不知 CharMatcher。