mattcasters commented on code in PR #8911:
URL: https://github.com/apache/hop/pull/8911#discussion_r4270011551
##########
plugins/actions/columnsexist/src/main/java/org/apache/hop/workflow/actions/columnsexist/ActionColumnsExistDialog.java:
##########
@@ -319,55 +328,82 @@ private void ok() {
/** Get a list of columns */
private void getListColumns() {
- if (!Utils.isEmpty(wTablename.getText())) {
- DatabaseMeta databaseMeta = wConnection.loadSelectedElement();
- if (databaseMeta != null) {
- try (Database database = new Database(loggingObject, variables,
databaseMeta)) {
- database.connect();
- IRowMeta row =
- database.getTableFieldsMeta(
- variables.resolve(wSchemaname.getText()),
- variables.resolve(wTablename.getText()));
- if (row != null) {
- String[] available = row.getFieldNames();
-
- wFields.removeAll();
- for (String s : available) {
- wFields.add(s);
- }
- wFields.removeEmptyRows();
- wFields.setRowNums();
- } else {
- MessageBox mb = new MessageBox(shell, SWT.OK | SWT.ICON_ERROR);
- mb.setMessage(
- BaseMessages.getString(PKG,
"ActionColumnsExist.GetListColumsNoRow.DialogMessage"));
- mb.setText(BaseMessages.getString(PKG, CONST_ERROR_TITLE));
- mb.open();
+ if (Utils.isEmpty(wConnection.getText())) {
+ MessageBox mb = new MessageBox(shell, SWT.OK | SWT.ICON_ERROR);
+ mb.setMessage(
+ BaseMessages.getString(PKG,
"ActionColumnsExist.ConnectionError.DialogMessage"));
+ mb.setText(BaseMessages.getString(PKG, CONST_ERROR_TITLE));
+ mb.open();
+ return;
+ }
+ if (Utils.isEmpty(wTablename.getText())) {
+ MessageBox mb = new MessageBox(shell, SWT.OK | SWT.ICON_ERROR);
+ mb.setMessage(BaseMessages.getString(PKG,
"ActionColumnsExist.Error.TablenameEmpty"));
+ mb.setText(BaseMessages.getString(PKG, CONST_ERROR_TITLE));
+ mb.open();
+ return;
+ }
+
+ DatabaseMeta databaseMeta = wConnection.loadSelectedElement();
+ if (databaseMeta != null) {
+ try (Database database = new Database(loggingObject, variables,
databaseMeta)) {
+ database.connect();
+ IRowMeta row =
+ database.getTableFieldsMeta(
+ variables.resolve(wSchemaname.getText()),
variables.resolve(wTablename.getText()));
+ if (row != null) {
+ String[] available = row.getFieldNames();
+
+ wFields.removeAll();
+ for (String s : available) {
+ wFields.add(s);
}
- } catch (Exception e) {
- new ErrorDialog(
- shell,
- BaseMessages.getString(PKG, CONST_ERROR_TITLE),
- BaseMessages.getString(
- PKG, "ActionColumnsExist.ConnectionError2.DialogMessage",
wTablename.getText()),
- e);
+ wFields.removeEmptyRows();
+ wFields.setRowNums();
+ } else {
+ MessageBox mb = new MessageBox(shell, SWT.OK | SWT.ICON_ERROR);
+ mb.setMessage(
+ BaseMessages.getString(PKG,
"ActionColumnsExist.GetListColumsNoRow.DialogMessage"));
+ mb.setText(BaseMessages.getString(PKG, CONST_ERROR_TITLE));
+ mb.open();
}
+ } catch (Exception e) {
+ new ErrorDialog(
+ shell,
+ BaseMessages.getString(PKG, CONST_ERROR_TITLE),
+ BaseMessages.getString(
+ PKG, "ActionColumnsExist.ConnectionError2.DialogMessage",
wTablename.getText()),
+ e);
}
+ } else {
+ MessageBox mb = new MessageBox(shell, SWT.OK | SWT.ICON_ERROR);
+ mb.setMessage(
+ BaseMessages.getString(PKG,
"ActionColumnsExist.ConnectionError.DialogMessage"));
+ mb.setText(BaseMessages.getString(PKG, CONST_ERROR_TITLE));
+ mb.open();
}
}
private void getSchemaNames() {
if (wSchemaname.isDisposed()) {
return;
}
+ if (Utils.isEmpty(wConnection.getText())) {
+ MessageBox mb = new MessageBox(shell, SWT.OK | SWT.ICON_ERROR);
+ mb.setMessage(
+ BaseMessages.getString(PKG,
"ActionColumnsExist.ConnectionError.DialogMessage"));
+ mb.setText(BaseMessages.getString(PKG, CONST_ERROR_TITLE));
+ mb.open();
+ return;
+ }
DatabaseMeta databaseMeta = wConnection.loadSelectedElement();
if (databaseMeta != null) {
try (Database database = new Database(loggingObject, variables,
databaseMeta)) {
database.connect();
String[] schemas = database.getSchemas();
if (null != schemas && schemas.length > 0) {
- schemas = Const.sortStrings(schemas);
+ Arrays.sort(schemas,
Comparator.nullsFirst(String.CASE_INSENSITIVE_ORDER));
Review Comment:
**[suggestion]** `Comparator.nullsFirst` does not stop the schema-browse
failure for a schema-less driver. `Database.getSchemas()` already sorts with
`String.CASE_INSENSITIVE_ORDER` before it returns. Two or more names that
include null throw inside that sort, so this line never runs. A single null is
not compared (a one-element sort is a no-op) and is then passed to
`EnterSelectionDialog`, whose `List.add(null)` throws
`IllegalArgumentException`. Both still surface only as the generic connection
error dialog.
**Suggestion:** Drop null schema names before sorting. In
`Database.getSchemas()`, `schemaList.removeIf(Objects::isNull)` before `sort`,
and filter again here before opening the selection dialog. If nothing remains,
keep the existing empty-schema message. A null-safe comparator in the dialog
cannot see names `getSchemas()` already rejected.
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]