-
Notifications
You must be signed in to change notification settings - Fork 54
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
Is there way to avoid 'Prefer java.util.Optional.orElseThrow' if 'isPresent()' is right before #300
Comments
is there a way to disable specific validator ? I did:
|
Modernizer has only simple bytecode-level checks with no flow control so it cannot understand if isPresent { get } sequences. But I would encourage you to call
I do appreciate any suggestions you have from the Checkstyle project as this project may benefit from better configuration. |
Following if statements from the bytecode may be near the same level of complexity as it is for us to track variable usage by the name. Even we can't do that correctly all the time for all our checks and there has been issues opened to build such a utility in CS. It doesn't help that each compiler will write the byte code in different ways for the same Java code. I've seen code block off logic in the if statements to the end of method's code, or inline it with the rest of the other logic by jumping around it. That doesn't even account for determining if it is a simple if or really a loop. And all this would have to be worked backwards from the pitest also works on the byte code only, and it used to write weird things in the report (from the source perspective) which made more sense looking at the bytecode. |
I understand general benefits of new methods, It is first time we run into this, and when I did suggested code it looked weird, we over care to readability of code in checkstyle project, and we try to find equilibrium between all best practices, and readability for regular humans(not very professional engineers). For now I will probably disable this valuation, and we might come back to it later on, maybe new jdk will not give us option anymore or something else come up as good pattern to write such code |
From the executing code perspective, there is no difference between |
detected at: checkstyle/checkstyle#16014 (comment)
from modernizer:
Prefer java.util.Optional.orElseThrow
I mam not sure why we should do it here as we did inlineTag.isPresent().
I agree that without
isPresent()
right before is it better to use orElseThrow as we do not know context, but if there is context .... can we somehow to avoid violation of such code ?The text was updated successfully, but these errors were encountered: