← Back to Pull requests

[ZEPPELIN-6309] Improve method by replacing JsonObject parameter #5063

Merged
celinayk merged 3 files (58 lines) on Sep 15, 2025 04:05 UTC
View on GitHub
celinayk celinayk commented on Aug 31, 2025 13:29 UTC
Author

What is this PR for?


Refactored the convertPermissionsFromUsersToOwners method in InterpreterSetting.java to improve code readability and maintainability by separating JSON parsing logic from business logic, addressing the TODO comment that identified this as "ugly code".

What type of PR is it?


Refactoring

Todos


[x] - Refactor convertPermissionsFromUsersToOwners method to remove JsonObject parameter
[x] - Extract JSON parsing logic into separate static helper method
[x] - Update all callers to use new method signature

What is the Jira issue?


ZEPPELIN-6309

How should this be tested?

Screenshots (if appropriate)

Questions:


Does the license files need to update? No
Is there breaking changes for older versions? No
Does this needs documentation? No

Diff: 58 lines (+37 / -21) across 3 files Reviewer: ParkGyeongTae Review duration: 21035m
All Vouch review confidence checks passed
Residual risk 0.05 = Change Risk (0.30) × (1 − Review Confidence (0.83)). Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.30 · 58 lines diff across 3 files
0.30
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.83 · 5 substantive comment(s)
0.83
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 50%
83%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size diff_size
0.244
Real PR Conversation Timeline
9 items
Copilot Copilot commented on code on Sep 01, 2025 12:57 UTC
Code Review
zeppelin-zengine/src/main/java/org/apache/zeppelin/interpreter/InterpreterSetting.java:1
@@ -1016,22 +1016,29 @@ public void run() {
     t.start();
   }
 
-  //TODO(zjffdu) ugly code, should not use JsonObject as parameter. not readable
-  public void convertPermissionsFromUsersToOwners(JsonObject jsonObject) {
+  public void convertPermissionsFromUsersToOwners(List<String> users) {
+    if (users != null && !users.isEmpty()) {
+      if (this.option.getOwners() == null) {
+        this.option.owners = new LinkedList<>();
+      }
+      this.option.getOwners().addAll(users);
+    }
+  }
+
+  public static List<String> extractUsersFromJsonObject(JsonObject jsonObject) {
+    List<String> users = new ArrayList<>();
     if (jsonObject != null) {
       JsonObject option = jsonObject.getAsJsonObject("option");
       if (option != null) {
-        JsonArray users = option.getAsJsonArray("users");
-        if (users != null) {
-          if (this.option.getOwners() == null) {
-            this.option.owners = new LinkedList<>();
-          }
-          for (JsonElement user : users) {
-            this.option.getOwners().add(user.getAsString());
+        JsonArray usersArray = option.getAsJsonArray("users");
+        if (usersArray != null) {
+          for (JsonElement userElement : usersArray) {
+            users.add(userElement.getAsString());
           }
         }
       }
     }
+    return users;

[nitpick] Consider using ArrayList constructor with initial capacity or LinkedList to match the pattern used in the convertPermissionsFromUsersToOwners method where LinkedList is used for owners.

    List<String> users = null;
    if (jsonObject != null) {
      JsonObject option = jsonObject.getAsJsonObject("option");
      if (option != null) {
        JsonArray usersArray = option.getAsJsonArray("users");
        if (usersArray != null) {
          users = new ArrayList<>(usersArray.size());
          for (JsonElement userElement : usersArray) {
            users.add(userElement.getAsString());
          }
        }
      }
    }
    return users == null ? new ArrayList<>() : users;

Copilot Copilot commented on code on Sep 01, 2025 12:57 UTC
Code Review
zeppelin-zengine/src/main/java/org/apache/zeppelin/storage/ConfigStorage.java:1
@@ -27,6 +27,7 @@
 import org.apache.zeppelin.util.ReflectionUtils;
 
 import java.io.IOException;
+import java.util.List;
 

[nitpick] The import statement should be placed in alphabetical order with other java.util imports to maintain consistent import organization.


import java.util.List;

copilot-pull-request-reviewer[bot] copilot-pull-request-reviewer[bot] commented on Sep 01, 2025 12:57 UTC
Reviewer

Pull Request Overview

This PR refactors the convertPermissionsFromUsersToOwners method in InterpreterSetting.java by removing the JsonObject parameter and separating JSON parsing logic from business logic, addressing a TODO comment about "ugly code".

  • Extracted JSON parsing into a new static helper method extractUsersFromJsonObject

  • Simplified the main method to accept a List<String> instead of JsonObject

  • Updated all callers to use the new method signature with proper JSON parsing
  • Reviewed Changes

    Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

    | File | Description |
    | ---- | ----------- |
    | InterpreterSetting.java | Refactored main method and added new static helper method for JSON parsing |
    | ConfigStorage.java | Updated caller to use new method signature with extracted users list |
    | InterpreterInfoSaving.java | Updated caller to use new method signature with extracted users list |

    ---

    <sub>Tip: Customize your code reviews with copilot-instructions.md. <a href="/apache/zeppelin/new/master/.github?filename=copilot-instructions.md" class="Link--inTextBlock" target="_blank" rel="noopener noreferrer">Create the file</a> or <a href="https://docs.github.com/en/copilot/customizing-copilot/adding-repository-custom-instructions-for-github-copilot" class="Link--inTextBlock" target="_blank" rel="noopener noreferrer">learn how to get started</a>.</sub>

    celinayk celinayk commented on code on Sep 02, 2025 09:49 UTC
    Code Review
    zeppelin-zengine/src/main/java/org/apache/zeppelin/interpreter/InterpreterSetting.java:1
    @@ -1016,22 +1016,29 @@ public void run() {
         t.start();
       }
     
    -  //TODO(zjffdu) ugly code, should not use JsonObject as parameter. not readable
    -  public void convertPermissionsFromUsersToOwners(JsonObject jsonObject) {
    +  public void convertPermissionsFromUsersToOwners(List<String> users) {
    +    if (users != null && !users.isEmpty()) {
    +      if (this.option.getOwners() == null) {
    +        this.option.owners = new LinkedList<>();
    +      }
    +      this.option.getOwners().addAll(users);
    +    }
    +  }
    +
    +  public static List<String> extractUsersFromJsonObject(JsonObject jsonObject) {
    +    List<String> users = new ArrayList<>();
         if (jsonObject != null) {
           JsonObject option = jsonObject.getAsJsonObject("option");
           if (option != null) {
    -        JsonArray users = option.getAsJsonArray("users");
    -        if (users != null) {
    -          if (this.option.getOwners() == null) {
    -            this.option.owners = new LinkedList<>();
    -          }
    -          for (JsonElement user : users) {
    -            this.option.getOwners().add(user.getAsString());
    +        JsonArray usersArray = option.getAsJsonArray("users");
    +        if (usersArray != null) {
    +          for (JsonElement userElement : usersArray) {
    +            users.add(userElement.getAsString());
               }
             }
           }
         }
    +    return users;

    Good catch! Updated to use LinkedList for consistency with the rest of the class. This maintains consistency with the owners field initialization on line.

    Reamer Reamer commented on code on Sep 03, 2025 10:05 UTC
    Code Review
    zeppelin-zengine/src/main/java/org/apache/zeppelin/interpreter/InterpreterInfoSaving.java:1
    @@ -62,9 +62,10 @@ public static InterpreterInfoSaving loadFromFile(Path file) throws IOException {
     
           if (infoSaving != null && infoSaving.interpreterSettings != null) {
             for (InterpreterSetting interpreterSetting : infoSaving.interpreterSettings.values()) {
    -          interpreterSetting.convertPermissionsFromUsersToOwners(
    -                  jsonObject.getAsJsonObject("interpreterSettings")
    -                          .getAsJsonObject(interpreterSetting.getId()));
    +          JsonObject interpreterSettingJson = jsonObject.getAsJsonObject("interpreterSettings")

    Are you sure this is what is meant by “ugly” here?
    I think we should use GSON here to create objects directly.

    GSON.fromJson(json, myFanceClass.class);
    

    celinayk celinayk commented on code on Sep 04, 2025 11:35 UTC
    Code Review
    zeppelin-zengine/src/main/java/org/apache/zeppelin/interpreter/InterpreterInfoSaving.java:1
    @@ -62,9 +62,10 @@ public static InterpreterInfoSaving loadFromFile(Path file) throws IOException {
     
           if (infoSaving != null && infoSaving.interpreterSettings != null) {
             for (InterpreterSetting interpreterSetting : infoSaving.interpreterSettings.values()) {
    -          interpreterSetting.convertPermissionsFromUsersToOwners(
    -                  jsonObject.getAsJsonObject("interpreterSettings")
    -                          .getAsJsonObject(interpreterSetting.getId()));
    +          JsonObject interpreterSettingJson = jsonObject.getAsJsonObject("interpreterSettings")

    Are you sure this is what is meant by “ugly” here? I think we should use GSON here to create objects directly.

    >
    > GSON.fromJson(json, myFanceClass.class);
    > 

    Thank you for the feedback! You're absolutely right. I've refactored the code to use GSON.fromJson() directly
    instead of JsonObject parameter.

    ParkGyeongTae ParkGyeongTae approved these changes on Sep 07, 2025 10:54 UTC
    Approved Reviewer

    LGTM 👍

    ParkGyeongTae ParkGyeongTae commented on Sep 15, 2025 04:05 UTC
    Contributor

    Merged into master and branch-0.12

    Reviewers
    Assignees
    celinayk celinayk
    Labels
    risk: low confidence: 83.3% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 30.3% (LOW) · Higher = larger blast radius
    30.3%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 83.3% · Lower = rushed or shallow review
    83.3%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 5.1% · Safe to merge
    5.1%