Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lists should be exposed to Kotlin as List, not MutableList #334

Open
david-allison opened this issue Dec 11, 2023 · 4 comments
Open

Lists should be exposed to Kotlin as List, not MutableList #334

david-allison opened this issue Dec 11, 2023 · 4 comments

Comments

@david-allison
Copy link
Member

Backend Codegen is problematic: it exposes a java.util.List, but this is actually a com.google.protobuf.Internal.ProtobufList. ProtobufList throws on mutation

Extends List to add the capability to make the list immutable and inspect if it is modifiable.

https://protobuf.dev/reference/java/api-docs/com/google/protobuf/Internal.ProtobufList

Reported in: ankidroid/Anki-Android#14948

@david-allison
Copy link
Member Author

david-allison commented Dec 11, 2023

I've had a quick Google, but no obvious annotations came up to tell the kotlin compiler that the Java list should be List<T> rather than MutableList<T> when accessed by Kotlin

If it means we need to port our codegen to Kotlin, this is likely not worthwhile

@dae
Copy link
Contributor

dae commented Dec 12, 2023

Where are you seeing mutable? I looked in the generated Note.java, and it's a plain list:

  /**
   * <code>repeated string fields = 7;</code>
   * @return A list containing the fields.
   */
  @java.lang.Override
  public java.util.List<java.lang.String> getFieldsList() {
    return fields_;
  }

@dae
Copy link
Contributor

dae commented Dec 12, 2023

Sorry, ignore me - I assumed that List was always an immutable variant in Java, but apparently that's not the case.

@dae
Copy link
Contributor

dae commented Dec 12, 2023

And this is not our codegen by the way - it's the output of protoc.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants