Looks like standard library issue that I've been c...
# stdlib
s
Looks like standard library issue that I've been chasing. I have a simple class with lots of members like this:
Copy code
class TooManyMembers(
        val mem1: Int? = null,
        val mem2: Int? = null,
        .
        .
        .
        val mem248: Int? = null) {
    }
That's a class with 248 members. Instantiating this member with
val obj = TooManyMembers()
throws this error at runtime:
Copy code
Too many arguments in method signature in class file SerializationTests$TooManyMembers
java.lang.ClassFormatError: Too many arguments in method signature in class file SerializationTests$TooManyMembers
If I remove just one member, no more of that error. Is that really a limit (247) with numbers of members one can have in a kotlin class? What can I do if I have an object with more members? 247 seems way too low. This is with kotlin
1.3.61
j
A method descriptor is valid only if it represents method parameters with a total length of 255 or less, where that length includes the contribution for 
this
 in the case of instance or interface method invocations. The total length is calculated by summing the contributions of the individual parameters, where a parameter of type 
long
 or 
double
 contributes two units to the length and a parameter of any other type contributes one unit.
https://docs.oracle.com/javase/specs/jvms/se7/html/jvms-4.html#jvms-4.3.3
looks like that is a limit of the jvm not just kotlin
g
"seems way too low" lmao
s
Ha! Interesting. Any way around this issue? This is part of autogenerated code we have for a growing API generated in various languages. Kotlin seems to be the only one with the issue.
j
are they always the same object type? and do you need default values?
s
No. The object types of the members are different from one another. All these autogen create this classes with default value of
null
e
You can split your class into several ones with fewer number of fields or write a custom serializer. I’m just curious on how you ended up with a class with some many fields? What does it do?
Btw, a better channel to ask would be #serialization
j
there's a 64 kb limit on the size of a single class file
i've gotten almost 10000 enum values into one enum in the past
e
This particular limitation on the number of fields comes from the serialization code-generation strategy. The stratetegy can be changed, but you’d stil be limited to at most few thousand fields (if you’re lucky) due to the aforementioned class size limit.
j
248 nullable ints does not seem like it has advantages of IntArray
s
Yeah, this particular example is not quite accurate because the class is made up of many fields. Unfortunately this is an autogerated class for our API endpoint that is works on all the platforms (web, iOS, and Android). I can modify annotations, and some very basic things, but refactoring this class would mean a giant pain. It is also outrageous to me that we have this class in the first place, but nothing I can do except to voice my concern...
I ended up writing a custom serializer for this, which was a bit challenging to finish off, but got it in the end after a bit of trial and error on my part. So, that works for now, which is great!
simple smile
j
what is this solutionspace? I have seen c->java converters doing silly things like arrays for memory but generating 248 addressable fields only vaguely resembles binprolog for java output
if the class can be the parameter for a function (which by definition is why you would serialize it) the thing that generated the class should probably just skip the class part and generate a datastruct without the compiler in the middle
e
I’ve commented on the issue with a possible solution: https://github.com/Kotlin/kotlinx.serialization/issues/632