Skip to content

Fix avro bugs - #745

Merged
cowtowncoder merged 7 commits into
FasterXML:3.xfrom
pjfanning:avro
Aug 16, 2026
Merged

Fix avro bugs#745
cowtowncoder merged 7 commits into
FasterXML:3.xfrom
pjfanning:avro

Conversation

@pjfanning

Copy link
Copy Markdown
Member

Claude AI found these - they look plausible to me but I must admit to not being an Avro expert.

Fix 1: _resolveBigDecimalIndex — dead code / wrong union branch

AvroWriteContext.java:441-448 — The second if (t == Type.DOUBLE) was dead code (unreachable after the first). The intent was to prefer STRING/BYTES (which preserve BigDecimal precision via logical types) and fall back to DOUBLE. Fixed to check STRING and BYTES first, with DOUBLE as the fallback match.

Fix 2: Stale type variable in both _createRecord overloads

AvroWriteContext.java:157-168, 179-195 — Both overloads captured type before union resolution but never updated it afterward. The MAP guard checked the stale type (still UNION) and would never trigger if the resolved schema was a MAP. Fixed by re-reading type = schema.getType() after union resolution.

Fix 3: Integer defaults stored as float — precision loss

AvroFieldDefaulters.java:31-38 — VALUE_NUMBER_INT cases used FloatDefaults (24-bit mantissa), silently losing precision for int values > 16,777,216 and all long values. IntDefaults and LongDefaults already existed in ScalarDefaults.java but were unused. Fixed to use IntDefaults for INT and LongDefaults for LONG/BIG_INTEGER.

@github-actions

github-actions Bot commented Aug 13, 2026

Copy link
Copy Markdown

🧪 Code Coverage Report

Coverage Type Coverage Change
📝 Instructions 77.07% 📈 +0.10%
🔀 Branches 68.23% 📈 +0.10%

Comment thread avro/src/test/java/tools/jackson/dataformat/avro/BugFixTest.java Outdated
@cowtowncoder cowtowncoder changed the title fix avro bugs Fix avro bugs Aug 16, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Class name should follow naming convention, no underscores.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is a pre-existing class - do you want me to rename the file?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I renamed the class but there are other classes in this repo that have this non-standard naming

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah sorry, did not realize. Thank you for renaming, going forward will try to keep an eye on additions.

@cowtowncoder

Copy link
Copy Markdown
Member

Looks good, but does require entry in release-notes/VERSION-2.x, something like:

#745: (avro) Misc schema bug fixes

(or ideally more specific -- but something)

@pjfanning

pjfanning commented Aug 16, 2026

Copy link
Copy Markdown
Member Author

Looks good, but does require entry in release-notes/VERSION-2.x, something like:

#745: (avro) Misc schema bug fixes

(or ideally more specific -- but something)

Added an entry to VERSION file - this PR is targeted at 3.x so I added the entry under 3.3.0.

@cowtowncoder

Copy link
Copy Markdown
Member

Hmmh. Claude found many issues here, will need to massage a bit...

@cowtowncoder cowtowncoder added this to the 3.3.0 milestone Aug 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants