-
Notifications
You must be signed in to change notification settings - Fork 7.6k
3.x: Fix scheduled tasks' fatal exception behavior #6956
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
Changes from all commits
5bb8720
c96767c
546ad7c
14c099f
7db460a
48bf526
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,7 +16,6 @@ | |
|
||
package io.reactivex.rxjava3.internal.schedulers; | ||
|
||
import io.reactivex.rxjava3.exceptions.Exceptions; | ||
import io.reactivex.rxjava3.plugins.RxJavaPlugins; | ||
|
||
/** | ||
|
@@ -39,10 +38,11 @@ public void run() { | |
runnable.run(); | ||
runner = null; | ||
} catch (Throwable ex) { | ||
Exceptions.throwIfFatal(ex); | ||
// Exceptions.throwIfFatal(ex); nowhere to go | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. But it seems make #748 a problem again. It seems tricky to balance this issue and #748. After all, if we passed StackOverflowError to RxJavaPlugins.onError(), RxJavaPlugins.onError() should throw it and it will be swallowed again. I think customizing the future task will completely solve #748 and this issue. JDK supports that and at least as I know Android are using that approach. And I think it is not complex as the core code is only implementing the JDK's interface. It even simplifies the schedulers implementation, as I see ; ) |
||
runner = null; | ||
lazySet(FINISHED); | ||
dispose(); | ||
RxJavaPlugins.onError(ex); | ||
throw ex; | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/** | ||
* Copyright (c) 2016-present, RxJava Contributors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in | ||
* compliance with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software distributed under the License is | ||
* distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See | ||
* the License for the specific language governing permissions and limitations under the License. | ||
*/ | ||
|
||
package io.reactivex.rxjava3.core; | ||
|
||
import static org.junit.Assert.fail; | ||
import static org.testng.Assert.assertTrue; | ||
|
||
import org.junit.Test; | ||
|
||
import io.reactivex.rxjava3.core.Scheduler.DisposeTask; | ||
import io.reactivex.rxjava3.exceptions.TestException; | ||
import io.reactivex.rxjava3.schedulers.Schedulers; | ||
import io.reactivex.rxjava3.testsupport.TestHelper; | ||
|
||
public class DisposeTaskTest extends RxJavaTest { | ||
|
||
@Test | ||
public void runnableThrows() throws Throwable { | ||
TestHelper.withErrorTracking(errors -> { | ||
|
||
Scheduler.Worker worker = Schedulers.single().createWorker(); | ||
|
||
DisposeTask task = new DisposeTask(() -> { | ||
throw new TestException(); | ||
}, worker); | ||
|
||
try { | ||
task.run(); | ||
fail("Should have thrown!"); | ||
} catch (TestException expected) { | ||
// expected | ||
} | ||
|
||
TestHelper.assertUndeliverable(errors, 0, TestException.class); | ||
|
||
assertTrue(worker.isDisposed()); | ||
}); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
/** | ||
* Copyright (c) 2016-present, RxJava Contributors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in | ||
* compliance with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software distributed under the License is | ||
* distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See | ||
* the License for the specific language governing permissions and limitations under the License. | ||
*/ | ||
|
||
package io.reactivex.rxjava3.core; | ||
|
||
import static org.junit.Assert.fail; | ||
import static org.testng.Assert.assertTrue; | ||
|
||
import java.util.List; | ||
|
||
import org.junit.Test; | ||
|
||
import io.reactivex.rxjava3.core.Scheduler.PeriodicDirectTask; | ||
import io.reactivex.rxjava3.exceptions.TestException; | ||
import io.reactivex.rxjava3.plugins.RxJavaPlugins; | ||
import io.reactivex.rxjava3.schedulers.Schedulers; | ||
import io.reactivex.rxjava3.testsupport.TestHelper; | ||
|
||
public class PeriodicDirectTaskTest extends RxJavaTest { | ||
|
||
@Test | ||
public void runnableThrows() { | ||
List<Throwable> errors = TestHelper.trackPluginErrors(); | ||
try { | ||
Scheduler.Worker worker = Schedulers.single().createWorker(); | ||
|
||
PeriodicDirectTask task = new PeriodicDirectTask(() -> { | ||
throw new TestException(); | ||
}, worker); | ||
|
||
try { | ||
task.run(); | ||
fail("Should have thrown!"); | ||
} catch (TestException expected) { | ||
// expected | ||
} | ||
|
||
TestHelper.assertUndeliverable(errors, 0, TestException.class); | ||
|
||
assertTrue(worker.isDisposed()); | ||
|
||
task.run(); | ||
} finally { | ||
RxJavaPlugins.reset(); | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/** | ||
* Copyright (c) 2016-present, RxJava Contributors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in | ||
* compliance with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software distributed under the License is | ||
* distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See | ||
* the License for the specific language governing permissions and limitations under the License. | ||
*/ | ||
|
||
package io.reactivex.rxjava3.internal.schedulers; | ||
|
||
import static org.junit.Assert.fail; | ||
|
||
import java.util.List; | ||
|
||
import org.junit.Test; | ||
|
||
import io.reactivex.rxjava3.core.RxJavaTest; | ||
import io.reactivex.rxjava3.exceptions.TestException; | ||
import io.reactivex.rxjava3.internal.schedulers.ExecutorScheduler.ExecutorWorker.BooleanRunnable; | ||
import io.reactivex.rxjava3.plugins.RxJavaPlugins; | ||
import io.reactivex.rxjava3.testsupport.TestHelper; | ||
|
||
public class BooleanRunnableTest extends RxJavaTest { | ||
|
||
@Test | ||
public void runnableThrows() { | ||
List<Throwable> errors = TestHelper.trackPluginErrors(); | ||
try { | ||
BooleanRunnable task = new BooleanRunnable(() -> { | ||
throw new TestException(); | ||
}); | ||
|
||
try { | ||
task.run(); | ||
fail("Should have thrown!"); | ||
} catch (TestException expected) { | ||
// expected | ||
} | ||
|
||
TestHelper.assertUndeliverable(errors, 0, TestException.class); | ||
} finally { | ||
RxJavaPlugins.reset(); | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/** | ||
* Copyright (c) 2016-present, RxJava Contributors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in | ||
* compliance with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software distributed under the License is | ||
* distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See | ||
* the License for the specific language governing permissions and limitations under the License. | ||
*/ | ||
|
||
package io.reactivex.rxjava3.internal.schedulers; | ||
|
||
import static org.junit.Assert.fail; | ||
|
||
import java.util.List; | ||
|
||
import org.junit.Test; | ||
|
||
import io.reactivex.rxjava3.core.RxJavaTest; | ||
import io.reactivex.rxjava3.exceptions.TestException; | ||
import io.reactivex.rxjava3.internal.schedulers.ExecutorScheduler.ExecutorWorker.InterruptibleRunnable; | ||
import io.reactivex.rxjava3.plugins.RxJavaPlugins; | ||
import io.reactivex.rxjava3.testsupport.TestHelper; | ||
|
||
public class InterruptibleRunnableTest extends RxJavaTest { | ||
|
||
@Test | ||
public void runnableThrows() { | ||
List<Throwable> errors = TestHelper.trackPluginErrors(); | ||
try { | ||
InterruptibleRunnable task = new InterruptibleRunnable(() -> { | ||
throw new TestException(); | ||
}, null); | ||
|
||
try { | ||
task.run(); | ||
fail("Should have thrown!"); | ||
} catch (TestException expected) { | ||
// expected | ||
} | ||
|
||
TestHelper.assertUndeliverable(errors, 0, TestException.class); | ||
} finally { | ||
RxJavaPlugins.reset(); | ||
} | ||
} | ||
} |
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.
@JakeWharton Does this syntax work with Android desugar (rethrowing final
Throwable
s)?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.
Hmm this looks like a normal throw. I don't understand what might be a compatibility concern here.
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.
The Java 7 compiler feature that let's you rethrow constant cheched or
Throwable
exceptions from within acatch
block, even if the method didn't specify athrows
clause.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.
Ah, missed it was
Throwable
. Checked exceptions are only a feature of the Java compiler not the Java bytecode so yeah the Android toolchain won't care 👍 .