gpt4 book ai didi

java - Sonar 死存储到局部变量

转载 作者:行者123 更新时间:2023-12-04 04:48:38 26 4
gpt4 key购买 nike

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

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

在以下代码中:
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);
}
}
}

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

最佳答案

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

关于java - Sonar 死存储到局部变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17781768/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com