You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@fory.apache.org by "mandrean (via GitHub)" <gi...@apache.org> on 2026/02/16 12:30:31 UTC

[PR] fix(java): Support TreeSet subclasses without Comparator constructor in SortedSetSerializer [fory]

mandrean opened a new pull request, #3344:
URL: https://github.com/apache/fory/pull/3344

   ## Why?
   
   `SortedSetSerializer` unconditionally requires a `(Comparator)` constructor for all non-`TreeSet` subclasses. Java constructors are not inherited, so a `class ChildTreeSet extends TreeSet<String>` with only a no-arg constructor throws `UnsupportedOperationException` when registered with `SortedSetSerializer`.
   
   ## What does this PR do?
   
   Changes `SortedSetSerializer` to try the `(Comparator)` constructor first, and fall back to the no-arg constructor if not found. At deserialization time, uses whichever constructor is available. The no-arg fallback uses natural ordering, which is the common case for TreeSet subclasses.
   
   Only throws `UnsupportedOperationException` if neither constructor is found.
   
   ## Related issues
   
   - Fixes #3343
   
   ## Does this PR introduce any user-facing change?
   
   - [ ] Does this PR introduce any public API change?
   No. Existing behavior is preserved for classes that have a `(Comparator)` constructor. Classes that previously threw `UnsupportedOperationException` now work.
   
   - [ ] Does this PR introduce any binary protocol compatibility change?
   No. The write path is unchanged (size + comparator ref), and the read path still reads the same bytes in the same order. Only the post-read instantiation strategy differs (which constructor is used). Wire format is identical in both directions.
   
   ## Benchmark
   
   Not applicable; the constructor lookup happens once at serializer construction time, not per serialization. The runtime paths (`newCollection`) add a single null check (`if (comparatorConstructor != null)`) which is negligible.
   


-- 
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: commits-unsubscribe@fory.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@fory.apache.org
For additional commands, e-mail: commits-help@fory.apache.org


Re: [PR] fix(java): support TreeSet/TreeMap subclasses without Comparator constructor in SortedSet/SortedMapSerializer [fory]

Posted by "mandrean (via GitHub)" <gi...@apache.org>.
mandrean commented on code in PR #3344:
URL: https://github.com/apache/fory/pull/3344#discussion_r2815614162


##########
java/fory-core/src/main/java/org/apache/fory/serializer/collection/CollectionSerializers.java:
##########
@@ -217,7 +229,19 @@ public T newCollection(MemoryBuffer buffer) {
         collection = (T) new TreeSet(comparator);
       } else {
         try {
-          collection = (T) constructor.invoke(comparator);
+          if (comparatorConstructor != null) {
+            collection = (T) comparatorConstructor.invoke(comparator);
+          } else {
+            if (comparator != null) {
+              LOG.warn(

Review Comment:
   Yeah alright, fixed!



-- 
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: commits-unsubscribe@fory.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@fory.apache.org
For additional commands, e-mail: commits-help@fory.apache.org


Re: [PR] fix(java): Support TreeSet subclasses without Comparator constructor in SortedSetSerializer [fory]

Posted by "chaokunyang (via GitHub)" <gi...@apache.org>.
chaokunyang commented on PR #3344:
URL: https://github.com/apache/fory/pull/3344#issuecomment-3911807476

   It seems that the comparator is null if the treeset subclass don't pass comparator to parent class. In such cases, treeset Or treemap will just use key compareTo api for sort. So it's not a bug, could you remove the log and keep constructor branch. And could you ask check TreeMap? I think it has similar issue


-- 
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: commits-unsubscribe@fory.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@fory.apache.org
For additional commands, e-mail: commits-help@fory.apache.org


Re: [PR] fix(java): support TreeSet/TreeMap subclasses without Comparator constructor in SortedSet/SortedMapSerializer [fory]

Posted by "chaokunyang (via GitHub)" <gi...@apache.org>.
chaokunyang merged PR #3344:
URL: https://github.com/apache/fory/pull/3344


-- 
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: commits-unsubscribe@fory.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@fory.apache.org
For additional commands, e-mail: commits-help@fory.apache.org


Re: [PR] fix(java): Support TreeSet subclasses without Comparator constructor in SortedSetSerializer [fory]

Posted by "chaokunyang (via GitHub)" <gi...@apache.org>.
chaokunyang commented on code in PR #3344:
URL: https://github.com/apache/fory/pull/3344#discussion_r2814734405


##########
java/fory-core/src/main/java/org/apache/fory/serializer/collection/CollectionSerializers.java:
##########
@@ -217,7 +229,19 @@ public T newCollection(MemoryBuffer buffer) {
         collection = (T) new TreeSet(comparator);
       } else {
         try {
-          collection = (T) constructor.invoke(comparator);
+          if (comparatorConstructor != null) {
+            collection = (T) comparatorConstructor.invoke(comparator);
+          } else {
+            if (comparator != null) {
+              LOG.warn(

Review Comment:
   This will print log every time. Which is not feasible fir serialization



-- 
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: commits-unsubscribe@fory.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@fory.apache.org
For additional commands, e-mail: commits-help@fory.apache.org


Re: [PR] fix(java): support TreeSet/TreeMap subclasses without Comparator constructor in SortedSet/SortedMapSerializer [fory]

Posted by "mandrean (via GitHub)" <gi...@apache.org>.
mandrean commented on PR #3344:
URL: https://github.com/apache/fory/pull/3344#issuecomment-3913068848

   Thanks, pushed some changes, have a look again @chaokunyang!


-- 
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: commits-unsubscribe@fory.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@fory.apache.org
For additional commands, e-mail: commits-help@fory.apache.org