Files
his/.analysis/bug491_analysis.md
关羽 cf9f9d7cd0 Fix Bug #491: 【执行科室配置】保存配置时系统报错
添加根因分析报告,确认修复已在历史 commit (eaac1676, 982e9059) 中完成。
所有 NPE 防护已到位:organizationId 前置校验、activityDefinition 判空、
organization 判空降级、stream null 过滤。

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-05-16 19:07:10 +08:00

46 lines
2.3 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# Bug #491 分析报告
## Bug 信息
- **Title**: 【执行科室配置】保存配置时系统报错
- **Severity**: 3 | **Priority**: 3 | **Type**: codeerror
- **Status**: resolved (已被修复)
## 错误信息
```
Cannot invoke "com.openhis.administration.domain.Organization.getName()" because
the return value of "com.openhis.administration.service.impl.OrganizationServiceImpl.getById(...)" is null
```
## 根因分析
`OrganizationLocationAppServiceImpl.addOrEditOrgLoc()` 方法中,存在多处 `organizationService.getById()``activityDefinitionMapper.selectById()` 的返回值未做 null 检查就直接调用 `.getName()` 的情况:
1. **时间冲突检查**:当数据库中某条执行科室配置关联的 `organizationId` 对应的科室记录已被删除时,`organizationService.getById()` 返回 null直接调用 `.getName()` 导致 NPE。
2. **activityDefinition 查询**`activityDefinitionMapper.selectById()` 可能返回 null直接调用 `.getName()` 导致 NPE。
3. **organizationLocationInit()**stream 中未过滤 name 为 null 的 Organization 记录。
4. **缺少 organizationId 前置校验**:传入空 organizationId 时未提前拦截。
## 修复内容(已在以下 commit 中完成)
**eaac1676** (关羽): 修复时间冲突检查中的 organization NPE
-`organizationService.getById().getName()` 改为先赋值再判空
**982e9059** (刘备): 补充其余 NPE 防护
- 第74行stream 中增加 `.filter(organization -> organization != null && organization.getName() != null)`
- 第149-151行增加 `organizationId == null` 前置校验,返回"请选择执行科室"
- 第157-159行`activityDefinitionMapper.selectById().getName()` 改为先赋值再判空
## 当前代码状态确认
当前 HEAD (ede95be8) 已包含上述所有修复,具体代码位置:
- `OrganizationLocationAppServiceImpl.java:149` - organizationId null 校验
- `OrganizationLocationAppServiceImpl.java:157-159` - activityDefinition null 安全
- `OrganizationLocationAppServiceImpl.java:171-172` - organization null 安全
- `OrganizationLocationAppServiceImpl.java:74` - stream null 过滤
## 结论
**Bug #491 已修复**。所有相关的 NPE 防护均已到位,工作目录与 HEAD 一致,无待提交变更。
修复结果:✅ 已完成(历史 commit