Bug 558642 - SafeRunner should be able to return results
Summary: SafeRunner should be able to return results
Status: RESOLVED FIXED
Alias: None
Product: Equinox
Classification: Eclipse Project
Component: Components (show other bugs)
Version: 4.15   Edit
Hardware: All All
: P3 enhancement (vote)
Target Milestone: 4.15 M3   Edit
Assignee: Marcus Höpfner CLA
QA Contact:
URL:
Whiteboard:
Keywords: api, noteworthy
Depends on:
Blocks:
 
Reported: 2019-12-27 04:29 EST by Marcus Höpfner CLA
Modified: 2020-05-26 10:23 EDT (History)
7 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Marcus Höpfner CLA 2019-12-27 04:29:50 EST
SafeRunner should be able to return results.

Often the "array pattern" is used to overcome final restriction.

Object[] obj = new Object[1];
SafeRunner.run(()-> obj[0] = callSomething());

SafeRunner should get a run method which accepts something like a SafeRunnableWithResult. This has a run method which returns something (<T>).
Comment 1 Marcus Höpfner CLA 2019-12-27 05:06:35 EST
Inspired by https://bugs.eclipse.org/bugs/show_bug.cgi?id=558562
Comment 2 Michael Keppler CLA 2019-12-27 06:04:15 EST
I had the same in mind, when I reviewed your change, therefore +1 for the request.

When implementing that, please consider making the class more user friendly than the current ISafeRunnable, which declares 2 methods, where 1 of them is always implemented empty. To get around that noise and to make the SafeRunnable usable as lambda, egit has a slightly different implementation for it: https://git.eclipse.org/r/#/c/131625/4/org.eclipse.egit.core/src/org/eclipse/egit/core/internal/SafeRunnable.java
Comment 3 Sebastian Ratz CLA 2019-12-27 10:46:45 EST
(In reply to Michael Keppler from comment #2)
> When implementing that, please consider making the class more user friendly
> than the current ISafeRunnable, which declares 2 methods, where 1 of them is
> always implemented empty. To get around that noise and to make the
> SafeRunnable usable as lambda, egit has a slightly different implementation
> for it:
> https://git.eclipse.org/r/#/c/131625/4/org.eclipse.egit.core/src/org/eclipse/
> egit/core/internal/SafeRunnable.java

org.eclipse.core.runtime.ISafeRunnable already is a @FunctionalInterface and can be implemented using a lambda.
Comment 4 Mickael Istria CLA 2020-01-06 05:11:26 EST
I think it's a good candidate for next milestone, but too late for the upcoming one.
Comment 6 Lars Vogel CLA 2020-01-06 08:15:05 EST
Thanks Marcus, please add to N&N.
Comment 7 Andrey Loskutov CLA 2020-01-07 01:44:06 EST
This causes regression on all platforms, see

https://download.eclipse.org/eclipse/downloads/drops4/I20200106-1805/testresults/html/org.eclipse.core.tests.runtime_ep415I-unit-cen64-gtk3-java8_linux.gtk.x86_64_8.0.html

2.1 expected:<org.eclipse.[core.tests.runtime]> but was:<org.eclipse.[equinox.common]>

junit.framework.ComparisonFailure: 2.1 expected:<org.eclipse.[core.tests.runtime]> but was:<org.eclipse.[equinox.common]>
at junit.framework.Assert.assertEquals(Assert.java:100)
at junit.framework.TestCase.assertEquals(TestCase.java:261)
at org.eclipse.core.tests.runtime.PlatformTest.testRunnable(PlatformTest.java:151)

Please evaluate if this is a problem with the change itself or only test that need to be fixed.
Comment 8 Andrey Loskutov CLA 2020-01-07 01:50:57 EST
(In reply to Andrey Loskutov from comment #7)
> This causes regression on all platforms, see

Also this causes *another* regression on all platforms:

https://download.eclipse.org/eclipse/downloads/drops4/I20200106-1805/testresults/html/org.eclipse.jface.text.tests_ep415I-unit-cen64-gtk3-java8_linux.gtk.x86_64_8.0.html

java.lang.AssertionError
at org.junit.Assert.fail(Assert.java:86)
at org.junit.Assert.assertTrue(Assert.java:41)
at org.junit.Assert.assertNotNull(Assert.java:712)
at org.junit.Assert.assertNotNull(Assert.java:722)
at org.eclipse.jface.text.tests.contentassist.AsyncContentAssistTest.testAsyncFailureStackOverflow(AsyncContentAssistTest.java:69)
Comment 9 Lars Vogel CLA 2020-01-07 04:05:24 EST
I suggest to revert for M1 and revisit for M3.

Marcus, OK for you?
Comment 10 Marcus Höpfner CLA 2020-01-07 04:08:11 EST
(In reply to Lars Vogel from comment #9)
> I suggest to revert for M1 and revisit for M3.
> 
> Marcus, OK for you?

Yes, I'll revert.
Comment 11 Marcus Höpfner CLA 2020-01-07 04:17:55 EST
(In reply to Marcus Höpfner from comment #10)
> (In reply to Lars Vogel from comment #9)
> > I suggest to revert for M1 and revisit for M3.
> > 
> > Marcus, OK for you?
> 
> Yes, I'll revert.

Sorry, I'm not allowed. Can someone else revert please.
Comment 12 Eclipse Genie CLA 2020-01-07 04:19:53 EST
New Gerrit change created: https://git.eclipse.org/r/155370
Comment 13 Eclipse Genie CLA 2020-01-07 04:19:56 EST
New Gerrit change created: https://git.eclipse.org/r/155371
Comment 14 Mickael Istria CLA 2020-01-07 04:20:30 EST
(In reply to Marcus Höpfner from comment #11)
> Sorry, I'm not allowed. Can someone else revert please.

Revert patch submitted for review at https://git.eclipse.org/r/#/c/155371/ . I'll leave it to other stakeholders to merge it or not.
Comment 15 Mickael Istria CLA 2020-01-07 04:21:41 EST
(In reply to Mickael Istria from comment #14)
> (In reply to Marcus Höpfner from comment #11)
> > Sorry, I'm not allowed. Can someone else revert please.
> 
> Revert patch submitted for review at https://git.eclipse.org/r/#/c/155371/ .
> I'll leave it to other stakeholders to merge it or not.

Abandonned and replaced with https://git.eclipse.org/r/155370
Comment 17 Marcus Höpfner CLA 2020-01-07 07:24:32 EST
(In reply to Mickael Istria from comment #15)
> (In reply to Mickael Istria from comment #14)
> > (In reply to Marcus Höpfner from comment #11)
> > > Sorry, I'm not allowed. Can someone else revert please.
> > 
> > Revert patch submitted for review at https://git.eclipse.org/r/#/c/155371/ .
> > I'll leave it to other stakeholders to merge it or not.
> 
> Abandonned and replaced with https://git.eclipse.org/r/155370

Can someone please revert https://git.eclipse.org/r/c/155370/ again so that we do not forget this for M3. I don't have committer rights and hence cannot do it.
Interesting authorization by the ways, I can upload commits by I cannot create revert commits via gerrit.
Comment 18 Andrey Loskutov CLA 2020-01-07 07:29:36 EST
(In reply to Marcus Höpfner from comment #17)
> > Abandonned and replaced with https://git.eclipse.org/r/155370
> 
> Can someone please revert https://git.eclipse.org/r/c/155370/ again so that
> we do not forget this for M3. I don't have committer rights and hence cannot
> do it.
> Interesting authorization by the ways, I can upload commits by I cannot
> create revert commits via gerrit.

I would first try to investigate what caused the two regressions. I don't think it will be a full revert then, so you will probably land in a new gerrit anyway.
Comment 19 Marcus Höpfner CLA 2020-01-07 07:37:59 EST
(In reply to Andrey Loskutov from comment #18)
> (In reply to Marcus Höpfner from comment #17)
> > > Abandonned and replaced with https://git.eclipse.org/r/155370
> > 
> > Can someone please revert https://git.eclipse.org/r/c/155370/ again so that
> > we do not forget this for M3. I don't have committer rights and hence cannot
> > do it.
> > Interesting authorization by the ways, I can upload commits by I cannot
> > create revert commits via gerrit.
> 
> I would first try to investigate what caused the two regressions. I don't
> think it will be a full revert then, so you will probably land in a new
> gerrit anyway.

Sure. I'll investigate. But I'd like to start with the revert (of the revert). Since the regression occurred due to this change I'd rather start with it and adapt it instead of creating a new from scratch.
Comment 20 Andrey Loskutov CLA 2020-01-07 07:42:12 EST
(In reply to Marcus Höpfner from comment #19)
> Sure. I'll investigate. But I'd like to start with the revert (of the
> revert). Since the regression occurred due to this change I'd rather start
> with it and adapt it instead of creating a new from scratch.

You can revert locally, update the code if needed and push, so where is the problem? If *I* will revert, you will not be able to modify the gerrit, because contributors are unable to update gerrits from commiters (there is a bug in our gerrit somewhere about it).
Comment 21 Marcus Höpfner CLA 2020-01-07 08:09:13 EST
(In reply to Andrey Loskutov from comment #20)
> (In reply to Marcus Höpfner from comment #19)
> > Sure. I'll investigate. But I'd like to start with the revert (of the
> > revert). Since the regression occurred due to this change I'd rather start
> > with it and adapt it instead of creating a new from scratch.
> 
> You can revert locally, update the code if needed and push, so where is the
> problem? If *I* will revert, you will not be able to modify the gerrit,
> because contributors are unable to update gerrits from commiters (there is a
> bug in our gerrit somewhere about it).

Ok. I'll do it
Comment 22 Eclipse Genie CLA 2020-01-13 08:09:32 EST
New Gerrit change created: https://git.eclipse.org/r/155742
Comment 23 Marcus Höpfner CLA 2020-01-13 08:16:38 EST
(In reply to Andrey Loskutov from comment #7)
> This causes regression on all platforms, see
> 
> https://download.eclipse.org/eclipse/downloads/drops4/I20200106-1805/
> testresults/html/org.eclipse.core.tests.runtime_ep415I-unit-cen64-gtk3-
> java8_linux.gtk.x86_64_8.0.html
> 
> 2.1 expected:<org.eclipse.[core.tests.runtime]> but
> was:<org.eclipse.[equinox.common]>
> 
> junit.framework.ComparisonFailure: 2.1
> expected:<org.eclipse.[core.tests.runtime]> but
> was:<org.eclipse.[equinox.common]>
> at junit.framework.Assert.assertEquals(Assert.java:100)
> at junit.framework.TestCase.assertEquals(TestCase.java:261)
> at
> org.eclipse.core.tests.runtime.PlatformTest.testRunnable(PlatformTest.java:
> 151)
> 
> Please evaluate if this is a problem with the change itself or only test
> that need to be fixed.

I have uploaded a new commit. Problem with the original one was, that the run method used a SafeRunnerWithResult<Void> to prevent duplicate code. Unfortunately the bundle of this SafeRunnerWithResult was determined instead of the bundle id of the original runnable. I removed the "composition" code and now it works. I tested only the above unit test. Not the one from comment #8 (https://bugs.eclipse.org/bugs/show_bug.cgi?id=558642#c8)
I'm pretty sure it was the same problem.
Comment 24 Eclipse Genie CLA 2020-01-13 08:32:39 EST
New Gerrit change created: https://git.eclipse.org/r/155744
Comment 25 Marcus Höpfner CLA 2020-01-21 01:47:42 EST
For me this is ready for merge.
Can someone please submit.
Comment 26 Marcus Höpfner CLA 2020-01-28 08:46:54 EST
Do you want me to do something more, are there any objections?
Or can this be merged?
Thanks
Comment 28 Lars Vogel CLA 2020-02-04 03:53:43 EST
I merged it on behave of Sebastians review, who AFAIK is not yet an Equinox committer.
Comment 29 Lars Vogel CLA 2020-02-04 03:53:57 EST
Thanks Marcus for the work!
Comment 30 Alexander Kurtakov CLA 2020-02-06 03:14:51 EST
Javadoc build failed with this patch:
https://download.eclipse.org/eclipse/downloads/drops4/I20200205-1800/compilelogs/platform.doc.isv.javadoc.txt
Comment 31 Eclipse Genie CLA 2020-02-06 03:17:51 EST
New Gerrit change created: https://git.eclipse.org/r/157251
Comment 33 Alexander Kurtakov CLA 2020-02-17 03:52:44 EST
As javadoc has been fixed resolved.
Comment 34 Marcus Höpfner CLA 2020-05-18 01:40:12 EDT
The N&N is still in review on gerrit https://git.eclipse.org/r/c/155744/. Should I abandon or merge?