]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-7435 DefaultProcessCommands close() doesn't throw any exception
authorSébastien Lesaint <sebastien.lesaint@sonarsource.com>
Thu, 10 Mar 2016 09:52:51 +0000 (10:52 +0100)
committerSébastien Lesaint <sebastien.lesaint@sonarsource.com>
Mon, 21 Mar 2016 15:44:04 +0000 (16:44 +0100)
this make writing try-with-resource easier

server/sonar-process-monitor/src/main/java/org/sonar/process/monitor/Monitor.java
server/sonar-process/src/main/java/org/sonar/process/AllProcessesCommands.java
server/sonar-process/src/main/java/org/sonar/process/DefaultProcessCommands.java
server/sonar-process/src/main/java/org/sonar/process/ProcessCommands.java
server/sonar-server/src/main/java/org/sonar/server/app/ProcessCommandWrapperImpl.java
server/sonar-server/src/test/java/org/sonar/server/app/ProcessCommandWrapperImplTest.java

index 4e5683d2e1b2e72cdc184b6de759b1e9786562da..8a28dcfb4306d88580f8795f35c6c3812abf8359 100644 (file)
@@ -359,29 +359,10 @@ public class Monitor {
         if (processCommands.askedForStop()) {
           return true;
         }
-      } catch (IllegalArgumentException e) {
-        // DefaultProcessCommand currently wraps IOException into a IllegalArgumentException
-        // accessing the shared memory file may fail if a restart is in progress and the temp directory
-        // is currently deleted and not yet recreated
-        if (e.getCause() instanceof IOException) {
-          ignore((IOException) e.getCause());
-        } else {
-          rethrow(e);
-        }
-      } catch (Exception e) {
-        rethrow(e);
       }
       return false;
     }
 
-    private void ignore(IOException e) {
-      trace("HardStopWatcherThread: Error checking stop flag in shared memory. Ignoring. Keep on watching.", e);
-    }
-
-    private void rethrow(Exception e) {
-      throw new RuntimeException("Unexpected error occurred while watch for stop flag in shared memory", e);
-    }
-
     private void delay() {
       try {
         Thread.sleep(WATCH_DELAY_MS);
index 512cd788bab4b5e996e2f5375de2d7cb9c7caa4b..d22a6ba10509ce687a69d00f484ad239d97c1c0e 100644 (file)
@@ -269,7 +269,7 @@ public class AllProcessesCommands {
     }
 
     @Override
-    public void close() throws Exception {
+    public void close() {
       endWatch();
     }
   }
index a617ea4580b2e7b12a7b94a349339054561017bc..04a608fef06fbf74cbf8a8a86214f4bb2755de9c 100644 (file)
@@ -117,7 +117,7 @@ public class DefaultProcessCommands implements ProcessCommands {
   }
 
   @Override
-  public void close() throws Exception {
+  public void close() {
     allProcessesCommands.close();
   }
 }
index 1057ad5415804a6230b1e9d9689069814c851124..482029b81d8b30c831d49077bd8ee0b2ae05fa4f 100644 (file)
@@ -28,7 +28,8 @@ import java.io.File;
  *   <li>stop/restart a specific processes</li>
  * </ul>
  *
- * @see DefaultProcessCommands#DefaultProcessCommands(File, int)
+ * @see DefaultProcessCommands#main(File, int)
+ * @see DefaultProcessCommands#secondary(File, int)
  */
 public interface ProcessCommands extends AutoCloseable {
 
index 3278c80ad5e88da9e1fe0fe53f2bfd864a3c475b..9936a9f7e93c82865966b8044441d5db108e7b33 100644 (file)
@@ -21,8 +21,6 @@ package org.sonar.server.app;
 
 import java.io.File;
 import org.sonar.api.config.Settings;
-import org.sonar.api.utils.log.Logger;
-import org.sonar.api.utils.log.Loggers;
 import org.sonar.process.DefaultProcessCommands;
 import org.sonar.process.ProcessCommands;
 
@@ -31,8 +29,6 @@ import static org.sonar.process.ProcessEntryPoint.PROPERTY_PROCESS_INDEX;
 import static org.sonar.process.ProcessEntryPoint.PROPERTY_SHARED_PATH;
 
 public class ProcessCommandWrapperImpl implements ProcessCommandWrapper {
-  private static final Logger LOG = Loggers.get(ProcessCommandWrapperImpl.class);
-
   private final Settings settings;
 
   public ProcessCommandWrapperImpl(Settings settings) {
@@ -52,10 +48,8 @@ public class ProcessCommandWrapperImpl implements ProcessCommandWrapper {
   private void call(VoidMethod command) {
     File shareDir = nonNullValueAsFile(PROPERTY_SHARED_PATH);
     int processNumber = nonNullAsInt(PROPERTY_PROCESS_INDEX);
-    try (ProcessCommands commands = DefaultProcessCommands.secondary(shareDir, processNumber)) {
+    try (DefaultProcessCommands commands = DefaultProcessCommands.secondary(shareDir, processNumber)) {
       command.callOn(commands);
-    } catch (Exception e) {
-      LOG.warn("Failed to close ProcessCommands", e);
     }
   }
 
index 40d6774dd318c5839b3ed2c942efe2e2700375e8..8a394785681d305b7ef4ef32cf3c674c32f9c472 100644 (file)
@@ -20,6 +20,7 @@
 package org.sonar.server.app;
 
 import java.io.File;
+import java.io.IOException;
 import org.junit.Rule;
 import org.junit.Test;
 import org.junit.rules.ExpectedException;
@@ -63,7 +64,7 @@ public class ProcessCommandWrapperImplTest {
   }
 
   @Test
-  public void requestSQRestart_updates_shareMemory_file() throws Exception {
+  public void requestSQRestart_updates_shareMemory_file() throws IOException {
     File tmpDir = temp.newFolder().getAbsoluteFile();
     settings.setProperty(PROPERTY_SHARED_PATH, tmpDir.getAbsolutePath());
     settings.setProperty(PROPERTY_PROCESS_INDEX, PROCESS_NUMBER);
@@ -98,7 +99,7 @@ public class ProcessCommandWrapperImplTest {
   }
 
   @Test
-  public void notifyOperational_updates_shareMemory_file() throws Exception {
+  public void notifyOperational_updates_shareMemory_file() throws IOException {
     File tmpDir = temp.newFolder().getAbsoluteFile();
     settings.setProperty(PROPERTY_SHARED_PATH, tmpDir.getAbsolutePath());
     settings.setProperty(PROPERTY_PROCESS_INDEX, PROCESS_NUMBER);