java 声纳死存储到局部变量

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/17781768/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-11-01 14:58:29  来源:igfitidea点击:

Sonar dead store to local variable

javasonarqube

提问by Marcel H?ll

I have the following code and sonar is telling me the following error message:

我有以下代码,声纳告诉我以下错误消息:

Dead store to descriptions1 in new com.dscsag.dsct2c.test.TestStep(Integer, String, Model)

In the follwing code:

在以下代码中:

for (Integer count = 0; count < testStepCount; count++)
    {
      if (xmlReader.isTestExistingForOrderNumber(count, orderNumber, version))
      {
        if (xmlReader.checkForDuplicateTest(orderNumber, count, version))
        {
          GlobalVariables.LOGGING_logger.error("### " + this.getClass().getSimpleName()
              + ": There are one or more duplicated order numbers for test " + count + " under test step " + orderNumber + ".");
          model.setStatusText("STATUS_DUPLICATED_TEST", orderNumber.toString(), StatusCode.ERROR);
          throw new Exception();
        }
        else
        {
          GlobalVariables.LOGGING_logger.info("### " + this.getClass().getSimpleName() + ": No duplicated found for test " + count
              + " under test step " + orderNumber + ".");
          boolean functionNeeded = xmlReader.isFunctionNeededForOrderNumber(orderNumber, count, version);

          String[][] descriptions1 = new String[2][descriptions[0].length];

          for (int a = 0; a < this.descriptions[0].length; a++)
          {
            descriptions1[0][a] = descriptions[0][a];
            descriptions1[1][a] = xmlReader.getTestDescription(descriptions[0][a], orderNumber, count, version);
          }

          ArrayList<String> filesString = xmlReader.getTestFilesForOrderNumber(orderNumber, count, version);
          ArrayList<File> filesFile = new ArrayList<File>();
          Iterator<String> it = filesString.iterator();
          while (it.hasNext())
          {
            File file = new File(GlobalVariables.PATH_TestFiles
                + xmlReader.getValueDocumentConfiguration(XmlElements.CAD_APPL, XmlElements.TESTING_ENVIRONMENT, null) + "/" + it.next());
            filesFile.add(file);

            GlobalVariables.LOGGING_logger.info("### " + this.getClass().getSimpleName() + ": Added file to test " + count
                + " under test step " + orderNumber + ": \"" + file.getName() + "\"");
          }

          testObjectsList.add(new TestObject(functionNeeded, xmlReader.getFunctionNameForOrderNumber(orderNumber, count, version),
              descriptions1, filesFile));

          GlobalVariables.LOGGING_logger.info("### " + this.getClass().getSimpleName() + ": Finally created test object for test " + count
              + " under test step " + orderNumber + ".");
        }
      }
      else
      {
        model.setStatusText("STATUS_NO_TEST", count.toString(), StatusCode.WARNING);
      }
    }
  }

Can you see why I store to "dead" descriptions1? I think I have to use this variable.

你能明白为什么我存储到“死”descriptions1吗?我想我必须使用这个变量。

回答by Chriss

Its a false positive of sonar. Sonar works on the compiled code, not your source. I guess the access to descriptions1is optimized away or replaced by the compiler, thus sonar cant see it.

它是声纳的误报。声纳适用于编译后的代码,而不是您的源代码。我猜对 的访问descriptions1被优化掉了或被编译器替换了,因此声纳看不到它。