Repository navigation
2.0.66.android5: port fixes from main - #7895
Merged
Merged
Conversation
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.
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
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
FieldReaderBigDecimalFieldalso gains main'sFieldReaderBigDecimalNullOnError branch -- 11 sibling readers already have it; without it the ported resync contract has no consumer and the three nullOnError* tests cannot pass.Double.isFinite/Float.isFiniteadded keeping this branch's simpler condition shape.Issue7783ported withouttest_specialAsString(WriteFloatSpecialAsStringdoes not exist here).ObjectWriterProvider.getObjectWriter(Type, String, Locale)hunk N/A (method absent).FieldWriterDoubleFieldnow readsthis.features-- the base constructor ORs the sentinel bit into its own parameter, and the subclass captured the flag from its own unmodified parameter.Issue7734adapted to@JSONField(format = "string").toJSONObjectFieldWriterObject.isTypeMatch(with null guard) + thegetObjectWriterrefactor + thetoJSONObjectre-resolution block withJSON.toJSONconversion for non-adapter writers.DynamicClassLoaderdoes not exist on this branch (no ASM codegen).ObjectWriterCreatoralways passes the getter toFieldWriterCharMethod(line 876) and the method is invoked (line 31). The existing guard test is extended with d5c30ac's f2 assertions.android5-specific adaptations
JSONReaderJSONBkeeps this branch'sZoneId.SHANGHAI_ZONE_ID_NAMEspelling (android8 usesDateUtils.); theMAX_DECIMAL_LEVELblock is inserted ahead of it.JSONReaderdrops the now-unused specific import ofdefaultDecimalMaxScale(checkstyle UnusedImports) -- the inline scale check was replaced bycheckDecimalScale(scale), which resolves through the existingJSONFactory.*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
中文
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)。