feat: Agent 工作区初始提交(源码+文档+Skills)
包含 CodeAgent 前后端源码、SKILLS、MCP、demo 代码与工作区文档。 排除依赖缓存、运行数据、备份与二进制附件,规则见 .gitignore。 Co-Authored-By: Claude Code <[email protected]>
This commit is contained in:
@@ -0,0 +1,15 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>com.demo</groupId>
|
||||
<artifactId>demo-order</artifactId>
|
||||
<version>1.0.0</version>
|
||||
<packaging>jar</packaging>
|
||||
<properties>
|
||||
<maven.compiler.source>21</maven.compiler.source>
|
||||
<maven.compiler.target>21</maven.compiler.target>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
</project>
|
||||
@@ -0,0 +1,27 @@
|
||||
package com.demo;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
/**
|
||||
* 订单实体
|
||||
*/
|
||||
public class Order {
|
||||
private BigDecimal amount;
|
||||
private BigDecimal discount;
|
||||
|
||||
public BigDecimal getAmount() {
|
||||
return amount;
|
||||
}
|
||||
|
||||
public void setAmount(BigDecimal amount) {
|
||||
this.amount = amount;
|
||||
}
|
||||
|
||||
public BigDecimal getDiscount() {
|
||||
return discount;
|
||||
}
|
||||
|
||||
public void setDiscount(BigDecimal discount) {
|
||||
this.discount = discount;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
package com.demo;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
/**
|
||||
* 订单服务(示例项目)
|
||||
* 功能:提供订单总额计算等订单相关服务
|
||||
* 修改原因:原实现中 calculateTotal 存在 NPE 空指针缺陷,本次进行非空防护修复,并同步补齐中文注释与中文提示文案
|
||||
*/
|
||||
public class OrderService {
|
||||
|
||||
/**
|
||||
* 计算订单总额(订单金额 - 折扣)
|
||||
*
|
||||
* 功能:根据订单对象计算最终应付总额
|
||||
* 修改原因:原实现直接链式调用 order.getAmount().subtract(order.getDiscount()),
|
||||
* 在 order / amount / discount 任一为 null 时都会抛出 NullPointerException,属于隐式空指针缺陷
|
||||
*
|
||||
* 修改清单(三个潜在 NPE 空指针点,原因:链式调用前缺少非空判断,JVM 会直接抛 NullPointerException):
|
||||
* 1. order 为 null 时,order.getAmount() 抛 NPE —— 已修复:方法入口前置非空校验
|
||||
* 2. order.amount 为 null 时,amount.subtract() 抛 NPE —— 已修复:取值后非空校验
|
||||
* 3. order.discount 为 null 时,amount.subtract(discount) 抛 NPE —— 已修复:取值后非空校验
|
||||
*
|
||||
* @param order 订单对象,不允许为 null
|
||||
* @return 订单总额(金额减去折扣)
|
||||
*/
|
||||
public BigDecimal calculateTotal(Order order) {
|
||||
// 功能:订单入参非空校验;修改原因:order 为 null 时后续 getAmount() 会抛 NPE
|
||||
if (order == null) {
|
||||
throw new IllegalArgumentException("订单对象 order 不能为空");
|
||||
}
|
||||
BigDecimal amount = order.getAmount();
|
||||
// 功能:金额字段非空校验;修改原因:amount 为 null 时 amount.subtract() 会抛 NPE
|
||||
if (amount == null) {
|
||||
throw new IllegalArgumentException("订单金额 order.amount 不能为空");
|
||||
}
|
||||
BigDecimal discount = order.getDiscount();
|
||||
// 功能:折扣字段非空校验;修改原因:discount 为 null 时 amount.subtract(discount) 会抛 NPE
|
||||
if (discount == null) {
|
||||
throw new IllegalArgumentException("订单折扣 order.discount 不能为空");
|
||||
}
|
||||
// 功能:计算订单总额 = 金额 - 折扣;此时 amount、discount 均已确认非空,subtract 不会再触发 NPE
|
||||
return amount.subtract(discount);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user