renechoi opened a new pull request, #4973: URL: https://github.com/apache/zeppelin/pull/4973
# [MINOR] Handle Collection as defaultValue in GUI.select() ## What is this PR for? This PR improves the `GUI.select()` method to properly handle Collection objects passed as defaultValue. When a Collection is provided, the method now extracts the first element as the actual default value instead of using the Collection object itself. ## What type of PR is it? Improvement ## What is the Jira issue? N/A (Minor improvement) ## How should this be tested? 1. Run the test: `./mvnw test -pl zeppelin-interpreter -Dtest=GUITest` 2. Verify that the new test `testSelectWithCollectionDefault()` passes 3. The test verifies that: - When a Collection containing `["2"]` is passed as defaultValue - The select form uses `"2"` as the default value (not the Collection object) ## Questions: * Does the license files need update? No * Is there breaking changes for older versions? No * Does this needs documentation? No ## Description ### Problem Currently, when using `GUI.select()` with a Collection as the defaultValue parameter, the entire Collection object is used as the default value. This can cause issues since the select form expects a single value, not a Collection. ### Solution Added logic to check if the defaultValue is a Collection (but not a String, since String implements CharSequence which is a Collection-like interface). If it is: - Extract the first element from the Collection - Use that element as the actual default value - If the Collection is empty, use null ### Code Changes ```java // Added to GUI.select() method if (defaultValue instanceof Collection && !(defaultValue instanceof String)) { Collection<?> values = (Collection<?>) defaultValue; defaultValue = values.isEmpty() ? null : values.iterator().next(); } ``` ### Test Coverage Added `testSelectWithCollectionDefault()` test that verifies: - A Collection containing `"2"` is properly converted to default value `"2"` - The form's default value is correctly set to `"2"` - The selected value matches the expected default This change improves the API's flexibility and prevents potential issues when Collections are inadvertently passed as default values. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: reviews-unsubscr...@zeppelin.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org