Skip to content

Many Diplomat generated Kotlin classes are unusable from Java #7262

@mihnita

Description

@mihnita

All public APIs should be Java-friendly (should contain only Java types and should have valid Java names).

For example there is no way to use a org.unicode.icu4x.Locale class from Java.

companion object {
    @JvmStatic fun fromString(name: String): Result<Locale> { .​.​. }
    @JvmStatic fun normalize(s: String): Result<String> { .​.​. }
}
fun setLanguage(s: String): Result<Unit> { .​.​. }
fun setRegion(s: String): Result<Unit> { .​.​. }
fun setScript(s: String): Result<Unit> { .​.​. }

All of them return Result, which is a Kotlin class (https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-result/).

How to inspect what is available for Java:

  • go to <repo_root>/ffi/mvn
  • build (make then mvn compile)
  • dump public methods and grep for - (javap target/classes/org/unicode/icu4x/Locale.class | grep ".*-.*")

Result:

public final java.lang.Object setLanguage-IoAF18A(java.lang.String);
public final java.lang.Object setRegion-IoAF18A(java.lang.String);
public final java.lang.Object setScript-IoAF18A(java.lang.String);
public static final java.lang.Object fromString-IoAF18A(java.lang.String);
public static final java.lang.Object normalize-IoAF18A(java.lang.String);

Since the methods return Object there is no way to call any Result methods (isFailure, getOrNull, getOrThrow, etc.)


Locale is just one example, but this happens in a lot of other classes.

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-ffi-infraComponent: Diplomat, horizontal FFItrackingThis issue tracks a ticket in another project

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions