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

sketch of a more invasive CompletableFuture patch #126

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

mosesn
Copy link
Contributor

@mosesn mosesn commented May 14, 2023

This more invasive approach (compared to #121) lets us delete a lot of code. I think it's a matter of taste whether it's better or not, but I figured this would illustrate what I meant more clearly than chatting over PRs :).

I do not think we should merge this as-is. In particular, I put a lot of logic in an anonymous lambda in the constructor, and we can likely find a better home for it. I would also completely understand you saying that you don't like this approach and simply closing the PR.

this.resultHandler = new CompositeExecuteResultHandler(this,
Arrays.asList(new LoggingExecuteResultHandler(this), new ProcessResultHandler(listener)));
this.asyncResult = new CompletableFuture<>();
this.asyncResult.<Void>handle((result, e) ->
Copy link

Choose a reason for hiding this comment

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

24% of developers fix this issue

FutureReturnValueIgnored: Return value of methods returning Future must be checked. Ignoring returned Futures suppresses exceptions thrown from the code that completes the Future.


ℹ️ Expand to see all @sonatype-lift commands

You can reply with the following commands. For example, reply with @sonatype-lift ignoreall to leave out all findings.

Command Usage
@sonatype-lift ignore Leave out the above finding from this PR
@sonatype-lift ignoreall Leave out all the existing findings from this PR
@sonatype-lift exclude <file|issue|path|tool> Exclude specified file|issue|path|tool from Lift findings by updating your config.toml file

Note: When talking to LiftBot, you need to refresh the page to see its response.
Click here to add LiftBot to another repo.

@sonatype-lift
Copy link

sonatype-lift bot commented May 14, 2023

🛠 Lift Auto-fix

Some of the Lift findings in this PR can be automatically fixed. You can download and apply these changes in your local project directory of your branch to review the suggestions before committing.1

# Download the patch
curl https://lift.sonatype.com/api/patch/github.com/vorburger/ch.vorburger.exec/126.diff -o lift-autofixes.diff

# Apply the patch with git
git apply lift-autofixes.diff

# Review the changes
git diff

Want it all in a single command? Open a terminal in your project's directory and copy and paste the following command:

curl https://lift.sonatype.com/api/patch/github.com/vorburger/ch.vorburger.exec/126.diff | git apply

Once you're satisfied, commit and push your changes in your project.

Footnotes

  1. You can preview the patch by opening the patch URL in the browser.

@mosesn mosesn force-pushed the mosesn/invasive-completablefuture branch 2 times, most recently from 94b82c3 to 30e05e0 Compare May 14, 2023 20:34
@vorburger
Copy link
Owner

@mosesn this looks interesting! I'm in principle in favour of something like this, because I like the code simplification that this seems to bring. I would need to review it in full details though. And we're both so excited that both of our work overlaps a little bit - which is totally OK! Could I propose the following next steps in this order:

  1. Do you want to review my Throw IllegalStateException instead of silently returning (wrong) Optional.empty() #123 + Catch more specific exception types, and add test coverage #124 and I merge those, for now? I do understand that this PR will then remove that again - and that's totally fine with me! I just prefer getting things merged in order, and then change them again (and have a baseline to revert back to, in the unlikely event that we would have to back this out again later).

  2. I finish a PR that I have WIP to add Checkstyle, in order to settle tabs vs spaces 🤣

  3. [I go to sleep]

  4. You rebase this PR

  5. I review this PR in details, may ask some questions and feedback, and then merge it

Would this sequence be OK for you?

@mosesn
Copy link
Contributor Author

mosesn commented May 14, 2023

🤦 Sorry about the tabs, I haven't set up my emacs config properly for Java on my personal laptop and I try to avoid opening my work laptop on the weekend . . . I'll get right to that. That approach sounds good to me! One nit: how about we use spotless instead of checkstyle? Spotless has an autofixer that doesn't force me to use IntelliJ haha

@vorburger
Copy link
Owner

@mosesn voilà steps 1. & 2. are done, I'll go to 😴 now and this is all yours for 4!

@mosesn mosesn force-pushed the mosesn/invasive-completablefuture branch from 30e05e0 to 822cfc6 Compare May 15, 2023 00:08
@mosesn
Copy link
Contributor Author

mosesn commented May 15, 2023

Looks like there are still a couple of bugs in it. Interestingly, I get a couple failures locally but they're different ones:

[ERROR] Failures:
[ERROR]   ManagedProcessTest.onProcessFailedInvokedOnCustomListenerWithExitValueChecker:67 expected:<2> but was:<1>
[ERROR] Errors:
[ERROR]   ManagedProcessTest.mustTerminateExec:210 » ManagedProcess Program [sleep, 30s] (in working directory /Users/moses/projects/ch.vorburger.exec/.) failed with Exception: , last 100 lines of console:
usage: sleep seconds

I think it's just discrepancies in the sleep and ls implementations though. I'll have to do some poking to figure out what's going on with the other issues. I don't think I'll get to it tonight, I'll try to figure it out later this week.

@vorburger
Copy link
Owner

I think it's just discrepancies in the sleep and ls implementations though.

Are you on Mac locally? The tests on the main branch may well be broken on Mac. (The CI only covers Linux.)

If so, raise a small separate PR to fix that, first?

@mosesn
Copy link
Contributor Author

mosesn commented May 20, 2023

I think it's just discrepancies in the sleep and ls implementations though.

Are you on Mac locally? The tests on the main branch may well be broken on Mac. (The CI only covers Linux.)

If so, raise a small separate PR to fix that, first?

#135

@vorburger
Copy link
Owner

@mosesn Hi! It's been a while... 😃 Do you want to rebase this, and we can get this in?

@mosesn
Copy link
Contributor Author

mosesn commented Dec 8, 2023

Hey, I think I'll get some time in the next few weeks to take a stab at rebasing this! Sorry for the delay

@vorburger
Copy link
Owner

@mosesn did you still want to rebase and clean this up for re-review and possible inclusion? Or forget about & close this one?

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.

None yet

2 participants