Skip to content

NullPointerException in revertSelfHostState due to missing hostState null check #44

Description

@Freshwlnd

Bug 描述
将请求配置文件中的 InstanceRetryTimes 修改为 10 后,运行程序出现 NullPointerException 错误:

java.lang.NullPointerException: Cannot load from int array because "hostState" is null
at org.lgdcloudsim.statemanager.StatesManagerSimple.revertSelfHostState(StatesManagerSimple.java:432)

复现步骤

  1. 修改配置文件,将 InstanceRetryTimes 参数设置为 10。
  2. 运行程序,观察日志输出。
  3. 发现程序在 revertSelfHostState 函数中抛出 NullPointerException 异常。

预期行为
程序应正常运行,不会因为 hostStatenull 导致 NullPointerException

实际行为
revertSelfHostState 方法中,第 431 和 432 行之间缺少判断条件。当 hostStatenull 时,未能跳过该状态,导致空指针异常。

可能的解决方案
revertSelfHostState 函数的第 431 和 432 行之间加入判断条件:

if (hostState == null) continue;

此更改的原理在于:

  1. selfState 用于记录上一次同步状态加上当前的调度结果。
  2. synAllState() 函数中,会在同步状态改变后对 selfHostStateMap 进行清空。
  3. 当某些 instance 的任务调度失败且未能实际迁移时,revertSelfHostState 会补全 selfState
  4. 在这两种情况同时出现且发生时序错位时,可能会导致 hostStatenull 的问题。

截图

  • 图 1:错误日志显示 NullPointerException(见附件)。
    image
  • 图 2:revertSelfHostState 函数代码片段,问题发生位置(见附件)。
    image
  • 图 3:synAllState() 函数中清空 selfHostStateMap 的代码(见附件)。
    image

环境

  • LGDCloudSim 版本:1.1.1
  • mvn 版本:4.0.0
  • Java 版本:17.0.10
  • 操作系统:CentOS Linux release 7.9.2009 (Core)

附加信息
该问题可能与调度器任务的某些 instance 未能被正确调度且同步状态的清空操作有关。

Metadata

Metadata

Labels

bugSomething isn't working

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions