Skip to content

2.0.66.android5: port fixes from main - #7895

Merged
wenshao merged 2 commits into
android5from
port/2.0.66.android5
Oct 16, 2026
Merged

wenshao merged 2 commits into
android5from
port/2.0.66.android5

Conversation

@wenshao

@wenshao wenshao commented Oct 15, 2026

Copy link
Copy Markdown
Member

Mirror of the 2.0.66.android8 port (port/2.0.66.android8), applying the same six fix groups to android5. The set of changed production lines is byte-identical to the android8 port (260 added lines, verified by diff-of-diffs).

Ported fixes

Fix Upstream Branch notes
JSONB decimal scale hardening #7857 / PR #7858 (6 commits) Full port of the guard series. FieldReaderBigDecimalField also gains main's FieldReaderBigDecimal NullOnError branch -- 11 sibling readers already have it; without it the ported resync contract has no consumer and the three nullOnError* tests cannot pass.
WriteClassName NaN/Infinity suffix #7783 / 6fd9ba1 Double.isFinite / Float.isFinite added keeping this branch's simpler condition shape. Issue7783 ported without test_specialAsString (WriteFloatSpecialAsString does not exist here).
format "string" sentinel for BigDecimal #7734 / 7da8818 ObjectWriterProvider.getObjectWriter(Type, String, Locale) hunk N/A (method absent). FieldWriterDoubleField now reads this.features -- the base constructor ORs the sentinel bit into its own parameter, and the subclass captured the flag from its own unmodified parameter. Issue7734 adapted to @JSONField(format = "string").
Cached field writer validated by value type in toJSONObject #7714 / PR #7739 FieldWriterObject.isTypeMatch (with null guard) + the getObjectWriter refactor + the toJSONObject re-resolution block with JSON.toJSON conversion for non-adapter writers.
DynamicClassLoader foreign parent #7869 / PR #7873 N/A -- DynamicClassLoader does not exist on this branch (no ASM codegen).
Character field getter discarded #7719 / 7c4609f + d5c30ac N/A -- ObjectWriterCreator always passes the getter to FieldWriterCharMethod (line 876) and the method is invoked (line 31). The existing guard test is extended with d5c30ac's f2 assertions.

android5-specific adaptations

  • JSONReaderJSONB keeps this branch's ZoneId.SHANGHAI_ZONE_ID_NAME spelling (android8 uses DateUtils.); the MAX_DECIMAL_LEVEL block is inserted ahead of it.
  • JSONReader drops the now-unused specific import of defaultDecimalMaxScale (checkstyle UnusedImports) -- the inline scale check was replaced by checkDecimalScale(scale), which resolves through the existing JSONFactory.* wildcard import. This is the only line the android5 port deletes beyond the android8 port (diff-of-diffs: 260 added lines identical, 57 vs 56 deleted lines).

Verification

  • 34 ported tests green (Issue7857 19, Issue7783 4, Issue7734 4, Issue7714 4, ObjectWriter14Test 3)
  • Full core suite BUILD SUCCESS (JDK 8)
中文

2.0.66.android8 port(见对应 PR)的镜像,把同样 6 组修复同步到 android5 分支。改动行与 android8 port 逐字节一致(260 行新增,diff-of-diffs 核验)。

android5 特有适配:

  • JSONReaderJSONB 保留本分支的 ZoneId.SHANGHAI_ZONE_ID_NAME 拼写(android8 用 DateUtils. 前缀),MAX_DECIMAL_LEVEL 块插在其前。
  • JSONReader 删掉因内联检查被 checkDecimalScale(scale) 替换而悬空的 defaultDecimalMaxScale 具体导入(checkstyle UnusedImports)——checkDecimalScale 经既有 JSONFactory.* 通配符导入解析。这是 android5 port 相对 android8 port 唯一多删的一行(diff-of-diffs:新增 260 行一致,删除 57 vs 56)。

验证:34 条移植测试全绿;core 全套件 BUILD SUCCESS(JDK 8)。

wenshao and others added 2 commits October 15, 2026 19:18
Mirror of the 2.0.66.android8 port (port/2.0.66.android8, commit
3f78e99). The set of changed production lines is byte-identical to
the android8 port (260 added lines, verified by diff-of-diffs);
android5-specific notes are collected at the bottom.

* fix: bound JSONB decimal scale to prevent excessive CPU usage (#7857)

Mirror of main's six-commit hardening series (35d225b, 9d43412,
29efe4d, 73bac1f, c27f0e7, 333cb52, merged as PR #7858). A
hostile BC_DECIMAL record can carry an enormous scale (CPU burn inside
BigDecimal), a nested decimal as its own scale field (unbounded
recursion to StackOverflowError), or a non-int32 scale encoding. The
port adds JSONFactory.checkDecimalScale(int)/(BigDecimal), routes every
BC_DECIMAL read in JSONReaderJSONB through the new readDecimalScale /
readDecimalUnscaled / checkDecimalScaleSum guards (8 switch arms plus
the readBigDecimal fast paths and skipValue), caps decimal
scale/unscaled nesting at MAX_DECIMAL_LEVEL = 128 (small-stack margin),
wraps string-to-BigDecimal conversions with checkDecimalScale, and
guards the writer side (JSONWriterJSONB.writeDecimal) and JSONBDump the
same way. main's isInt32Num/isInt32Byte/isInt32Short helpers are added
to JSONB (this branch did not have them).

Branch adaptations (same shape as android8):
- JSONReaderJSONB gains `import static com.alibaba.fastjson2.JSONB.*;`
  (mirroring main's import shape) in place of the JSONB.typeName
  single-type import; unqualified calls do not resolve across classes
  without it.
- The readBigDecimal fast paths keep this branch's getInt/UNSAFE.getLong
  forms (no getIntBE/check3/check7 here); only the guards are added.
- readFloatValue/readDoubleValue BC_DECIMAL arms also take main's
  intValue -> floatValue/doubleValue corrections; this branch had the
  same latent bug.
- FieldReaderBigDecimalField gains main's FieldReaderBigDecimal
  NullOnError branch (try/catch -> null when the feature is set).
  Eleven sibling readers on this branch already implement NullOnError;
  the field-based BigDecimal reader did not, so the ported resync
  contract (the record is fully consumed before the throw and
  NullOnError readers resume at the record boundary) had no consumer
  here, and the three nullOnError* tests in Issue7857 could not pass.

(cherry picked from the PR #7858 series, manually applied)

* fix: WriteClassName produces illegal JSON for NaN and Infinity (#7783)

Mirror of main 6fd9ba1. Non-finite values must not take the D/F
suffix: Double.isFinite / Float.isFinite are added to the existing
WriteClassName condition, keeping this branch's simpler condition shape
(no WriteNonStringKeyAsString / NotWriteNumberClassName checks here).
Test adaptation: Issue7783 is ported without test_specialAsString --
JSONWriter.Feature.WriteFloatSpecialAsString does not exist on this
branch.

(cherry picked from commit 6fd9ba1, manually applied)

* fix: treat format "string" as WriteNonStringValueAsString for BigDecimal (#7734)

Mirror of main 7da8818. The "string" sentinel (from
@jsonformat(shape = STRING) on main, or @JSONField(format = "string")
here) must not be compiled into a DecimalFormat pattern. Ports the
FieldWriter constructor guard and the BigDecimal / BigDecimal[] writer
resolution arms.

Branch adaptations (same shape as android8):
- main's ObjectWriterProvider.getObjectWriter(Type, String, Locale)
  hunk is not applicable: the method does not exist on this branch.
- FieldWriterDoubleField now reads this.features when computing
  writeNonStringValueAsString. The base FieldWriter constructor ORs the
  sentinel bit into its own parameter before assigning this.features;
  the subclass captured the flag from its own (unmodified) parameter,
  so the sentinel was silently lost for Double fields. main reads the
  feature at write time and is unaffected. The same capture pattern
  remains in FieldWriterDoubleMethod / FieldWriterFloatMethod /
  FieldWriterInt16 / FieldWriterInt8 -- out of the ported suite's
  scope.
- Issue7734 is adapted to drive the sentinel through
  @JSONField(format = "string"): this branch's BeanUtils does not
  process @jsonformat, while the FieldWriter sentinel ->
  WriteNonStringValueAsString mapping (FieldWriter.java:74) makes the
  @JSONField path exercise the same contract. 4/4 green.

(cherry picked from commit 7da8818, manually applied)

* fix: validate cached field writer by value type in toJSONObject (#7714)

Mirror of main 6c29d27 + 514f3af (merged as PR #7739). Ports
FieldWriterObject.isTypeMatch (final form, with the null guard and
javadoc), the getObjectWriter refactor to share the predicate, and the
ObjectWriterAdapter.toJSONObject re-resolution block including the
JSON.toJSON conversion for non-adapter writers. This branch's
toJSONObject had the same unguarded reuse (issue #7714:
ClassCastException wrapped as "key get error", and subclass values
silently dropped). Issue7714 ported verbatim, 4/4 green.

(cherry picked from commits 6c29d27 and 514f3af, manually applied)

* fix: use own ClassLoader as parent when context ClassLoader loads a foreign fastjson2 (#7869)

Not applicable to this branch -- DynamicClassLoader does not exist here
(no ASM codegen), so the foreign-parent failure mode of main #7873
cannot occur.

* fix: the getter method is discarded when serializing character fields (#7719)

Not applicable to this branch -- main's shared FieldWriterCharValue /
FieldWriterChar constructors dropped the method argument; here
ObjectWriterCreator always passes the getter to FieldWriterCharMethod
(ObjectWriterCreator.java:876) and FieldWriterCharMethod invokes it
(line 31). The guard test was already ported from main 7c4609f as
ObjectWriter14Test; it is extended with the f2 assertions from
d5c30ac (primitive char getter returning lowercase while the backing
field holds uppercase), adapted to this branch's JSONPath.of().eval()
spelling. 3/3 green.

android5-specific adaptations:
- JSONReaderJSONB keeps this branch's ZoneId.SHANGHAI_ZONE_ID_NAME
  spelling (android8 uses DateUtils.SHANGHAI_ZONE_ID_NAME); the
  MAX_DECIMAL_LEVEL block is inserted ahead of it.
- JSONReader drops the now-unused specific import of
  defaultDecimalMaxScale (checkstyle UnusedImports) -- the inline scale
  check was replaced by checkDecimalScale(scale), which resolves
  through the existing JSONFactory.* wildcard import. This is the only
  line the android5 port deletes beyond the android8 port
  (diff-of-diffs: 260 added lines identical, 57 vs 56 deleted lines).

Verification: 34 ported tests green (Issue7857 19, Issue7783 4,
Issue7734 4, Issue7714 4, ObjectWriter14Test 3); full core suite
BUILD SUCCESS (JDK 8).

Co-authored-by: Qwen-Coder <qwen-coder@alibabacloud.com>
ubuntu-20.04 runners are retired, so every android5 CI run since
2025-12 has been auto-cancelled after queueing 24h with no runner
pickup -- jobs never executed. Switch the matrix to ubuntu-24.04,
matching main's ci.yaml.
@wenshao
wenshao merged commit 4dce036 into android5 Oct 16, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant