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

replace anonymous runnable class with lambda #1459

Merged

Conversation

elsazac
Copy link
Member

@elsazac elsazac commented Jan 3, 2024

No description provided.

Copy link
Contributor

github-actions bot commented Jan 3, 2024

Test Results

   899 files   -     1     899 suites   - 1   36m 3s ⏱️ - 30m 46s
 7 470 tests ±    0   7 316 ✅  -     1  153 💤 ±  0  1 ❌ +1 
21 982 runs   - 1 577  21 591 ✅  - 1 457  390 💤  - 121  1 ❌ +1 

For more details on these failures, see this check.

Results for commit 605c868. ± Comparison against base commit f746493.

♻️ This comment has been updated with latest results.

@elsazac elsazac force-pushed the refactor_runnableToLambda branch from 5002bb3 to 8b937a5 Compare January 4, 2024 06:32
Copy link
Contributor

@mickaelistria mickaelistria left a comment

Choose a reason for hiding this comment

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

I don't think this change is safe. Usually, a class that defines a field shouldn't be turned into a lambda as the field lifecycle (which value they get and where) matters.

@@ -872,18 +872,14 @@ public void processEvent(VerifyEvent e) {
private void filterProposals() {
++ fInvocationCounter;
Control control= fViewer.getTextWidget();
control.getDisplay().asyncExec(new Runnable() {
control.getDisplay().asyncExec(() -> {
Copy link
Contributor

Choose a reason for hiding this comment

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

This is not equivalent and will most likely cause bugs:

@@ -872,18 +872,14 @@ public void processEvent(VerifyEvent e) {
private void filterProposals() {
++ fInvocationCounter;
Control control= fViewer.getTextWidget();
control.getDisplay().asyncExec(new Runnable() {
control.getDisplay().asyncExec(() -> {
long fCounter= fInvocationCounter;
Copy link
Contributor

Choose a reason for hiding this comment

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

Before, fCounter is initialized just once, when filterProposals is invoked and the Runnable is created, ie before actually running the Runnable. While with the change, the value is set at execution of the Runnable, leading to...

Copy link
Member Author

Choose a reason for hiding this comment

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

will moving fCounter assignment outside of the lambda solve the problem?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, I think it would.

Copy link
Member Author

Choose a reason for hiding this comment

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

@mickaelistria I have made that change accordingly and removed the problematic lambda. please have a look.

@Override
public void run() {

if (fCounter != fInvocationCounter)
Copy link
Contributor

Choose a reason for hiding this comment

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

This condition not being always true (before) but being always true (after)


fContextInfoPopup.getDisplay().asyncExec(new Runnable() {

private ContextFrame fFrame= fContextFrameStack.peek();
Copy link
Contributor

Choose a reason for hiding this comment

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

A similar pattern here: the frame is set once at instantiation for some reason, not on the execution. This looks like an actual intent to capture the "initial value before execution".

@elsazac elsazac force-pushed the refactor_runnableToLambda branch from 8b937a5 to 605c868 Compare January 9, 2024 05:20
@mickaelistria mickaelistria merged commit 36519cd into eclipse-platform:master Jan 9, 2024
14 of 16 checks passed
@mickaelistria
Copy link
Contributor

Thank you!

amartya4256 pushed a commit to amartya4256/eclipse.platform.ui that referenced this pull request Feb 8, 2024
* replace anonymous runnable class with lambda
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.

2 participants