[Scala] Common Scala types fail with requireClassRegistration(true) because ForyScala does not pre-register them
Maintainer thường phản hồi trong vòng 1 ngày
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức phù hợp với người mới
- 52/100
Hướng nghiên cứu
Start in ScalaSerializers.registerSerializers and inspect CollectionKindsTest, along with the supported types listed in docs/object-serialization/scala/native.md. Determine how native registrations and xlang Option handling should cover the listed Scala types without destabilizing existing type IDs. Done means the affected values round trip with requireClassRegistration(true), and the relevant kinds can move from the unregistered tests in #4100.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Search before asking
- I had searched in the issues and found no similar issues.
Version
main (1.8.0-SNAPSHOT), Scala 2.13.18 and 3.3.8
Component(s)
Scala
Minimal reproduce step
import org.apache.fory.scala.ForyScala
val fory = ForyScala.builder()
.withXlang(false)
.withRefTracking(true)
.requireClassRegistration(true) // the default
.build()
fory.deserialize(fory.serialize(Some(1)))
// InsecureException: class scala.Some is not registered ...
requireClassRegistration(true) is the builder default. The Scala security guide also recommends it. So the Option and Either examples in docs/object-serialization/scala/native.md fail as written.
What did you expect to see?
The Scala types that docs/object-serialization/scala/native.md lists as supported should round trip with class registration enabled, without the application registering Scala library classes. Collection kinds should be registered too, including their internal node and factory classes.
What did you see instead?
In native mode, compatible and schema-consistent, InsecureException: class ... is not registered is thrown for the types below. The class named is the first unregistered class reached:
| Value | Unregistered class |
|---|---|
Some(1) / None |
scala.Some / scala.None$ |
Right(1) / Left("a") |
scala.util.Right / scala.util.Left |
(1, 2) |
scala.Tuple2$mcII$sp (specialised tuples) |
Duration(1, "s") |
scala.concurrent.duration.FiniteDuration |
Duration.Inf |
scala.concurrent.duration.Duration$$anon$2 |
Vector.empty |
scala.collection.immutable.Vector0$ |
immutable.ArraySeq(1, 2) / ArraySeq("a") |
ArraySeq$ofInt / ArraySeq$ofRef |
mutable.ArraySeq("a") |
scala.collection.mutable.ArraySeq$ofRef |
immutable.ListSet(1) |
scala.collection.immutable.ListSet$Node |
immutable.ListMap(1 -> 1) |
scala.collection.immutable.ListMap$Node |
immutable.IntMap(1 -> "a") / LongMap(1L -> "a") |
IntMap$Tip / LongMap$Tip |
TreeSet, mutable.TreeSet, mutable.BitSet |
scala.collection.EvidenceIterableFactory$ToFactory |
TreeMap, mutable.TreeMap |
scala.collection.SortedMapFactory$ToFactory |
mutable.LongMap(1L -> 1) |
scala.collection.mutable.Map$ |
new mutable.StringBuilder("x") |
scala.collection.mutable.IndexedSeq$ |
Sorted collections also write their Ordering by reference, so the ordering classes, for example scala.math.Ordering$Int$, probably need registering as well.
In xlang mode, a reflective (non-macro) case class with an Option[T] field fails the same way: ClassUnregisteredException: Class scala.Some is not registered, thrown from the generated codec's writeClassAndObject. Turning off requireClassRegistration does not help in xlang mode.
These types all round trip with requireClassRegistration(false). Separately, some of them come back as a different class; that will be raised as its own issue.
Anything Else?
The fix most likely belongs in ScalaSerializers.registerSerializers, which already registers many Scala collection classes. Points to settle:
- Type IDs: adding registrations assigns new internal type IDs in native mode. Where should new entries go so that IDs of existing registrations, and of classes the user registers afterwards, stay stable? Or is an ID change acceptable for native mode?
- Scala versions: some internal classes (
Vector0–Vector6,ListSet$Node,IntMap$Tip, …) are Scala library implementation details. They should be registered by name, as some already are, so that differences between 2.13 and 3 library versions don't break installation. - Xlang
Option: this may need a nullable-wrapper field path rather than a type registration, because xlangOption[T]is meant to carryTas nullable. - Tests: once fixed, the kinds in
CollectionKindsTestthat are currently tested without registration (#4100) can move to the registration-required group.
Are you willing to submit a PR?
- I'm willing to submit a PR!
- Ngôn ngữ chính
- Java
- Star
- 4.6k
- Fork
- 470
- Merge trung bình
- 9 giờ 28 phút
- Pull request đã merge (30 ngày)
- 33
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của apache/fory
-
[Python] Compatible xlang read silently drops fields when the peer writes camelCase/PascalCase namesĐang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 85/100
Maintainer thường phản hồi trong vòng 1 ngày
-
[Build] Add ASF license headers to config files that allow commentsCó thể làm lại được @Swatantra-66 đã nhận 27 ngày trước và không có pull request nào đang mở. Đang mởenhancement
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
apache/fory#4124 · 3 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
xlang: the snake_case conversion of field names is not specified, and the runtimes do not agreeCó thể làm lại được @dhruv-dagar đã nhận 14 ngày trước và không có pull request nào đang mở. Đang mởbug
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 25/100
apache/fory#4187 · 2 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
[Rust] Add an option to use Rust native enumCó thể đã có người làm @BaldDemian đã nhận 18 ngày trước. Đang mở
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 35/100
apache/fory#4177 · 1 bình luận · 1 người được giao ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Untyped read collapses a number literal that does not fit a doubleCó thể đã có người làm @mohitjoshi-hey đã nhận 20 ngày trước. Đang mởbug
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 68/100
apache/fory#4170 · 3 bình luận · 1 người được giao ·
Maintainer thường phản hồi trong vòng 1 ngày
Issue tương tự
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
liberation-data/drivine4j#547 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
enhancement
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 70/100
-
BindingServiceProperties.bindings regressed to a non-thread-safe TreeMap in GH-3158: concurrent first use of binding names corrupts itCó thể đã có người làm @AkashB23 đã nhận hôm nay. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 62/100
spring-cloud/spring-cloud-stream#3321 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
[Bug] 资源包列表 与 模组/数据包/世界 列表排列顺序不一致Có thể đã có người làm @fishdry1000 đã nhận 4 ngày trước. Đang mởbug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 62/100
Maintainer thường phản hồi trong vòng 1 ngày
-
ai-driven-fuzzing bug claude Minor
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
linagora/twake-calendar-side-service#1333 ·
Maintainer thường phản hồi trong vòng 1 ngày