Uh oh!
There was an error while loading. Please reload this page.
[ZEPPELIN-6309] Improve method by replacing JsonObject parameter - #5063
Conversation
There was a problem hiding this comment.
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 |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
| 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; |
There was a problem hiding this comment.
[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 = newArrayList<>(); | |
| if (jsonObject != null) { | |
| JsonObjectoption = jsonObject.getAsJsonObject("option"); | |
| if (option != null) { | |
| JsonArrayusers = option.getAsJsonArray("users"); | |
| if (users != null) { | |
| if (this.option.getOwners() == null) { | |
| this.option.owners = newLinkedList<>(); | |
| } | |
| for (JsonElementuser : users) { | |
| this.option.getOwners().add(user.getAsString()); | |
| JsonArrayusersArray = option.getAsJsonArray("users"); | |
| if (usersArray != null) { | |
| for (JsonElementuserElement : usersArray) { | |
| users.add(userElement.getAsString()); | |
| } | |
| } | |
| } | |
| } | |
| returnusers; | |
| List<String> users = null; | |
| if (jsonObject != null) { | |
| JsonObjectoption = jsonObject.getAsJsonObject("option"); | |
| if (option != null) { | |
| JsonArrayusersArray = option.getAsJsonArray("users"); | |
| if (usersArray != null) { | |
| users = newArrayList<>(usersArray.size()); | |
| for (JsonElementuserElement : usersArray) { | |
| users.add(userElement.getAsString()); | |
| } | |
| } | |
| } | |
| } | |
| returnusers == null ? newArrayList<>() : users; |
There was a problem hiding this comment.
Good catch! Updated to use LinkedList for consistency with the rest of the class. This maintains consistency with the owners field initialization on line.
Uh oh!
There was an error while loading. Please reload this page.
…figStorage.java Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
| interpreterSetting.convertPermissionsFromUsersToOwners( | ||
| jsonObject.getAsJsonObject("interpreterSettings") | ||
| .getAsJsonObject(interpreterSetting.getId())); | ||
| JsonObject interpreterSettingJson = jsonObject.getAsJsonObject("interpreterSettings") |
There was a problem hiding this comment.
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);
There was a problem hiding this comment.
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.
Uh oh!
There was an error while loading. Please reload this page.
### 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](https://issues.apache.org/jira/browse/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 Closes#5063 from celinayk/ZEPPELIN-6309. Signed-off-by: ParkGyeongTae <gyeongtae@apache.org> (cherry picked from commit 75a9caa) Signed-off-by: ParkGyeongTae <gyeongtae@apache.org>
ParkGyeongTae
commented
Sep 15, 2025
Merged into |
…ers.json ### What is this PR for? Tests in the `zeppelin-zengine` module were failing. The main reason was that the `interpreter.json` in test resources were invalid: the value object did not have an `id` field matching its corresponding key. As a result, the deserialized `InterpreterSetting` instance had an auto-genarated `id` field, causing the key and value.id to be inconsistent. Before #5063, invalid settings were simply skipped. However, after that change, they caused a NPE. This PR fixes the invalid JSON files and adds minor validation logic in the deserialization method so that such issues can be detected early by users. ### What type of PR is it? Bug Fix ### What is the Jira issue? https://issues.apache.org/jira/browse/ZEPPELIN-6335 ### How should this be tested? * Check `core-modules` - `zeppelin-zengine` tests in CI ### Questions: * Does the license files need to update? No * Is there breaking changes for older versions? No * Does this needs documentation? No Closes#5081 from tbonelee/fix-test-resource. Signed-off-by: ChanHo Lee <chanholee@apache.org>
…ers.json ### What is this PR for? Tests in the `zeppelin-zengine` module were failing. The main reason was that the `interpreter.json` in test resources were invalid: the value object did not have an `id` field matching its corresponding key. As a result, the deserialized `InterpreterSetting` instance had an auto-genarated `id` field, causing the key and value.id to be inconsistent. Before #5063, invalid settings were simply skipped. However, after that change, they caused a NPE. This PR fixes the invalid JSON files and adds minor validation logic in the deserialization method so that such issues can be detected early by users. ### What type of PR is it? Bug Fix ### What is the Jira issue? https://issues.apache.org/jira/browse/ZEPPELIN-6335 ### How should this be tested? * Check `core-modules` - `zeppelin-zengine` tests in CI ### Questions: * Does the license files need to update? No * Is there breaking changes for older versions? No * Does this needs documentation? No Closes#5081 from tbonelee/fix-test-resource. Signed-off-by: ChanHo Lee <chanholee@apache.org> (cherry picked from commit 80ff51c) Signed-off-by: ChanHo Lee <chanholee@apache.org>
What is this PR for?
Refactored the
convertPermissionsFromUsersToOwnersmethod 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
What is the Jira issue?
ZEPPELIN-6309
How should this be tested?
Screenshots (if appropriate)
Questions: