Skip to content

Replace explicit type conversion with instanceof pattern variable in part non-core modules#15842

Merged
dweiss merged 4 commits into
apache:mainfrom
gaobinlong:pv1
Apr 2, 2026
Merged

Replace explicit type conversion with instanceof pattern variable in part non-core modules#15842
dweiss merged 4 commits into
apache:mainfrom
gaobinlong:pv1

Conversation

@gaobinlong
Copy link
Copy Markdown
Contributor

Description

As a follow-up of #15837, replace all explicit type conversions with instanceof pattern variable in part non-core modules like analysis, codecs, facets, grouping, highlighter etc, using the modern style aims to improve the code readability and reduces potential ClassCastException risks.

…part non-core modules

Signed-off-by: Binlong Gao <gbinlong@amazon.com>
} else {
if (((Hyphen) item).noBreak != null) {
res.append(((Hyphen) item).noBreak);
if (item instanceof Hyphen h && h.noBreak != null) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

this is subtly different - the refactored version will silently pass when item is not a Hyphen (previously, it'd throw ClassCastException. I don't think this matters.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thanks, reverted that back.

Comment on lines +97 to +99
if (q instanceof RegexpQuery query) {
String regexp = parseOutRegexp(query.toString(""));
String selected = selectLongestSubstring(regexp);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think I liked the previous version better - the short-circuit at the front instead of the long conditional block.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Changed that, thanks!

@dweiss
Copy link
Copy Markdown
Contributor

dweiss commented Apr 1, 2026

Also, conflict needs to be resolved.

Signed-off-by: Binlong Gao <gbinlong@amazon.com>
Signed-off-by: Binlong Gao <gbinlong@amazon.com>
Signed-off-by: Binlong Gao <gbinlong@amazon.com>
@dweiss dweiss merged commit b59848c into apache:main Apr 2, 2026
13 of 14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants