Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove unreachable code in OrderedPeriodParser #24405

Merged
merged 1 commit into from
Dec 30, 2024

Conversation

takezoe
Copy link
Member

@takezoe takezoe commented Dec 8, 2024

Description

Additional context and related issues

Release notes

( ) This is not user-visible or is docs only, and no release notes are required.
( ) Release notes are required. Please propose a release note for me.
( ) Release notes are required, with the following suggested text:

## Section
* Fix some things. ({issue}`issuenumber`)

@cla-bot cla-bot bot added the cla-signed label Dec 8, 2024
}

return ~bestInvalidPos;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line is unreachable because bestValidPos > position || (bestValidPos == position) is always true.

// Restore the state to the best valid parse.
if (bestValidPeriod != null) {
period.setPeriod(bestValidPeriod);
return ~parsePos;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think there is no reason to continue trying to parse when even one of parsers fails in this use case. It would be better to return earlier.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the reason it is there is because it can provide better error messages since the error that would be retained would be from the "longest matching" parser.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In that case, I wonder how it should work when any parsers fail. Just throwing away error position and returning the longest succeeded position (or the initial position if there are no successful parsers) is expected?

Sure, that works because PeriodFormatter throws an exception when returned position is less than the text length: https://github.com/JodaOrg/joda-time/blob/v2.12.7/src/main/java/org/joda/time/format/PeriodFormatter.java#L323-L331

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I revised this PR to just remove the unreachable (and meaningless) code.

@takezoe takezoe force-pushed the return-datetime-parse-failure-earlier branch from b7afe3d to 80bd9a6 Compare December 9, 2024 17:27
@takezoe takezoe changed the title Fix OrderedPeriodParser to return earlier when parsing fails Remove unreachable code in OrderedPeriodParser Dec 9, 2024
@takezoe takezoe force-pushed the return-datetime-parse-failure-earlier branch from 80bd9a6 to ba07989 Compare December 9, 2024 17:31
@dain dain merged commit effac4f into trinodb:master Dec 30, 2024
94 checks passed
@github-actions github-actions bot added this to the 469 milestone Dec 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging this pull request may close these issues.

3 participants