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:06:31 UTC
[I] [Java] SortedSetSerializer fails for TreeSet subclasses without Comparator constructor [fory]
mandrean opened a new issue, #3343:
URL: https://github.com/apache/fory/issues/3343
### Search before asking
- [x] I had searched in the [issues](https://github.com/apache/fory/issues) and found no similar issues.
### Version
0.15.0
### Component(s)
Java
### Minimal reproduce step
```java
import java.util.TreeSet;
import org.apache.fory.Fory;
import org.apache.fory.serializer.collection.CollectionSerializers.SortedSetSerializer;
public class ChildTreeSet extends TreeSet<String> {}
Fory fory = Fory.builder()
.requireClassRegistration(false)
.build();
// This throws UnsupportedOperationException at construction time
fory.registerSerializer(
ChildTreeSet.class,
new SortedSetSerializer<>(fory, ChildTreeSet.class));
```
`SortedSetSerializer` requires all non-`TreeSet` subclasses to have an explicit `(Comparator)` constructor. Java constructors are not inherited, so a subclass with only a no-arg constructor (which delegates to `TreeSet()`) fails even though `TreeSet(Comparator)` exists on the parent class.
### What did you expect to see?
`SortedSetSerializer` should accept `TreeSet` subclasses that have a no-arg constructor but no `(Comparator)` constructor, falling back to the no-arg constructor for instantiation.
### What did you see instead?
```
java.lang.UnsupportedOperationException: java.lang.NoSuchMethodException:
no such constructor: ChildTreeSet.<init>(Comparator)void/newInvokeSpecial
at o.a.fory.serializer.collection.CollectionSerializers$SortedSetSerializer.<init>(CollectionSerializers.java:194)
```
### Anything Else?
This also affects the default serialization path indirectly. `TreeSet` subclasses fall back to `JDKCompatibleCollectionSerializer` (because `TreeSet` has `readObject`/`writeObject`), which works but is inefficient. Users who try to optimize by explicitly registering `SortedSetSerializer` hit this error.
### Are you willing to submit a PR?
- [x] I'm willing to submit a PR!
--
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.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: [I] [Java] SortedSet/SortedMapSerializer fails for TreeSet/TreeMap subclasses without Comparator constructor [fory]
Posted by "chaokunyang (via GitHub)" <gi...@apache.org>.
chaokunyang closed issue #3343: [Java] SortedSet/SortedMapSerializer fails for TreeSet/TreeMap subclasses without Comparator constructor
URL: https://github.com/apache/fory/issues/3343
--
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