Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit 457e8f9

Browse files
committed
fixed npe that lead to the revert
1 parent e7b6493 commit 457e8f9

File tree

4 files changed

+26
-3
lines changed

4 files changed

+26
-3
lines changed

shell/platform/android/BUILD.gn

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -487,6 +487,7 @@ action("robolectric_tests") {
487487
"test/io/flutter/embedding/engine/systemchannels/PlatformChannelTest.java",
488488
"test/io/flutter/embedding/engine/systemchannels/RestorationChannelTest.java",
489489
"test/io/flutter/external/FlutterLaunchTests.java",
490+
"test/io/flutter/plugin/common/BinaryCodecTest.java",
490491
"test/io/flutter/plugin/common/StandardMessageCodecTest.java",
491492
"test/io/flutter/plugin/common/StandardMethodCodecTest.java",
492493
"test/io/flutter/plugin/editing/InputConnectionAdaptorTest.java",

shell/platform/android/io/flutter/plugin/common/BinaryCodec.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
package io.flutter.plugin.common;
66

7+
import androidx.annotation.Nullable;
78
import java.nio.ByteBuffer;
89

910
/**
@@ -45,13 +46,15 @@ private BinaryCodec(boolean returnsDirectByteBufferFromDecoding) {
4546
}
4647

4748
@Override
48-
public ByteBuffer encodeMessage(ByteBuffer message) {
49+
public ByteBuffer encodeMessage(@Nullable ByteBuffer message) {
4950
return message;
5051
}
5152

5253
@Override
53-
public ByteBuffer decodeMessage(ByteBuffer message) {
54-
if (returnsDirectByteBufferFromDecoding) {
54+
public ByteBuffer decodeMessage(@Nullable ByteBuffer message) {
55+
if (message == null) {
56+
return message;
57+
} else if (returnsDirectByteBufferFromDecoding) {
5558
return message;
5659
} else {
5760
ByteBuffer result = ByteBuffer.allocate(message.capacity());

shell/platform/android/test/io/flutter/FlutterTestSuite.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import io.flutter.embedding.engine.systemchannels.PlatformChannelTest;
3131
import io.flutter.embedding.engine.systemchannels.RestorationChannelTest;
3232
import io.flutter.external.FlutterLaunchTests;
33+
import io.flutter.plugin.common.BinaryCodecTest;
3334
import io.flutter.plugin.common.StandardMessageCodecTest;
3435
import io.flutter.plugin.common.StandardMethodCodecTest;
3536
import io.flutter.plugin.editing.InputConnectionAdaptorTest;
@@ -53,6 +54,7 @@
5354
AccessibilityBridgeTest.class,
5455
AndroidKeyProcessorTest.class,
5556
ApplicationInfoLoaderTest.class,
57+
BinaryCodecTest.class,
5658
DartExecutorTest.class,
5759
DartMessengerTest.class,
5860
FlutterActivityAndFragmentDelegateTest.class,
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package io.flutter.plugin.common;
2+
3+
import static org.junit.Assert.assertNull;
4+
5+
import org.junit.Test;
6+
import org.junit.runner.RunWith;
7+
import org.robolectric.RobolectricTestRunner;
8+
import org.robolectric.annotation.Config;
9+
10+
@Config(manifest = Config.NONE)
11+
@RunWith(RobolectricTestRunner.class)
12+
public class BinaryCodecTest {
13+
@Test
14+
public void decodeNull() {
15+
assertNull(BinaryCodec.INSTANCE.decodeMessage(null));
16+
}
17+
}

0 commit comments

Comments
 (0)