question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

File names of @serializable classes cause error building multiplatform project.

See original GitHub issue

Task ‘compileKotlinIos’ fails with : e: java.util.NoSuchElementException: Sequence contains no element matching the predicate. at org.jetbrains.kotlinx.serialization.compiler.backend.ir.IrBuilderExtension$DefaultImpls.serializableSyntheticConstructor(GeneratorHelpers.kt:620) at org.jetbrains.kotlinx.serialization.compiler.backend.ir.SerializableIrGenerator.serializableSyntheticConstructor(SerializableIrGenerator.kt:30) at org.jetbrains.kotlinx.serialization.compiler.backend.ir.SerializableIrGenerator.generateSuperSerializableCall(SerializableIrGenerator.kt:130) ... with serializable abstract and inherited classes, but only if the name of the file containing the abstract class comes after the inheriting class alphabetically.

To Reproduce

In file Cabstract.kt: @Serializable abstract class Cabstract( var foo: String ) { }

in file Binherit.kt: @Serializable class Binherit( var bar: String = "" ) : Cabstract("") { }

‘./gradlew clean build’ results in error. Renaming the file ‘Binherit.kt’ to ‘Dinherit.kt’ allows the build to complete with no issue.

Expected behavior

Build should run fine regardless of file names.

Environment

  • Kotlin version: 1.3.31
  • Library version: 0.11.0
  • Kotlin platforms: Native
  • Gradle version: 5.3.1
  • IDE version Android studio 3.3

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:1
  • Comments:13 (6 by maintainers)

github_iconTop GitHub Comments

2reactions
sandwwraithcommented, Jun 3, 2019

Ok, that’s fun. It is actually related to names; the problem is the order in which compiler process classes. If file’s name with a derived class lexicographically smaller than the file’s with a base class, it is processed first and does not see special constructor added by the compiler plugin to the base class. The workaround is to rename files (you don’t need to rename classes themselves) or put the whole hierarchy in one file.

Read more comments on GitHub >

github_iconTop Results From Across the Web

NoClassDefFoundError kotlinx serialization - Stack Overflow
I have a kotlin multiplatform project and I need to serialize a class. I have included the following dependency in my commonMain and ......
Read more >
Current issues with Kotlin Multiplatform and how to fix them
Recently I started to play around with Kotlin Multiplatform, ... Sadly, a simple renaming of the package will lead to build errors.
Read more >
Understanding Kotlin data serialization - LogRocket Blog
Understand data serialization in Kotlin, which allows you to convert your data into other compatible formats and share it with others.
Read more >
Script serialization - Unity - Manual
Serialization is the automatic process of transforming data structures or GameObject states into a format that ... Script serialization can cause errors.
Read more >
SerializationException Class (System.Runtime.Serialization)
The exception thrown when an error occurs during serialization or deserialization. ... Note: You must compile this file using the C# /unsafe switch....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found