Skip to content

Conversation

@Pankraz76
Copy link

Issue #17487: Add refasterrules.OptionalRulesRecipes

@Pankraz76 Pankraz76 marked this pull request as ready for review September 15, 2025 11:12
Copy link
Member

@romani romani left a comment

Choose a reason for hiding this comment

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

Items

boolean shouldValidateUntaggedSummary = true;
if (inlineTagNode.isPresent()) {
final DetailNode node = inlineTagNode.get();
final DetailNode node = inlineTagNode.orElseThrow();
Copy link
Member

Choose a reason for hiding this comment

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

I am not fun of this API .
I my opinion it doesn't help much , but a way more verbose and confusing in reading.

@rdiachenko , what is your opinion or thoughts on this?

Copy link
Author

Choose a reason for hiding this comment

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

and confusing in reading.

why confusing? It tells what happens, not like before hiding the exception surprise/bug.

Don’t like it either, but it still seems to be the de facto convention, since IntelliJ IDEA and other tools suggest it as well.

Asuming the idea is to promote a clear API, as get throwing an exception is a bit of a surprise—it’s not obvious and relies on prior knowledge.

That’s not great software design, since we want to avoid surprises and instead aim for code that is clear and intentional.

Copy link
Member

Choose a reason for hiding this comment

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

It's not black and white. I usually consider its usage case by case. From the exception standpoint there is no difference:

Exception in thread "main" java.util.NoSuchElementException: No value present
	at java.base/java.util.Optional.orElseThrow(Optional.java:377)

vs

Exception in thread "main" java.util.NoSuchElementException: No value present
	at java.base/java.util.Optional.get(Optional.java:143)

If no additional context to provide, I go with .get() since its less verbose, otherwise .orElseThrow(() -> new SomeException("more context")) is more helpful.

By the way, I don't like neither approach. Usually you want to handle it in a more proper way like opt.ifPresent(value -> {....}), and similar methods. Relying on .get()/orElseThrow throwing exception should be a rare case as to me.

Copy link
Member

Choose a reason for hiding this comment

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

Thanks a lot.

@Pankraz76 , please disable this recipe with link to this discussion. In far future, next generation of maintainers might have different opinion. For now disabled.

<configuration>
<compilerArgs>
<arg>-Xpkginfo:always</arg>
<arg>-XepOpt:Refaster:NamePattern=^(?!OptionalRules\$OptionalOrElseThrow).*</arg>
Copy link
Author

Choose a reason for hiding this comment

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

Caused by: org.codehaus.plexus.compiler.CompilerException: error: invalid flag: -XepOpt:Refaster:NamePattern=^(?!OptionalRules\$OptionalOrElseThrow).*

applied from template:

Copy link
Member

Choose a reason for hiding this comment

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

ok, future engineers will use blame to get to reason of exclusion and will find our conversation in PR

Copy link
Author

Choose a reason for hiding this comment

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

yes but its not working currently, need to add link once its stable.

Copy link
Author

Choose a reason for hiding this comment

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

can not make this work.

@Pankraz76 Pankraz76 marked this pull request as draft September 18, 2025 09:40
@Pankraz76
Copy link
Author

feel free to reopen and continue.

My goal was to use rewrite, not to rely on some random recipe.

@Pankraz76 Pankraz76 closed this Sep 19, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants