This is an automated email from the ASF dual-hosted git repository.

dongjoon pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/spark-kubernetes-operator.git


The following commit(s) were added to refs/heads/main by this push:
     new 137824a  [SPARK-49157] Enforce `SignatureDeclareThrowsException` and 
`AvoidThrowingRawExceptionTypes` rules
137824a is described below

commit 137824aad13c59cdb4ae2cbb954b3c0112028da9
Author: William Hyun <[email protected]>
AuthorDate: Thu Aug 8 00:11:51 2024 -0700

    [SPARK-49157] Enforce `SignatureDeclareThrowsException` and 
`AvoidThrowingRawExceptionTypes` rules
    
    ### What changes were proposed in this pull request?
    This PR aims to enforce `SignatureDeclareThrowsException` and 
`AvoidThrowingRawExceptionTypes` rules
    
    ### Why are the changes needed?
    To ensure future code quality.
    
    ### Does this PR introduce _any_ user-facing change?
    No.
    
    ### How was this patch tested?
    Pass the CIs.
    
    ### Was this patch authored or co-authored using generative AI tooling?
    No.
    
    Closes #38 from williamhyun/exception.
    
    Authored-by: William Hyun <[email protected]>
    Signed-off-by: Dongjoon Hyun <[email protected]>
---
 config/pmd/ruleset.xml                                              | 2 --
 .../org/apache/spark/k8s/operator/status/ApplicationStatus.java     | 2 +-
 .../main/java/org/apache/spark/k8s/operator/utils/ModelUtils.java   | 2 +-
 .../java/org/apache/spark/k8s/operator/metrics/MetricsService.java  | 2 +-
 .../java/org/apache/spark/k8s/operator/metrics/MetricsSystem.java   | 2 +-
 .../org/apache/spark/k8s/operator/metrics/MetricsSystemFactory.java | 4 ++--
 .../main/java/org/apache/spark/k8s/operator/probe/ProbeService.java | 2 +-
 .../spark/k8s/operator/reconciler/SparkAppResourceSpecFactory.java  | 2 +-
 .../java/org/apache/spark/k8s/operator/probe/ProbeServiceTest.java  | 6 ++++--
 .../test/java/org/apache/spark/k8s/operator/utils/TestUtils.java    | 2 +-
 10 files changed, 13 insertions(+), 13 deletions(-)

diff --git a/config/pmd/ruleset.xml b/config/pmd/ruleset.xml
index 515783e..f4a6c25 100644
--- a/config/pmd/ruleset.xml
+++ b/config/pmd/ruleset.xml
@@ -45,14 +45,12 @@
   <rule ref="category/java/design.xml">
     <exclude name="AbstractClassWithoutAnyMethod" />
     <exclude name="AvoidCatchingGenericException" />
-    <exclude name="AvoidThrowingRawExceptionTypes" />
     <exclude name="ClassWithOnlyPrivateConstructorsShouldBeFinal" />
     <exclude name="CognitiveComplexity" />
     <exclude name="CyclomaticComplexity" />
     <exclude name="ExcessiveImports" />
     <exclude name="LawOfDemeter" />
     <exclude name="NPathComplexity" />
-    <exclude name="SignatureDeclareThrowsException" />
     <exclude name="TooManyMethods" />
     <exclude name="UseUtilityClass" />
   </rule>
diff --git 
a/spark-operator-api/src/main/java/org/apache/spark/k8s/operator/status/ApplicationStatus.java
 
b/spark-operator-api/src/main/java/org/apache/spark/k8s/operator/status/ApplicationStatus.java
index ae7ea89..76f5ad3 100644
--- 
a/spark-operator-api/src/main/java/org/apache/spark/k8s/operator/status/ApplicationStatus.java
+++ 
b/spark-operator-api/src/main/java/org/apache/spark/k8s/operator/status/ApplicationStatus.java
@@ -83,7 +83,7 @@ public class ApplicationStatus
       boolean trimStateTransitionHistory) {
     if (!currentState.currentStateSummary.isStopping()) {
       // application is not stopping, skip
-      throw new RuntimeException(
+      throw new IllegalStateException(
           "Spark application cannot be directly terminated unless in stopping "
               + "state, current state is: "
               + currentState);
diff --git 
a/spark-operator-api/src/main/java/org/apache/spark/k8s/operator/utils/ModelUtils.java
 
b/spark-operator-api/src/main/java/org/apache/spark/k8s/operator/utils/ModelUtils.java
index 03d84be..7106a2c 100644
--- 
a/spark-operator-api/src/main/java/org/apache/spark/k8s/operator/utils/ModelUtils.java
+++ 
b/spark-operator-api/src/main/java/org/apache/spark/k8s/operator/utils/ModelUtils.java
@@ -93,7 +93,7 @@ public class ModelUtils {
     try {
       return objectMapper.writeValueAsString(resource);
     } catch (JsonProcessingException e) {
-      throw new RuntimeException(e);
+      throw new IllegalStateException(e);
     }
   }
 
diff --git 
a/spark-operator/src/main/java/org/apache/spark/k8s/operator/metrics/MetricsService.java
 
b/spark-operator/src/main/java/org/apache/spark/k8s/operator/metrics/MetricsService.java
index 2c6b3b8..c97818e 100644
--- 
a/spark-operator/src/main/java/org/apache/spark/k8s/operator/metrics/MetricsService.java
+++ 
b/spark-operator/src/main/java/org/apache/spark/k8s/operator/metrics/MetricsService.java
@@ -39,7 +39,7 @@ public class MetricsService {
     try {
       server = HttpServer.create(new 
InetSocketAddress(OPERATOR_METRICS_PORT.getValue()), 0);
     } catch (IOException e) {
-      throw new RuntimeException("Failed to create Metrics Server", e);
+      throw new IllegalStateException("Failed to create Metrics Server", e);
     }
     server.setExecutor(executor);
   }
diff --git 
a/spark-operator/src/main/java/org/apache/spark/k8s/operator/metrics/MetricsSystem.java
 
b/spark-operator/src/main/java/org/apache/spark/k8s/operator/metrics/MetricsSystem.java
index 5dcd61b..4194144 100644
--- 
a/spark-operator/src/main/java/org/apache/spark/k8s/operator/metrics/MetricsSystem.java
+++ 
b/spark-operator/src/main/java/org/apache/spark/k8s/operator/metrics/MetricsSystem.java
@@ -118,7 +118,7 @@ public class MetricsSystem {
                       sinkProp.getClassName(),
                       sinkProp.getProperties());
                 }
-                throw new RuntimeException("Fail to create metrics sink", e);
+                throw new IllegalStateException("Fail to create metrics sink", 
e);
               }
             });
   }
diff --git 
a/spark-operator/src/main/java/org/apache/spark/k8s/operator/metrics/MetricsSystemFactory.java
 
b/spark-operator/src/main/java/org/apache/spark/k8s/operator/metrics/MetricsSystemFactory.java
index 88d357c..35427ce 100644
--- 
a/spark-operator/src/main/java/org/apache/spark/k8s/operator/metrics/MetricsSystemFactory.java
+++ 
b/spark-operator/src/main/java/org/apache/spark/k8s/operator/metrics/MetricsSystemFactory.java
@@ -91,13 +91,13 @@ public class MetricsSystemFactory {
         String errorMessage =
             String.format(
                 "%s provides properties, but does not provide full class 
name", pair.getKey());
-        throw new RuntimeException(errorMessage);
+        throw new IllegalStateException(errorMessage);
       }
       // Check the existence of each class full name
       try {
         Class.forName(pair.getValue().getClassName());
       } catch (ClassNotFoundException e) {
-        throw new RuntimeException(
+        throw new IllegalStateException(
             String.format("Fail to find class %s", 
pair.getValue().getClassName()), e);
       }
     }
diff --git 
a/spark-operator/src/main/java/org/apache/spark/k8s/operator/probe/ProbeService.java
 
b/spark-operator/src/main/java/org/apache/spark/k8s/operator/probe/ProbeService.java
index 48159f5..1ab82aa 100644
--- 
a/spark-operator/src/main/java/org/apache/spark/k8s/operator/probe/ProbeService.java
+++ 
b/spark-operator/src/main/java/org/apache/spark/k8s/operator/probe/ProbeService.java
@@ -45,7 +45,7 @@ public class ProbeService {
     try {
       this.server = HttpServer.create(new 
InetSocketAddress(OPERATOR_PROBE_PORT.getValue()), 0);
     } catch (IOException e) {
-      throw new RuntimeException("Failed to create Probe Service Server", e);
+      throw new IllegalStateException("Failed to create Probe Service Server", 
e);
     }
     server.createContext(READYZ, new ReadinessProbe(operators));
     server.createContext(HEALTHZ, healthProbe);
diff --git 
a/spark-operator/src/main/java/org/apache/spark/k8s/operator/reconciler/SparkAppResourceSpecFactory.java
 
b/spark-operator/src/main/java/org/apache/spark/k8s/operator/reconciler/SparkAppResourceSpecFactory.java
index 59c7883..1ac27ae 100644
--- 
a/spark-operator/src/main/java/org/apache/spark/k8s/operator/reconciler/SparkAppResourceSpecFactory.java
+++ 
b/spark-operator/src/main/java/org/apache/spark/k8s/operator/reconciler/SparkAppResourceSpecFactory.java
@@ -169,7 +169,7 @@ public class SparkAppResourceSpecFactory {
       }
       return path;
     } catch (IOException e) {
-      throw new RuntimeException(e);
+      throw new IllegalStateException(e);
     }
   }
 }
diff --git 
a/spark-operator/src/test/java/org/apache/spark/k8s/operator/probe/ProbeServiceTest.java
 
b/spark-operator/src/test/java/org/apache/spark/k8s/operator/probe/ProbeServiceTest.java
index a5fa45c..aeb3aa0 100644
--- 
a/spark-operator/src/test/java/org/apache/spark/k8s/operator/probe/ProbeServiceTest.java
+++ 
b/spark-operator/src/test/java/org/apache/spark/k8s/operator/probe/ProbeServiceTest.java
@@ -26,7 +26,9 @@ import static org.junit.jupiter.api.Assertions.assertEquals;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.when;
 
+import java.io.IOException;
 import java.net.HttpURLConnection;
+import java.net.MalformedURLException;
 import java.net.URL;
 import java.util.Collections;
 import java.util.HashMap;
@@ -114,7 +116,7 @@ class ProbeServiceTest {
     probeService.stop();
   }
 
-  private void hitHealthyEndpoint() throws Exception {
+  private void hitHealthyEndpoint() throws IOException, MalformedURLException {
     URL u = new URL("http://localhost:"; + OPERATOR_PROBE_PORT.getValue() + 
HEALTHZ);
     HttpURLConnection connection = (HttpURLConnection) u.openConnection();
     connection.setConnectTimeout(100000);
@@ -122,7 +124,7 @@ class ProbeServiceTest {
     assertEquals(connection.getResponseCode(), 200, "Health Probe should 
return 200");
   }
 
-  private void hitStartedUpEndpoint() throws Exception {
+  private void hitStartedUpEndpoint() throws IOException, 
MalformedURLException {
     URL u = new URL("http://localhost:"; + OPERATOR_PROBE_PORT.getValue() + 
READYZ);
     HttpURLConnection connection = (HttpURLConnection) u.openConnection();
     connection.setConnectTimeout(100000);
diff --git 
a/spark-operator/src/test/java/org/apache/spark/k8s/operator/utils/TestUtils.java
 
b/spark-operator/src/test/java/org/apache/spark/k8s/operator/utils/TestUtils.java
index 1603cfa..6320263 100644
--- 
a/spark-operator/src/test/java/org/apache/spark/k8s/operator/utils/TestUtils.java
+++ 
b/spark-operator/src/test/java/org/apache/spark/k8s/operator/utils/TestUtils.java
@@ -50,7 +50,7 @@ public class TestUtils {
   public static void cleanPropertiesFile(String filePath) {
     File myObj = new File(filePath);
     if (!myObj.delete()) {
-      throw new RuntimeException("Failed to clean properties file: " + 
filePath);
+      throw new IllegalStateException("Failed to clean properties file: " + 
filePath);
     }
   }
 


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to