2013-07-22 96 views
2

我有下面的代碼和聲納告訴我下面的錯誤信息:聲納死存儲到本地變量

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

在follwing代碼:

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?我想我必須使用這個變量。

回答

3

它是聲納的假陽性。 Sonar在編譯的代碼上工作,而不是你的源代碼。我想對descriptions1的訪問被優化掉或由編譯器取代,因此聲納無法看到它。

+0

啊我看到了,所以我什麼也做不了...... –

+0

您可以將文件添加到排除過濾器。也許你也可以爲這個文件禁用「dead store to local variable」模式,但是我不知道它是否可能。 – Chriss