This repository was archived by the owner on Feb 25, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6k
Forward Error objects to uncaught exception handler if there is one. #21806
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
cefc5e0
Forward Error objects to uncaught exception handler if there is one.
mehmetf 284c159
Fix typo in comments
mehmetf 1fff810
Add test for DartMessenger
mehmetf 6775c6f
Remove mistake
mehmetf 3903737
Formatting and reorg imports
mehmetf 0754943
Add the new test file to BUILD
mehmetf 7ecbba7
Wrong test class name
mehmetf 1978370
Import assertTrue
mehmetf File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
shell/platform/android/test/io/flutter/embedding/engine/dart/DartExecutorTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
shell/platform/android/test/io/flutter/embedding/engine/dart/DartMessengerTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| package io.flutter.embedding.engine.dart; | ||
|
|
||
| import static junit.framework.TestCase.assertNotNull; | ||
| import static junit.framework.TestCase.assertTrue; | ||
| import static org.mockito.Matchers.any; | ||
| import static org.mockito.Mockito.mock; | ||
|
|
||
| import io.flutter.embedding.engine.FlutterJNI; | ||
| import io.flutter.plugin.common.BinaryMessenger.BinaryMessageHandler; | ||
| import java.nio.ByteBuffer; | ||
| import org.junit.Test; | ||
| import org.junit.runner.RunWith; | ||
| import org.mockito.Mockito; | ||
| import org.robolectric.RobolectricTestRunner; | ||
| import org.robolectric.annotation.Config; | ||
|
|
||
| @Config(manifest = Config.NONE) | ||
| @RunWith(RobolectricTestRunner.class) | ||
| public class DartMessengerTest { | ||
| private static class ReportingUncaughtExceptionHandler | ||
| implements Thread.UncaughtExceptionHandler { | ||
| public Throwable latestException; | ||
|
|
||
| @Override | ||
| public void uncaughtException(Thread t, Throwable e) { | ||
| latestException = e; | ||
| } | ||
| } | ||
|
|
||
| @Test | ||
| public void itHandlesErrors() { | ||
| // Setup test. | ||
| final FlutterJNI fakeFlutterJni = mock(FlutterJNI.class); | ||
| final Thread currentThread = Thread.currentThread(); | ||
| final Thread.UncaughtExceptionHandler savedHandler = | ||
| currentThread.getUncaughtExceptionHandler(); | ||
| final ReportingUncaughtExceptionHandler reportingHandler = | ||
| new ReportingUncaughtExceptionHandler(); | ||
| currentThread.setUncaughtExceptionHandler(reportingHandler); | ||
|
|
||
| // Create object under test. | ||
| final DartMessenger messenger = new DartMessenger(fakeFlutterJni); | ||
| final BinaryMessageHandler throwingHandler = mock(BinaryMessageHandler.class); | ||
| Mockito.doThrow(AssertionError.class) | ||
| .when(throwingHandler) | ||
| .onMessage(any(ByteBuffer.class), any(DartMessenger.Reply.class)); | ||
|
|
||
| messenger.setMessageHandler("test", throwingHandler); | ||
| messenger.handleMessageFromDart("test", new byte[] {}, 0); | ||
| assertNotNull(reportingHandler.latestException); | ||
| assertTrue(reportingHandler.latestException instanceof AssertionError); | ||
| currentThread.setUncaughtExceptionHandler(savedHandler); | ||
| } | ||
| } | ||
|
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Should this catch all Throwables?
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.
For now, no. I wanted to be explicit about handling
Errors which is a special kind of throwable that is not supposed to be caught. Java does not (currently) define anyThrowableother thanErrorandException.