You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@avro.apache.org by "RyanSkraba (via GitHub)" <gi...@apache.org> on 2026/05/10 11:58:36 UTC
[PR] AVRO-4209: [java] Reflect correctly on recursive schemas [avro]
RyanSkraba opened a new pull request, #3765:
URL: https://github.com/apache/avro/pull/3765
## What is the purpose of the change
When reflecting on a class with a recursive reference, make sure that the schemas are parsed and emitted in the correct order.
Currently after #3304, schemas are defined to be emitted when they are completely resolved (i.e. a RECORD schema is put into the context after all its fields have also been completely resolved). Unfortunately for recursive data where a field is the same class as a parent structure, this causes a stack overflow.
This can be resolved by noting that the record schema is "in progress" by adding it to the list *before* it is fully resolved. In order to keep the right order in the map in the end, it needs to be removed and re-added after the fields are finished resolving.
## Verifying this change
*(Please pick one of the following options)*
This change added tests to `TestReflect`. Current tests that check the schema order still pass.
## Documentation
- Does this pull request introduce a new feature? **no**
- If yes, how is the feature documented? **not applicable**
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: dev-unsubscribe@avro.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] AVRO-4209: [java] Reflect correctly on recursive schemas [avro]
Posted by "RyanSkraba (via GitHub)" <gi...@apache.org>.
RyanSkraba commented on PR #3765:
URL: https://github.com/apache/avro/pull/3765#issuecomment-4423732672
Cherry-picked to [branch-1.12](https://github.com/apache/avro/commit/ace4a89ae4e12382299e1a6cd87a2400c97c3045).
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@avro.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] AVRO-4209: [java] Reflect correctly on recursive schemas [avro]
Posted by "RyanSkraba (via GitHub)" <gi...@apache.org>.
RyanSkraba merged PR #3765:
URL: https://github.com/apache/avro/pull/3765
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: dev-unsubscribe@avro.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] AVRO-4209: [java] Reflect correctly on recursive schemas [avro]
Posted by "github-advanced-security[bot] (via GitHub)" <gi...@apache.org>.
github-advanced-security[bot] commented on code in PR #3765:
URL: https://github.com/apache/avro/pull/3765#discussion_r3214842462
##########
lang/java/avro/src/test/java/org/apache/avro/reflect/TestReflect.java:
##########
@@ -1416,4 +1417,55 @@
+ "{\"name\":\"foo\",\"type\":\"int\",\"doc\":\"Some Documentation\"}" + "]}");
}
+ // test recursive record schema
+ public static class TreeNode {
Review Comment:
## CodeQL / Inconsistent equals and hashCode
Class TreeNode overrides [equals](1) but not hashCode.
[Show more details](https://github.com/apache/avro/security/code-scanning/3361)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@avro.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] AVRO-4209: [java] Reflect correctly on recursive schemas [avro]
Posted by "opwvhk (via GitHub)" <gi...@apache.org>.
opwvhk commented on code in PR #3765:
URL: https://github.com/apache/avro/pull/3765#discussion_r3214850073
##########
lang/java/avro/src/test/java/org/apache/avro/reflect/TestReflect.java:
##########
@@ -1416,4 +1417,55 @@ void avroDoc() {
+ "{\"name\":\"foo\",\"type\":\"int\",\"doc\":\"Some Documentation\"}" + "]}");
}
+ // test recursive record schema
+ public static class TreeNode {
+ public int value = 0;
+ @Nullable
+ public TreeNode left;
+ @Nullable
+ public TreeNode right;
+
+ public TreeNode() {
+ }
+
+ public TreeNode(int value) {
+ this.value = value;
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (!(o instanceof TreeNode))
+ return false;
+ TreeNode that = (TreeNode) o;
+ if (value != that.value || !Objects.equals(left, that.left) || !Objects.equals(right, that.right))
+ return false;
+ return true;
+ }
Review Comment:
```suggestion
}
@Override
public int hashCode() {
return Objects.hash(value, left, right);
}
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@avro.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org