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

dongjoon-hyun 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 5a41dd21 [SPARK-59879] Close PrintWriter with try-with-resources in 
ConfOptionDocGenerator
5a41dd21 is described below

commit 5a41dd2134be038e4bcd86f6558407ada3569cf2
Author: Zhou JIANG <[email protected]>
AuthorDate: Thu Oct 1 08:32:30 2026 -0700

    [SPARK-59879] Close PrintWriter with try-with-resources in 
ConfOptionDocGenerator
    
    ### What changes were proposed in this pull request?
    
    Wrap the `PrintWriter` used in `ConfOptionDocGenerator.generate()` in a 
try-with-resources statement instead of a manual `close()` call.
    
    ### Why are the changes needed?
    
    The writer was not guaranteed to be closed if an exception occurred while 
writing the docs table, risking a resource leak.
    
    ### How was this patch tested?
    
    Pass the CIs .
    
    Manually checked `build-tools-docs-utils:validateConfPropsDocUpToDate` 
works as expected.
    
    ### Does this PR introduce _any_ user-facing change?
    
    No
    
    ### Was this patch authored or co-authored using generative AI tooling?
    
    Generated-by: Claude Code (claude-sonnet-5)
    
    Closes #912 from jiangzho/fixnpe.
    
    Authored-by: Zhou JIANG <[email protected]>
    Signed-off-by: Dongjoon Hyun <[email protected]>
---
 .../k8s/operator/utils/ConfOptionDocGenerator.java | 43 +++++++++++-----------
 1 file changed, 22 insertions(+), 21 deletions(-)

diff --git 
a/build-tools/docs-utils/src/main/java/org/apache/spark/k8s/operator/utils/ConfOptionDocGenerator.java
 
b/build-tools/docs-utils/src/main/java/org/apache/spark/k8s/operator/utils/ConfOptionDocGenerator.java
index c4464749..b4bd559f 100644
--- 
a/build-tools/docs-utils/src/main/java/org/apache/spark/k8s/operator/utils/ConfOptionDocGenerator.java
+++ 
b/build-tools/docs-utils/src/main/java/org/apache/spark/k8s/operator/utils/ConfOptionDocGenerator.java
@@ -49,29 +49,30 @@ public class ConfOptionDocGenerator {
     if (generated.createNewFile()) {
       log.info("Creating props at {}/{}", docsPath, CONF_FILE_NAME);
     }
-    PrintWriter printWriter = new PrintWriter(generated, 
StandardCharsets.UTF_8);
-    printWriter.println(String.format("[//]: # (%s)", GENERATED_FILE_HEADER));
-    printWriter.println("# Spark Operator Config Properties");
-    DocTable table =
-        DocTable.builder()
-            .headers(List.of("Key", "Type", "Default Value", "Allow Hot 
Reloading", "Description"))
-            .columns(5)
-            .build();
-    for (Field f : fields) {
-      if (ConfigOption.class.isAssignableFrom(f.getType())) {
-        ConfigOption<?> conf = (ConfigOption<?>) f.get(this);
-        table.addRow(
-            List.of(
-                conf.getKey(),
-                conf.getTypeParameterClass().getSimpleName(),
-                conf.getDefaultValue().toString(),
-                String.valueOf(conf.isEnableDynamicOverride()),
-                conf.getDescription()));
+    try (PrintWriter printWriter = new PrintWriter(generated, 
StandardCharsets.UTF_8)) {
+      printWriter.println(String.format("[//]: # (%s)", 
GENERATED_FILE_HEADER));
+      printWriter.println("# Spark Operator Config Properties");
+      DocTable table =
+          DocTable.builder()
+              .headers(
+                  List.of("Key", "Type", "Default Value", "Allow Hot 
Reloading", "Description"))
+              .columns(5)
+              .build();
+      for (Field f : fields) {
+        if (ConfigOption.class.isAssignableFrom(f.getType())) {
+          ConfigOption<?> conf = (ConfigOption<?>) f.get(this);
+          table.addRow(
+              List.of(
+                  conf.getKey(),
+                  conf.getTypeParameterClass().getSimpleName(),
+                  conf.getDefaultValue().toString(),
+                  String.valueOf(conf.isEnableDynamicOverride()),
+                  conf.getDescription()));
+        }
       }
+      table.sort();
+      table.flush(printWriter);
     }
-    table.sort();
-    table.flush(printWriter);
-    printWriter.close();
   }
 
   public static void main(String[] args) throws IOException, 
IllegalAccessException {


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

Reply via email to