arrow-kt / arrow

Λrrow - Functional companion to Kotlin's Standard Library
http://arrow-kt.io
Other
6.13k stars 442 forks source link

["Request"] Please do not use the java8 API #1616

Closed Yumenokanata closed 4 years ago

Yumenokanata commented 4 years ago

Hello, I am an Android developer, I really like the arrow library, and I have used the arrow library for a long time in the project. But I encountered a problem when upgrading to 0.10.0 version: The app crashed at startup:

    java.lang.NoClassDefFoundError: arrow.fx.internal.Platform$_trampoline$1
        at arrow.fx.internal.Platform.<clinit>(Utils.kt:204)
        at arrow.fx.IO$Async.unsafeRunTimedTotal$arrow_fx(IO.kt:1017)
        at arrow.fx.IO.unsafeRunTimed(IO.kt:862)
        at arrow.fx.IO.unsafeRunSync(IO.kt:851)

I found this because the internal Util of arrow-fx uses the java8 API withInitial:

  @PublishedApi
  internal val _trampoline = ThreadLocal.withInitial {
    TrampolineExecutor(underlying)
  }
/**
 * Creates a thread local variable. The initial value of the variable is
 * determined by invoking the {@code get} method on the {@code Supplier}.
 *
 * @param <S> the type of the thread local's value
 * @param supplier the supplier to be used to determine the initial value
 * @return a new thread local variable
 * @throws NullPointerException if the specified supplier is null
 * @since 1.8
 */
public static <S> ThreadLocal<S> withInitial(Supplier<? extends S> supplier) {
    return new SuppliedThreadLocal<>(supplier);
}

In Android, just can use this API since SDK26 (Android8.0). Https://developer.android.com/studio/write/java8-support

This problem caused me can not to use the latest version of the arrow in the project right now.

pakoito commented 4 years ago

This is a big bug! I'm surprised we didn't catch it before, there were people using the snapshot for a while.

nomisRev commented 4 years ago

@Yumenokanata you should be able to test this with the latest SNAPSHOT.