嵌套 while-switch-switch 构造中的规则 S2538 误报

False positive with rule S2538 in nested while-switch-switch construction

在以下代码中使用规则 S2538 时出现误报

  EventLogLevel[] eventLevels = null;
  bool reachedEnd = false;
  while(!reachedEnd && jsonReader.Read())
  {
    switch(jsonReader.TokenType)
    {
      case JsonToken.PropertyName:
        string propertyName = jsonReader.Value.ToString();

        switch(propertyName)
        {
          case nameof(EventLevels):
            eventLevels = EventSettingsJson.ParseEventLogLevelsArray(nameof(EventLevels), jsonReader);
            break;
          default:
            throw new JsonParserException($"Invalid property: {propertyName}");
        }

        break;
      case JsonToken.EndObject:
        reachedEnd = true;
        break;
      default:
        throw new JsonParserException($"Unexpected Token Type while parsing json properties. TokenType: {jsonReader.TokenType}");
    }
  }

  if(eventLevels != null)
  {
    return new EventLogCollectionSettings(eventLogName, eventLevels);
  }

最后一个 if (eventLevels != null) 显示带有消息的警告:

[Change this condition so that it does not always evaluate to "false"].

我无法创建测试用例来重现它。

我们知道我们的数据流分析引擎存在这个限制。它与这张票有关:https://jira.sonarsource.com/browse/SLVS-1091。我们还没有修复它。