Pet-Home 模组引发了服务器崩溃(由于我不回写报告,所以使用了AI。以下都是AI写的)
崩溃原因分析
- 配置未正确初始化
在 PetHomeConfig.noProtectionEntity 配置项为 null 时,代码尝试调用 contains() 方法
具体错误位置:FriendlyFireCommon.isProtected() 方法第63行
- 事件处理中的空指针异常
java
// 错误代码逻辑
java.lang.NullPointerException: Cannot invoke "java.util.Set.contains(Object)"
because "com.github.yzqdev.pethome.PetHomeConfig.noProtectionEntity" is null
- 触发场景
当僵尸在岩浆块上受伤时触发 LivingAttackEvent 事件
Pet-Home 的事件监听器 CommonProxy.onLivingHurt() 处理该事件
在处理过程中访问了未初始化的配置项
GitHub Issue 建议内容
markdown
Pet-Home 模组导致服务器崩溃
问题描述
服务器在启动后不久因 Pet-Home 模组抛出 NullPointerException 而崩溃。
崩溃日志关键信息
[03:26:27.990] [Server thread/ERROR] [net.minecraftforge.eventbus.EventBus/EVENTBUS]:
Exception caught during firing event: Cannot invoke "java.util.Set.contains(Object)"
because "com.github.yzqdev.pethome.PetHomeConfig.noProtectionEntity" is null
java.lang.NullPointerException: Cannot invoke "java.util.Set.contains(Object)"
because "com.github.yzqdev.pethome.PetHomeConfig.noProtectionEntity" is null
at com.github.yzqdev.pethome.util.FriendlyFireCommon.isProtected(FriendlyFireCommon.java:63)
text
重现步骤
- 安装 Pet-Home 模组 v1.0.4
- 启动 Minecraft 1.20.1 Forge 服务器
- 等待生物自然生成并受伤(如僵尸踩在岩浆块上)
- 服务器崩溃
可能原因
PetHomeConfig.noProtectionEntity 配置项未正确初始化
- 配置加载顺序问题,事件监听器在配置完全加载前就开始工作
- 缺少对配置项的空值检查
环境信息
- Minecraft: 1.20.1
- Forge: 47.4.9
- Pet-Home: 1.0.4
- 其他相关模组:C2ME, ModernFix, Radium 等优化模组
建议修复
在访问 noProtectionEntity 配置项前添加空值检查:
if (PetHomeConfig.noProtectionEntity != null && PetHomeConfig.noProtectionEntity.contains(entityType)) {
// 原有逻辑
}
或者确保配置在事件监听器注册前完全初始化。
text
这个 Issue 清晰地描述了问题现象、原因和可能的解决方案,方便开发者快速定位和修复问题。
[debug.log](https://github.com/user-attachments/files/22891765/debug.log)
[latest.log](https://github.com/user-attachments/files/22891766/latest.log)
Pet-Home 模组引发了服务器崩溃(由于我不回写报告,所以使用了AI。以下都是AI写的)
崩溃原因分析
在 PetHomeConfig.noProtectionEntity 配置项为 null 时,代码尝试调用 contains() 方法
具体错误位置:FriendlyFireCommon.isProtected() 方法第63行
java
// 错误代码逻辑
java.lang.NullPointerException: Cannot invoke "java.util.Set.contains(Object)"
because "com.github.yzqdev.pethome.PetHomeConfig.noProtectionEntity" is null
当僵尸在岩浆块上受伤时触发 LivingAttackEvent 事件
Pet-Home 的事件监听器 CommonProxy.onLivingHurt() 处理该事件
在处理过程中访问了未初始化的配置项
GitHub Issue 建议内容
markdown
Pet-Home 模组导致服务器崩溃
问题描述
服务器在启动后不久因 Pet-Home 模组抛出 NullPointerException 而崩溃。
崩溃日志关键信息
[03:26:27.990] [Server thread/ERROR] [net.minecraftforge.eventbus.EventBus/EVENTBUS]:
Exception caught during firing event: Cannot invoke "java.util.Set.contains(Object)"
because "com.github.yzqdev.pethome.PetHomeConfig.noProtectionEntity" is null
java.lang.NullPointerException: Cannot invoke "java.util.Set.contains(Object)"
because "com.github.yzqdev.pethome.PetHomeConfig.noProtectionEntity" is null
at com.github.yzqdev.pethome.util.FriendlyFireCommon.isProtected(FriendlyFireCommon.java:63)
text
重现步骤
可能原因
PetHomeConfig.noProtectionEntity配置项未正确初始化环境信息
建议修复
在访问
noProtectionEntity配置项前添加空值检查: