2013-06-19 2 views
1

가 나는 이유는 모르겠지만, 디버깅에 노력하고있는 동안, 나는 이것이 매우 이상한 찾을 경우 다음에 스킵 경우 :조건이 충족하지만

하면 이미지에서 보는 것처럼 enter image description here

in.readLine()의 값은 null이고 in.readLine() == nulltrue입니다. 하지만 왜 그것이 if (in.readLine() == null) { ... 라인을 건너 뛰는가? 그러나 내가 줄을 266267에 놓으려고 할 때, 그 조건에 코드를 입력하고있다.

enter image description here

코드 : 디버거는 in.readLine()을 평가할 때

private void startSOfficeService() throws InterruptedException, IOException { 
    if (System.getProperty("os.name").matches(("(?i).*Windows.*"))) { 
     try { 
      //Check if the soffice process is running 
      Process process = Runtime.getRuntime().exec("tasklist /FI \"IMAGENAME eq soffice.exe\""); 
      //Need to wait for this command to execute 
      int code = process.waitFor(); 

      //If we get anything back from readLine, then we know the process is running 
      BufferedReader in = new BufferedReader(new InputStreamReader(process.getInputStream())); 
      if (in.readLine() == null) { 
       //Nothing back, then we should execute the process 
       String[] SOFFICE_CMD = { SOFFICE_SERVICE_PATH, 
             "-accept=socket,host=" + SOFFICE_SERVICE_HOST + ",port=" + SOFFICE_SERVICE_PORT + ";urp;", 
             "-invisible", 
             "-nologo"}; 
       process = Runtime.getRuntime().exec(SOFFICE_CMD); 
       code = process.waitFor(); 
       System.out.println("soffice script started"); 
      } else { 
       System.out.println("soffice script is already running"); 
      } 

      in.close(); 
      in = null; 
      System.gc(); 
     } catch(Exception e) { 
      e.printStackTrace(); 
     } 
    } 
} 

답변

7

, 그것은 독자에서 소비한다. 따라서 읽는 내용의 마지막 줄에있는 경우 in.readLine()은 null이 아니므로 else에 컨트롤을 넣을 수 있지만 in.readLine()을 디버거에 표시하도록 평가하면 은 다시을 읽고 아무 ​​것도 없다고 확인합니다. 더 많은 행을 표시하고 디버거에 표시 할 값으로 null을 반환합니다.

실제 사진을 보려면 먼저 변수에 in.readLine()을 할당하고 단순히 변수를 읽는 것으로 변경되지 않는 해당 변수의 값을 봅니다.

+0

고마워요! :) –