From 34981c30a78e8bbd7791131059a9210f9928b62c Mon Sep 17 00:00:00 2001
From: 刘光辉 <347230014@qq.com>
Date: 星期四, 17 九月 2026 09:24:09 +0800
Subject: [PATCH] Merge remote-tracking branch 'origin/master' into master
---
jnpf-biz-common/jnpf-biz-common-audit/src/test/java/jnpf/bizcommon/audit/service/AuditL0ParseFailureProbe.java | 128 ++++++++++++++++++++++++++++++++++++++++++
1 files changed, 128 insertions(+), 0 deletions(-)
diff --git a/jnpf-biz-common/jnpf-biz-common-audit/src/test/java/jnpf/bizcommon/audit/service/AuditL0ParseFailureProbe.java b/jnpf-biz-common/jnpf-biz-common-audit/src/test/java/jnpf/bizcommon/audit/service/AuditL0ParseFailureProbe.java
new file mode 100644
index 0000000..1176cf3
--- /dev/null
+++ b/jnpf-biz-common/jnpf-biz-common-audit/src/test/java/jnpf/bizcommon/audit/service/AuditL0ParseFailureProbe.java
@@ -0,0 +1,128 @@
+package jnpf.bizcommon.audit.service;
+
+import com.alibaba.fastjson.JSONException;
+import jnpf.util.JsonUtil;
+
+import java.lang.reflect.Method;
+import java.util.Map;
+
+/**
+ * 灞� 0 璐熺紦瀛樼殑**澶辫触鍒嗙被**鎺㈤拡锛圕1 浜岃疆璇勫 I-3 鐨勮瘉鎹剼鏈級銆�
+ *
+ * <p>涓轰粈涔堝繀椤诲疄娴嬭�屼笉鑳芥帹锛歿@code AuditFormRegistry.deterministicParseFailure} 鍐冲畾
+ * 銆岃繖娆¤В鏋愬け璐ヨ涓嶈杩涜礋缂撳瓨銆嶃�傚垽閿欑殑浠d环涓嶅绉扳�斺�旀妸**鐬椂**澶辫触鍒ゆ垚纭畾鎬э紝璇ヨ〃鍗�
+ * 浠庢闈欓粯涓嶈瀹¤鐩村埌閲嶅惎锛堢紦瀛樻槸杩涚▼绾с�佹棤杩囨湡鐨勶級锛涘弽杩囨潵鍙槸澶氭煡涓�娆″簱銆�
+ * L061 鈶� 璁扮殑灏辨槸杩欎釜鍧戯紝鑰屽畠褰撴椂姝f槸**鎺�**鍑烘潵鐨勯粦鍚嶅崟琚疄璇佹帹缈荤殑銆�
+ *
+ * <p>鏈帰閽堝杺鍚勭鐣稿舰杈撳叆缁� {@code JsonUtil.getJsonToList}锛堝眰 0 鍙嶆煡涓昏〃鐢ㄧ殑姝f槸瀹冿級锛�
+ * 鎵撳嵃鐪熷疄寮傚父閾撅紝鍐嶈 {@code deterministicParseFailure} 瀵瑰畠鍋氬垽瀹氾紝閫愭潯鏂█銆�
+ *
+ * <p>閫�鍑虹爜锛�0 = 鍏ㄧ豢 / 1 = 鏈夋柇瑷�澶辫触銆�**涓嶈繛搴撱�佷笉璧峰鍣�**锛岀绾с��
+ */
+public final class AuditL0ParseFailureProbe {
+
+ private static int passed;
+ private static int failed;
+
+ public static void main(String[] args) throws Exception {
+ Method decide = AuditFormRegistry.class
+ .getDeclaredMethod("deterministicParseFailure", Throwable.class);
+ decide.setAccessible(true);
+
+ System.out.println("=== 灞�0 瑙f瀽澶辫触鍒嗙被鎺㈤拡锛坒astjson 瀹炴祴閾惧舰 + 鐧藉悕鍗曞垽瀹氾級===");
+
+ // 鈶� 鍚勭被璇硶閿欒锛氬簲鎶� JSONException 鈫� 纭畾鎬� 鈫� 鍙紦瀛�
+ expect(decide, "鎴柇鐨� JSON", "[{\"table\":\"lims_x\"", true);
+ expect(decide, "椤跺眰闈炴暟缁�", "{\"table\":\"lims_x\"}", true);
+ expect(decide, "鍏冪礌闈炲璞�", "[1,2,3]", true);
+ expect(decide, "绌轰覆浠ュ鐨勭函鍨冨溇", "not json at all", true);
+
+ // 鈶� 鐣稿舰 Unicode 杞箟锛�**瀹炴祴鎶涜8鐨� NumberFormatException銆佷笉琚寘瑁呮垚 JSONException**
+ // 锛坈odex 鐙珛澶嶆牳鍙戠幇锛屾湰鎺㈤拡鐙珛澶嶆牳鍏跺彂鐜帮級銆傚畠鍚屾牱鏄枃鏈殑鍥烘湁灞炴�� 鈫� 纭畾鎬с��
+ expect(decide, "鐣稿舰 Unicode 杞箟 \\uZZZZ", "[{\"table\":\"\\uZZZZ\"}]", true);
+
+ // 鈶� 鐬椂鏁呴殰锛�**缁濅笉鑳�**鍒ゆ垚纭畾鎬�
+ assertDecide(decide, "StackOverflowError锛堟繁灞傚祵濂楃殑鐪熷疄褰㈡�侊級",
+ new StackOverflowError(), false);
+ assertDecide(decide, "OutOfMemoryError", new OutOfMemoryError(), false);
+ assertDecide(decide, "绾跨▼涓柇", new InterruptedException(), false);
+ assertDecide(decide, "鍖呬簡涓�灞傜殑 SOE锛堟睜绾跨▼褰㈡�侊級",
+ new RuntimeException(new StackOverflowError()), false);
+
+ // 鈶� 鑷幆 cause 閾句笉鑳芥妸閬嶅巻鍗℃锛圠061 鐨勫啓娉曡姹傦級銆�
+ // 娉ㄦ剰**涓嶈兘**鐢� `e.initCause(e)` 鏋勯�犫�斺�擩DK 鐩存帴鎶� IllegalArgumentException:
+ // Self-causation not permitted锛堟湰鎺㈤拡绗竴鐗堝氨杩欎箞鍐欑殑锛屽綋鍦虹偢浜嗭級銆�
+ // 鐪熷疄鐨勮嚜鐜彧鍙兘鏉ヨ嚜瑕嗙洊浜� getCause() 鐨勮嚜瀹氫箟寮傚父锛屾墍浠ョ収閭d釜褰㈡�侀�犮��
+ assertDecide(decide, "鑷幆 cause 閾句笉姝诲惊鐜紙瑕嗙洊 getCause 鐨勫舰鎬侊級",
+ new SelfCausedException(), false);
+
+ System.out.println();
+ System.out.printf("=== 灞�0 澶辫触鍒嗙被鏂█锛�%d 閫氳繃 / %d 澶辫触 ===%n", passed, failed);
+ if (failed > 0) {
+ System.exit(1);
+ }
+ }
+
+ /** 鐪熷杺涓�娈电暩褰� JSON锛屾墦鍗板畠瀹為檯鎶涚殑寮傚父閾撅紝鍐嶆柇瑷�鐧藉悕鍗曠殑鍒ゅ畾銆� */
+ private static void expect(Method decide, String label, String json, boolean deterministic) {
+ Throwable caught = null;
+ try {
+ JsonUtil.getJsonToList(json, Map.class);
+ } catch (Throwable t) {
+ caught = t;
+ }
+ if (caught == null) {
+ // 娌℃姏寮傚父涔熸槸鏈夋晥淇℃伅锛堣鏄� fastjson 瀹藉鍦版帴鍙椾簡瀹冿級锛屼笉绠楀け璐ワ紝浣嗚鎵撳嵃鍑烘潵
+ System.out.printf(" [INFO] %s 鈫� 鏈姏寮傚父锛坒astjson 鎺ュ彈浜嗚繖娈佃緭鍏ワ級%n", label);
+ return;
+ }
+ System.out.printf(" 閾惧舰 %-28s 鈫� %s%n", label, chain(caught));
+ assertDecide(decide, label, caught, deterministic);
+ }
+
+ private static void assertDecide(Method decide, String label, Throwable t, boolean expected) {
+ boolean actual;
+ try {
+ actual = (Boolean) decide.invoke(null, t);
+ } catch (Exception e) {
+ System.out.printf(" [FAIL] %s 鈫� 鍒ゅ畾鏂规硶鑷韩鎶涘紓甯革細%s%n", label, e);
+ failed++;
+ return;
+ }
+ if (actual == expected) {
+ System.out.printf(" [PASS] %s 鈫� %s%n", label,
+ expected ? "纭畾鎬э紙鍙礋缂撳瓨锛�" : "鐬椂锛堜笉缂撳瓨锛�");
+ passed++;
+ } else {
+ System.out.printf(" [FAIL] %s 鈫� 鍒や负%s锛屽簲涓�%s%s%n", label,
+ actual ? "纭畾鎬�" : "鐬椂", expected ? "纭畾鎬�" : "鐬椂",
+ expected ? "" : " 鈫� 鍗遍櫓鏂瑰悜锛氱灛鏃跺け璐ヨ姘镐箙璐熺紦瀛� = 璇ヨ〃鍗曢潤榛樹笉鍐嶈瀹¤");
+ failed++;
+ }
+ }
+
+ private static String chain(Throwable t) {
+ StringBuilder sb = new StringBuilder();
+ for (Throwable c = t; c != null; c = (c.getCause() == c ? null : c.getCause())) {
+ if (sb.length() > 0) {
+ sb.append(" 鈫� ");
+ }
+ sb.append(c.getClass().getSimpleName());
+ if (c instanceof JSONException || c instanceof NumberFormatException) {
+ sb.append("*"); // * = 鍛戒腑鐧藉悕鍗曠殑閭d竴鐜�
+ }
+ }
+ return sb.toString();
+ }
+
+ /** 鍞竴鑳介�犲嚭鑷幆 cause 鐨勫舰鎬侊細瑕嗙洊 getCause() 杩斿洖鑷繁銆� */
+ private static final class SelfCausedException extends RuntimeException {
+ @Override
+ public synchronized Throwable getCause() {
+ return this;
+ }
+ }
+
+ private AuditL0ParseFailureProbe() {
+ }
+}
--
Gitblit v1.8.0