You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@zeppelin.apache.org by "ParkGyeongTae (via GitHub)" <gi...@apache.org> on 2025/07/27 12:28:13 UTC
[PR] [ZEPPELIN-6262] Refactor ElasticsearchClientTypeBuilder for safer enum handling and blank input support [zeppelin]
ParkGyeongTae opened a new pull request, #5002:
URL: https://github.com/apache/zeppelin/pull/5002
### What is this PR for?
This PR refactors the ElasticsearchClientTypeBuilder class to improve its robustness and readability:
- Replaces StringUtils.isEmpty() with StringUtils.isBlank() to treat whitespace-only strings as invalid input
- Simplifies enum parsing by removing redundant checks and using a try-catch block around Enum.valueOf(...)
- Ensures that invalid or null inputs gracefully fall back to ElasticsearchClientType.UNKNOWN
### What type of PR is it?
Refactoring
### Todos
* [x] - Verify existing tests
### What is the Jira issue?
* Jira: https://issues.apache.org/jira/browse/ZEPPELIN-6262
### How should this be tested?
N/A
### Screenshots (if appropriate)
N/A
### Questions:
* Does the license files need to update? No.
* Is there breaking changes for older versions? No.
* Does this needs documentation? No.
--
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-unsubscribe@zeppelin.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [ZEPPELIN-6262] Refactor ElasticsearchClientTypeBuilder for safer enum handling and blank input support [zeppelin]
Posted by "ParkGyeongTae (via GitHub)" <gi...@apache.org>.
ParkGyeongTae commented on code in PR #5002:
URL: https://github.com/apache/zeppelin/pull/5002#discussion_r2237986023
##########
elasticsearch/src/main/java/org/apache/zeppelin/elasticsearch/client/ElasticsearchClientTypeBuilder.java:
##########
@@ -47,18 +43,18 @@ private Builder(String propertyValue) {
@Override
public ElasticsearchClientType build() {
- boolean isEmpty = StringUtils.isEmpty(propertyValue);
- return isEmpty ?
+ boolean isBlank = StringUtils.isBlank(propertyValue);
+ return isBlank ?
DEFAULT_ELASTICSEARCH_CLIENT_TYPE :
getElasticsearchClientType(propertyValue);
}
private ElasticsearchClientType getElasticsearchClientType(String propertyValue){
- boolean isExistingValue =
- Arrays
- .stream(values())
- .anyMatch(clientType -> clientType.toString().equalsIgnoreCase(propertyValue));
- return isExistingValue ? valueOf(propertyValue.toUpperCase()) : UNKNOWN;
+ try {
+ return ElasticsearchClientType.valueOf(propertyValue.toUpperCase());
+ } catch (IllegalArgumentException | NullPointerException e) {
Review Comment:
I've removed the NPE in the updated code.
--
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-unsubscribe@zeppelin.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [ZEPPELIN-6262] Refactor ElasticsearchClientTypeBuilder for safer enum handling and blank input support [zeppelin]
Posted by "Reamer (via GitHub)" <gi...@apache.org>.
Reamer commented on PR #5002:
URL: https://github.com/apache/zeppelin/pull/5002#issuecomment-3131090872
Merged into master and branch-0.12
--
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-unsubscribe@zeppelin.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [ZEPPELIN-6262] Refactor ElasticsearchClientTypeBuilder for safer enum handling and blank input support [zeppelin]
Posted by "Reamer (via GitHub)" <gi...@apache.org>.
Reamer merged PR #5002:
URL: https://github.com/apache/zeppelin/pull/5002
--
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-unsubscribe@zeppelin.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [ZEPPELIN-6262] Refactor ElasticsearchClientTypeBuilder for safer enum handling and blank input support [zeppelin]
Posted by "Reamer (via GitHub)" <gi...@apache.org>.
Reamer commented on code in PR #5002:
URL: https://github.com/apache/zeppelin/pull/5002#discussion_r2234972759
##########
elasticsearch/src/main/java/org/apache/zeppelin/elasticsearch/client/ElasticsearchClientTypeBuilder.java:
##########
@@ -47,18 +43,18 @@ private Builder(String propertyValue) {
@Override
public ElasticsearchClientType build() {
- boolean isEmpty = StringUtils.isEmpty(propertyValue);
- return isEmpty ?
+ boolean isBlank = StringUtils.isBlank(propertyValue);
Review Comment:
There is no need to save the result of IsBlank as a variable. Please resolve this.
##########
elasticsearch/src/main/java/org/apache/zeppelin/elasticsearch/client/ElasticsearchClientTypeBuilder.java:
##########
@@ -47,18 +43,18 @@ private Builder(String propertyValue) {
@Override
public ElasticsearchClientType build() {
- boolean isEmpty = StringUtils.isEmpty(propertyValue);
- return isEmpty ?
+ boolean isBlank = StringUtils.isBlank(propertyValue);
+ return isBlank ?
DEFAULT_ELASTICSEARCH_CLIENT_TYPE :
getElasticsearchClientType(propertyValue);
}
private ElasticsearchClientType getElasticsearchClientType(String propertyValue){
- boolean isExistingValue =
- Arrays
- .stream(values())
- .anyMatch(clientType -> clientType.toString().equalsIgnoreCase(propertyValue));
- return isExistingValue ? valueOf(propertyValue.toUpperCase()) : UNKNOWN;
+ try {
+ return ElasticsearchClientType.valueOf(propertyValue.toUpperCase());
+ } catch (IllegalArgumentException | NullPointerException e) {
Review Comment:
How can an NPE be thrown here?
--
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-unsubscribe@zeppelin.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [ZEPPELIN-6262] Refactor ElasticsearchClientTypeBuilder for safer enum handling and blank input support [zeppelin]
Posted by "ParkGyeongTae (via GitHub)" <gi...@apache.org>.
ParkGyeongTae commented on code in PR #5002:
URL: https://github.com/apache/zeppelin/pull/5002#discussion_r2237985010
##########
elasticsearch/src/main/java/org/apache/zeppelin/elasticsearch/client/ElasticsearchClientTypeBuilder.java:
##########
@@ -47,18 +43,18 @@ private Builder(String propertyValue) {
@Override
public ElasticsearchClientType build() {
- boolean isEmpty = StringUtils.isEmpty(propertyValue);
- return isEmpty ?
+ boolean isBlank = StringUtils.isBlank(propertyValue);
Review Comment:
Thanks for the feedback. I've made the change and removed the unnecessary variable for `IsBlank`.
--
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-unsubscribe@zeppelin.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org