[BUG]在安卓上JSONObject.put多个字段null值后toJSONString(JSONWriter.Feature.WriteMapNullValue)会崩溃
- Dominant language
- Java
- Stars
- 4.4k
- Forks
- 613
- Avg merge
- 1d 22h
- Merged PRs (30d)
- 6
Description
### 问题描述
*简要描述您碰到的问题。*
在RK3568安卓11平台上,使用fastjson2的JSONObject.put多个(3个及以上)字段为null时,对JSONObject对象调用toJSONString方法,传参为JSONWriter.Feature.WriteMapNullValue时,app会崩溃
### 环境信息
*请填写以下信息:*
- OS信息: [e.g.:CentOS 8.4.2105 4Core 3.10GHz 16 GB] android 11
- JDK信息: [e.g.:Openjdk 1.8.0_312] jdk 17.0.10
- 版本信息:[e.g.:Fastjson2 2.x.x] com.alibaba.fastjson2:fastjson2:2.0.53
### 重现步骤
*如何操作可以重现该问题:*
1. 使用 `xxx.xxx` 方法
2. 输入 `...` 数据
3. 出现 `...` 错误
```java
//可在此输入示例代码
```
以下是单元测试的代码:
@Test
public void testJso2() {
JSONObject object = new JSONObject();
object.put("name", "tx");
object.put("age", null);
object.put("gender", null);
object.put("address", null);
object.put("gender", null);
Log.d(TAG, "testJso2: " + object.toJSONString(JSONWriter.Feature.WriteMapNullValue));
}
### 期待的正确结果
*对您期望发生的结果进行清晰简洁的描述。*
{"name":"tx","age":null,"gender":null,"address":null,"gender":null}
### 相关日志输出
*请复制并粘贴任何相关的日志输出。*
以下是logcat的日志(其中com.tx.face为app的包名):
2024-10-25 15:36:04.555 3205-3205 ActivityThread com.tx.face W Package uses different ABI(s) than its instrumentation: package[com.tx.face]: armeabi-v7a, null instrumentation[com.tx.face.test]: null, null
2024-10-25 15:36:06.816 3205-3205 com.tx.face com.tx.face W Accessing hidden method Landroid/app/Instrumentation;->execStartActivity(Landroid/content/Context;Landroid/os/IBinder;Landroid/os/IBinder;Landroid/app/Activity;Landroid/content/Intent;ILandroid/os/Bundle;)Landroid/app/Instrumentation$ActivityResult; (greylist, linking, allowed)
2024-10-25 15:36:06.817 3205-3205 com.tx.face com.tx.face W Accessing hidden method Landroid/app/Instrumentation;->execStartActivity(Landroid/content/Context;Landroid/os/IBinder;Landroid/os/IBinder;Ljava/lang/String;Landroid/content/Intent;ILandroid/os/Bundle;)Landroid/app/Instrumentation$ActivityResult; (greylist, linking, allowed)
2024-10-25 15:36:06.832 3205-3205 MonitoringInstr com.tx.face I newApplication called!
2024-10-25 15:36:06.887 3205-3205 MonitoringInstr com.tx.face I Instrumentation started!
2024-10-25 15:36:06.912 3205-3205 AndroidJUnitRunner com.tx.face I onCreate Bundle[{testTimeoutSeconds=31536000, class=com.tx.face.ExampleInstrumentedTest#testJso2, additionalTestOutputDir=/sdcard/Android/media/com.tx.face/additional_test_output}]
2024-10-25 15:36:06.917 3205-3205 TestEventClient com.tx.face V No service name argument was given (testDiscoveryService, testRunEventService or orchestratorService)
2024-10-25 15:36:06.922 3205-3245 AndroidJUnitRunner com.tx.face D onStart is called.
2024-10-25 15:36:06.926 3205-3205 MonitoringInstr com.tx.face I No JSBridge.
2024-10-25 15:36:06.951 3205-3245 TestRequestBuilder com.tx.face D Skipping class path scanning and directly running [com.tx.face.ExampleInstrumentedTest]
2024-10-25 15:36:06.987 3205-3245 AndroidJUnitRunner com.tx.face D Use the raw file system for managing file I/O.
2024-10-25 15:36:06.998 3205-3245 TestExecutor com.tx.face D Adding listener androidx.test.internal.runner.listener.LogRunListener
2024-10-25 15:36:06.998 3205-3245 TestExecutor com.tx.face D Adding listener androidx.test.internal.runner.listener.InstrumentationResultPrinter
2024-10-25 15:36:06.999 3205-3245 TestExecutor com.tx.face D Adding listener androidx.test.internal.runner.listener.ActivityFinisherRunListener
2024-10-25 15:36:06.999 3205-3245 TestExecutor com.tx.face D Adding listener androidx.test.internal.runner.listener.TraceRunListener
2024-10-25 15:36:07.009 3205-3245 TestRunner com.tx.face I run started: 1 tests
2024-10-25 15:36:07.013 3205-3245 TestRunner com.tx.face I started: testJso2(com.tx.face.ExampleInstrumentedTest)
2024-10-25 15:36:07.078 3205-3245 com.tx.face com.tx.face W Accessing hidden method Lsun/misc/Unsafe;->arrayBaseOffset(Ljava/lang/Class;)I (greylist,core-platform-api, linking, allowed)
2024-10-25 15:36:07.078 3205-3245 com.tx.face com.tx.face W Accessing hidden method Lsun/misc/Unsafe;->objectFieldOffset(Ljava/lang/reflect/Field;)J (greylist,core-platform-api, linking, allowed)
2024-10-25 15:36:07.079 3205-3245 com.tx.face com.tx.face W Accessing hidden method Ljava/lang/invoke/LambdaMetafactory;->metafactory(Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodHandle;Ljava/lang/invoke/MethodType;)Ljava/lang/invoke/CallSite; (blacklist, linking, allowed)
2024-10-25 15:36:07.090 3205-3245 com.tx.face com.tx.face W Accessing hidden method Lsun/misc/Unsafe;->getObject(Ljava/lang/Object;J)Ljava/lang/Object; (greylist, linking, allowed)
2024-10-25 15:36:07.091 3205-3245 com.tx.face com.tx.face W Accessing hidden field Lsun/misc/Unsafe;->theUnsafe:Lsun/misc/Unsafe; (greylist, reflection, allowed)
2024-10-25 15:36:07.171 3205-3245 com.tx.face com.tx.face W Accessing hidden method Lsun/misc/Unsafe;->getObject(Ljava/lang/Object;J)Ljava/lang/Object; (greylist, linking, allowed)
2024-10-25 15:36:07.171 3205-3245 com.tx.face com.tx.face W Accessing hidden method Lsun/misc/Unsafe;->getLong(Ljava/lang/Object;J)J (greylist,core-platform-api, linking, allowed)
2024-10-25 15:36:07.217 3205-3245 com.tx.face com.tx.face W Accessing hidden method Lsun/misc/Unsafe;->allocateInstance(Ljava/lang/Class;)Ljava/lang/Object; (greylist, linking, allowed)
2024-10-25 15:36:07.347 3205-3245 com.tx.face com.tx.face W Accessing hidden method Lsun/misc/Unsafe;->putLong(Ljava/lang/Object;JJ)V (greylist, linking, allowed)
2024-10-25 15:36:07.350 3205-3245 com.tx.face com.tx.face W Accessing hidden method Lsun/misc/Unsafe;->putInt(Ljava/lang/Object;JI)V (greylist, linking, allowed)
2024-10-25 15:36:07.351 3205-3245 com.tx.face com.tx.face W Accessing hidden method Lsun/misc/Unsafe;->getLong(Ljava/lang/Object;J)J (greylist,core-platform-api, linking, allowed)
2024-10-25 15:36:07.357 3205-3245 com.tx.face com.tx.face W Accessing hidden method Lsun/misc/Unsafe;->getChar(Ljava/lang/Object;J)C (greylist, linking, allowed)
2024-10-25 15:36:07.362 3205-3245 com.tx.face com.tx.face W Accessing hidden method Lsun/misc/Unsafe;->putShort(Ljava/lang/Object;JS)V (greylist, linking, allowed)
2024-10-25 15:36:07.367 3205-3245 libc com.tx.face A Fatal signal 7 (SIGBUS), code 1 (BUS_ADRALN), fault addr 0xe2942032 in tid 3245 (roidJUnitRunner), pid 3205 (com.tx.face)
2024-10-25 15:36:07.460 3282-3282 DEBUG pid-3282 A pid: 3205, tid: 3245, name: roidJUnitRunner >>> com.tx.face <<<
2024-10-25 15:36:07.735 3282-3282 DEBUG crash_dump32 A #08 pc 003b0e70 /data/app/com.tx.face-HIUDyM1VXQBJfbzsrO_XQQ==/base.apk (com.alibaba.fastjson2.JSONWriterUTF16.writeNull+52)
2024-10-25 15:36:07.736 3282-3282 DEBUG crash_dump32 A #11 pc 003ae732 /data/app/com.tx.face-HIUDyM1VXQBJfbzsrO_XQQ==/base.apk (com.alibaba.fastjson2.JSONWriterUTF16.write+410)
2024-10-25 15:36:07.736 3282-3282 DEBUG crash_dump32 A #14 pc 0035d91e /data/app/com.tx.face-HIUDyM1VXQBJfbzsrO_XQQ==/base.apk (com.alibaba.fastjson2.JSONObject.toString+14)
2024-10-25 15:36:07.737 3282-3282 DEBUG crash_dump32 A #17 pc 0035d870 /data/app/com.tx.face-HIUDyM1VXQBJfbzsrO_XQQ==/base.apk (com.alibaba.fastjson2.JSONObject.toJSONString)
2024-10-25 15:36:07.738 3282-3282 DEBUG crash_dump32 A #20 pc 0000079c /data/app/com.tx.face.test-Fv7zJJp3nsw7Yarj77H5mQ==/base.apk (com.tx.face.ExampleInstrumentedTest.testJso2+100)
2024-10-25 15:36:07.741 3282-3282 DEBUG crash_dump32 A #39 pc 000a4188 /data/app/com.tx.face.test-Fv7zJJp3nsw7Yarj77H5mQ==/base.apk (org.junit.runners.model.FrameworkMethod$1.runReflectiveCall+20)
2024-10-25 15:36:07.742 3282-3282 DEBUG crash_dump32 A #42 pc 0009c154 /data/app/com.tx.face.test-Fv7zJJp3nsw7Yarj77H5mQ==/base.apk (org.junit.internal.runners.model.ReflectiveCallable.run)
2024-10-25 15:36:07.742 3282-3282 DEBUG crash_dump32 A #45 pc 000a43e2 /data/app/com.tx.face.test-Fv7zJJp3nsw7Yarj77H5mQ==/base.apk (org.junit.runners.model.FrameworkMethod.invokeExplosively+10)
2024-10-25 15:36:07.742 3282-3282 DEBUG crash_dump32 A #48 pc 0009d15e /data/app/com.tx.face.test-Fv7zJJp3nsw7Yarj77H5mQ==/base.apk (org.junit.internal.runners.statements.InvokeMethod.evaluate+14)
2024-10-25 15:36:07.742 3282-3282 DEBUG crash_dump32 A #51 pc 000a2da8 /data/app/com.tx.face.test-Fv7zJJp3nsw7Yarj77H5mQ==/base.apk (org.junit.runners.ParentRunner$3.evaluate+4)
2024-10-25 15:36:07.743 3282-3282 DEBUG crash_dump32 A #54 pc 000a1b7c /data/app/com.tx.face.test-Fv7zJJp3nsw7Yarj77H5mQ==/base.apk (org.junit.runners.BlockJUnit4ClassRunner$1.evaluate+16)
2024-10-25 15:36:07.743 3282-3282 DEBUG crash_dump32 A #57 pc 000a37f0 /data/app/com.tx.face.test-Fv7zJJp3nsw7Yarj77H5mQ==/base.apk (org.junit.runners.ParentRunner.runLeaf+16)
2024-10-25 15:36:07.743 3282-3282 DEBUG crash_dump32 A #60 pc 000a229e /data/app/com.tx.face.test-Fv7zJJp3nsw7Yarj77H5mQ==/base.apk (org.junit.runners.BlockJUnit4ClassRunner.runChild+38)
2024-10-25 15:36:07.744 3282-3282 DEBUG crash_dump32 A #63 pc 000a225e /data/app/com.tx.face.test-Fv7zJJp3nsw7Yarj77H5mQ==/base.apk (org.junit.runners.BlockJUnit4ClassRunner.runChild+6)
2024-10-25 15:36:07.744 3282-3282 DEBUG crash_dump32 A #66 pc 000a2e10 /data/app/com.tx.face.test-Fv7zJJp3nsw7Yarj77H5mQ==/base.apk (org.junit.runners.ParentRunner$4.run+12)
2024-10-25 15:36:07.744 3282-3282 DEBUG crash_dump32 A #69 pc 000a2d2c /data/app/com.tx.face.test-Fv7zJJp3nsw7Yarj77H5mQ==/base.apk (org.junit.runners.ParentRunner$1.schedule)
2024-10-25 15:36:07.744 3282-3282 DEBUG crash_dump32 A #72 pc 000a37a6 /data/app/com.tx.face.test-Fv7zJJp3nsw7Yarj77H5mQ==/base.apk (org.junit.runners.ParentRunner.runChildren+50)
2024-10-25 15:36:07.744 3282-3282 DEBUG crash_dump32 A #75 pc 000a3444 /data/app/com.tx.face.test-Fv7zJJp3nsw7Yarj77H5mQ==/base.apk (org.junit.runners.ParentRunner.access$100)
2024-10-25 15:36:07.745 3282-3282 DEBUG crash_dump32 A #78 pc 000a2d6c /data/app/com.tx.face.test-Fv7zJJp3nsw7Yarj77H5mQ==/base.apk (org.junit.runners.ParentRunner$2.evaluate+8)
2024-10-25 15:36:07.745 3282-3282 DEBUG crash_dump32 A #81 pc 000a2da8 /data/app/com.tx.face.test-Fv7zJJp3nsw7Yarj77H5mQ==/base.apk (org.junit.runners.ParentRunner$3.evaluate+4)
2024-10-25 15:36:07.745 3282-3282 DEBUG crash_dump32 A #84 pc 000a3714 /data/app/com.tx.face.test-Fv7zJJp3nsw7Yarj77H5mQ==/base.apk (org.junit.runners.ParentRunner.run+32)
2024-10-25 15:36:07.745 3282-3282 DEBUG crash_dump32 A #87 pc 0006e730 /data/app/com.tx.face.test-Fv7zJJp3nsw7Yarj77H5mQ==/base.apk (androidx.test.ext.junit.runners.AndroidJUnit4.run+4)
2024-10-25 15:36:07.746 3282-3282 DEBUG crash_dump32 A #90 pc 000a3ed0 /data/app/com.tx.face.test-Fv7zJJp3nsw7Yarj77H5mQ==/base.apk (org.junit.runners.Suite.runChild)
2024-10-25 15:36:07.746 3282-3282 DEBUG crash_dump32 A #93 pc 000a3eb6 /data/app/com.tx.face.test-Fv7zJJp3nsw7Yarj77H5mQ==/base.apk (org.junit.runners.Suite.runChild+6)
2024-10-25 15:36:07.746 3282-3282 DEBUG crash_dump32 A #96 pc 000a2e10 /data/app/com.tx.face.test-Fv7zJJp3nsw7Yarj77H5mQ==/base.apk (org.junit.runners.ParentRunner$4.run+12)
2024-10-25 15:36:07.746 3282-3282 DEBUG crash_dump32 A #99 pc 000a2d2c /data/app/com.tx.face.test-Fv7zJJp3nsw7Yarj77H5mQ==/base.apk (org.junit.runners.ParentRunner$1.schedule)
2024-10-25 15:36:07.747 3282-3282 DEBUG crash_dump32 A #102 pc 000a37a6 /data/app/com.tx.face.test-Fv7zJJp3nsw7Yarj77H5mQ==/base.apk (org.junit.runners.ParentRunner.runChildren+50)
2024-10-25 15:36:07.747 3282-3282 DEBUG crash_dump32 A #105 pc 000a3444 /data/app/com.tx.face.test-Fv7zJJp3nsw7Yarj77H5mQ==/base.apk (org.junit.runners.ParentRunner.access$100)
2024-10-25 15:36:07.747 3282-3282 DEBUG crash_dump32 A #108 pc 000a2d6c /data/app/com.tx.face.test-Fv7zJJp3nsw7Yarj77H5mQ==/base.apk (org.junit.runners.ParentRunner$2.evaluate+8)
2024-10-25 15:36:07.747 3282-3282 DEBUG crash_dump32 A #111 pc 000a2da8 /data/app/com.tx.face.test-Fv7zJJp3nsw7Yarj77H5mQ==/base.apk (org.junit.runners.ParentRunner$3.evaluate+4)
2024-10-25 15:36:07.748 3282-3282 DEBUG crash_dump32 A #114 pc 000a3714 /data/app/com.tx.face.test-Fv7zJJp3nsw7Yarj77H5mQ==/base.apk (org.junit.runners.ParentRunner.run+32)
2024-10-25 15:36:07.748 3282-3282 DEBUG crash_dump32 A #117 pc 0009fd6e /data/app/com.tx.face.test-Fv7zJJp3nsw7Yarj77H5mQ==/base.apk (org.junit.runner.JUnitCore.run+50)
2024-10-25 15:36:07.748 3282-3282 DEBUG crash_dump32 A #120 pc 0009fd20 /data/app/com.tx.face.test-Fv7zJJp3nsw7Yarj77H5mQ==/base.apk (org.junit.runner.JUnitCore.run+8)
2024-10-25 15:36:07.748 3282-3282 DEBUG crash_dump32 A #123 pc 00074ae4 /data/app/com.tx.face.test-Fv7zJJp3nsw7Yarj77H5mQ==/base.apk (androidx.test.internal.runner.TestExecutor.execute+16)
2024-10-25 15:36:07.748 3282-3282 DEBUG crash_dump32 A #126 pc 00074b90 /data/app/com.tx.face.test-Fv7zJJp3nsw7Yarj77H5mQ==/base.apk (androidx.test.internal.runner.TestExecutor.execute+20)
2024-10-25 15:36:07.749 3282-3282 DEBUG crash_dump32 A #129 pc 0007f756 /data/app/com.tx.face.test-Fv7zJJp3nsw7Yarj77H5mQ==/base.apk (androidx.test.runner.AndroidJUnitRunner.onStart+266)
2024-10-25 15:36:19.413 1899-2018 PasspointManager system_server E No app ops listener found for com.tx.face
2024-10-25 15:36:19.888 1899-2018 PasspointManager system_server E No app ops listener found for com.tx.face.test
#### 附加信息
*如果你还有其他需要提供的信息,可以在这里填写(可以提供截图、视频等)。*
Contributor guide
Research direction
Start with JSONObject.toJSONString and the JSONWriterUTF16.writeNull stack entry, using the supplied testJso2 reproduction on Android 11 with fastjson2 2.0.53. Investigate the crash when three or more null fields are serialized with WriteMapNullValue, then verify that the expected JSON is produced without a SIGBUS.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- android, java
- Domain
- mobile-dev
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100