-
-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Issue #17487: Add refasterrules.OptionalRulesRecipes
#17792
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
Conversation
romani
left a comment
There was a problem hiding this 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(); |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
5476b26 to
5b25c01
Compare
| <configuration> | ||
| <compilerArgs> | ||
| <arg>-Xpkginfo:always</arg> | ||
| <arg>-XepOpt:Refaster:NamePattern=^(?!OptionalRules\$OptionalOrElseThrow).*</arg> |
There was a problem hiding this comment.
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:
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
5b25c01 to
2adc016
Compare
|
feel free to reopen and continue. My goal was to use rewrite, not to rely on some random recipe. |
Issue #17487: Add
refasterrules.OptionalRulesRecipes