mattcasters commented on code in PR #8379:
URL: https://github.com/apache/hop/pull/8379#discussion_r4028616625
##########
plugins/misc/mail/src/main/java/org/apache/hop/mail/workflow/actions/getpop/MailConnectionMeta.java:
##########
@@ -130,69 +131,48 @@ public static String getValueImapListCode(int i) {
return valueIMAPListCode[i];
}
- public static int getConditionByCode(String tt) {
- if (tt == null) {
+ /**
+ * Resolve a persisted code. Accepts the historical string codes ({@code
ignore}, {@code
+ * imaplistunread}, {@code nothing}, …) and integer indexes written by Hop
2.19 before converters
+ * were added.
+ */
Review Comment:
**[suggestion]** The `parseCodeOrInt` javadoc narrates version history
(“integer indexes written by Hop 2.19 before converters were added”) instead of
stating the current contract.
**Suggestion:** Keep a short contract comment, for example that the value
may be a code from the given table or a decimal index in range; drop the
2.19/converter origin story.
##########
plugins/misc/mail/src/main/java/org/apache/hop/mail/workflow/actions/getpop/MailConnectionMeta.java:
##########
@@ -130,69 +131,48 @@ public static String getValueImapListCode(int i) {
return valueIMAPListCode[i];
}
- public static int getConditionByCode(String tt) {
- if (tt == null) {
+ /**
+ * Resolve a persisted code. Accepts the historical string codes ({@code
ignore}, {@code
+ * imaplistunread}, {@code nothing}, …) and integer indexes written by Hop
2.19 before converters
+ * were added.
+ */
+ static int parseCodeOrInt(String value, String[] codes) {
+ if (StringUtils.isBlank(value)) {
return 0;
}
-
- for (int i = 0; i < conditionDateCode.length; i++) {
- if (conditionDateCode[i].equalsIgnoreCase(tt)) {
+ String trimmed = value.trim();
+ for (int i = 0; i < codes.length; i++) {
+ if (codes[i].equalsIgnoreCase(trimmed)) {
return i;
}
}
+ if (StringUtils.isNumeric(trimmed)) {
+ int parsed = Integer.parseInt(trimmed);
+ if (parsed >= 0 && parsed < codes.length) {
+ return parsed;
Review Comment:
**[suggestion]** `parseCodeOrInt` is meant to be total over persisted
strings (unknown → 0) so XML load never throws. After `StringUtils.isNumeric`,
`Integer.parseInt` can still throw `NumberFormatException`: values larger than
`Integer.MAX_VALUE`, or Unicode digits that `Character.isDigit` accepts but
`parseInt` does not. That exception is wrapped by
`XmlMetadataUtil.deSerializeInteger` and fails the whole workflow load — the
same class of failure this PR is fixing for `"ignore"`.
**Suggestion:** Do not let the converter throw. Use
`NumberUtils.toInt(trimmed, -1)` (already on the Lang3 classpath) or catch
`NumberFormatException` and return 0, matching the out-of-range integer path.
--
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]