From team-standards
Enforces Java coding standards (Alibaba Huangshan Edition) for naming, formatting, Javadoc, OOP, collections, concurrency, exceptions, and POJO rules. Use when writing, reviewing, or modifying Java code.
How this skill is triggered — by the user, by Claude, or both
Slash command
/team-standards:java-coding-standardsThe summary Claude sees in its skill listing — used to decide when to auto-load this skill
> **本文件只写 Java 独占条款。** 命名表意、函数原子、层次分明、零魔法值、注释三档、异常不静默、删冗余 这 7 条通用铁律在 `coding-standards-common/SKILL.md` 中,Java 编码同时遵守通用 skill + 本文件。
本文件只写 Java 独占条款。 命名表意、函数原子、层次分明、零魔法值、注释三档、异常不静默、删冗余 这 7 条通用铁律在
coding-standards-common/SKILL.md中,Java 编码同时遵守通用 skill + 本文件。触发顺序:
coding-standards-common(通用 7 条) →java-coding-standards(本文件 Java 独占)。
通用命名规则见
coding-standards-common §1。以下为 Java 独占:
Abstract / Base 开头;异常类以 Exception 结尾;测试类以被测类名开头、Test 结尾public 修饰符(冗余,接口方法默认 public)is 前缀(框架反序列化会出错,Jackson / Fastjson 都踩过)if / for / while / switch / do 即使只有一行也必须加大括号if 与括号之间有空格注释三档铁律(类 1-3 行 / 方法 1-2 行 / 核心块 1 行)见
coding-standards-common §5。以下为 Java 独占:
/** */),禁用 //@param / @return / @throws)示例:
/**
* 并发控制器 — 基于 Semaphore 限制同时执行的任务数量。
*
* <p>属于 Infrastructure 层,被 {@link DevPlanTaskManagerImpl} 调用。</p>
*/
@Component
public class ConcurrencyController {
/** 并发信号量,permits 数量由配置项 devplan.max-concurrent 决定 */
private final Semaphore semaphore;
/**
* 尝试获取一个并发执行槽位。非阻塞,获取失败立即抛异常,避免请求堆积。
*
* @throws ConcurrencyExceededException 当前并发数已达上限时抛出
*/
public void acquire() {
if (!semaphore.tryAcquire()) {
// 非阻塞获取失败,说明并发数已满,快速失败
throw new ConcurrencyExceededException("并发超限,请稍后重试");
}
}
}
@Override== 比较 Integer 等包装类(应用 .equals())== 或 equals 比较,须用差值范围或 BigDecimalStringBuilder.append,禁止在循环内用 +toString()@Deprecated 标记的类或方法Integer 等),不得用基本类型(int 等),避免 0 / null 语义混淆equals 必须同时覆写 hashCodeArrays.asList() 返回的 List 禁 add / remove / clear(底层是定长数组)foreach 里 remove / add,须用 IteratorHashMap 初始化时须指定初始容量(expectedSize / 0.75 + 1),避免触发扩容entrySet,不用 keySet + get(后者多一次哈希查找)CollectionUtils.isEmpty(),不用 == null || size() == 0new Thread() 手动创建线程,必须使用线程池Executors 直接创建线程池,须用 ThreadPoolExecutor 手动指定参数(队列、拒绝策略)SimpleDateFormat 禁止定义为 static(线程不安全);JDK 8+ 用 DateTimeFormatterThreadLocal 使用完毕后必须调用 remove()(否则线程池场景内存泄漏)ConcurrentHashMap 等)通用规则(catch 不静默、日志带堆栈、不用 try-catch 做流程控制)见
coding-standards-common §6。以下为 Java 独占:
finally 中禁止使用 return(会吞掉 try 的返回值或异常)catch 块须手动回滚事务(TransactionAspectSupport.currentTransactionStatus().setRollbackOnly() 或抛 RuntimeException)Log4j / Logback API,须用 SLF4J 门面(org.slf4j.Logger)log.info("name: {}", name)log.error("处理订单失败,orderId={}", orderId, e),禁止只打 e.getMessage()(丢堆栈)id、create_time、update_time 三个字段decimal,禁止 float / double(精度问题)SELECT *,须列明所有查询字段LIKE '%keyword' 开头的模糊查询(走不了索引)通用安全(用户输入校验、敏感数据脱敏、鉴权服务端)见
coding-standards-common(暂未单独成节,后续可补)。以下为 Java 独占:
#{} 占位符(不用 ${})| 错误写法 | 正确写法 |
|---|---|
if (a == b) 比较 Integer | if (a.equals(b)) |
log.error(e.getMessage()) | log.error("描述: {}", param, e) |
new Thread(() -> {}).start() | 使用线程池 |
SELECT * | 列明字段 |
Executors.newFixedThreadPool(10) | new ThreadPoolExecutor(...) |
布尔字段 isDeleted | 字段名 deleted |
for 循环内 str += x | StringBuilder.append(x) |
static SimpleDateFormat sdf = ... | DateTimeFormatter.ofPattern(...) |
new HashMap<>() 然后塞 1000 条 | new HashMap<>(1334) |
// 这是个 user 类 | /** 用户聚合根,负责... */ |
Provides behavioral guidelines to reduce common LLM coding mistakes, focusing on simplicity, surgical changes, assumption surfacing, and verifiable success criteria.
Searches, retrieves, and installs Agent Skills from prompts.chat registry using MCP tools like search_skills and get_skill. Activates for finding skills, browsing catalogs, or extending Claude.
Creates, edits, and optimizes skills for Claude Code, including drafting, evaluating with test prompts, iterating on performance, and improving skill descriptions for better triggering accuracy.
npx claudepluginhub exception-coder/team-standards --plugin team-standards