line/armeria

Using fluent builder patterns can cause issues for Scala 3 users

Opened this issue · 0 comments

Running the following currently fails for scala 3 since 1.29.0 (PR)

(The following can be run from {root_dir}/scala/scala_3)

@main
def main(): Unit = {
  DnsAddressEndpointGroup.builder("")
    .selectionTimeout(Duration.ofDays(1))
    .selectionTimeout(Duration.ofDays(1))
    .selectionTimeout(Duration.ofDays(1))
    .build()

  val server = Server.builder()
    .contextPath("/v1")
    .service("/", (ctx, req) => HttpResponse.of("Hello, world"))
    .and()
    .build()
    .start()

  println(s"server started = ${server}")
}
Exception in thread "main" java.lang.IllegalAccessError: failed to access class com.linecorp.armeria.client.endpoint.dns.DnsEndpointGroupBuilder from class TestSuite$package$
	at TestSuite$package$.main(TestSuite.scala:14)
	at main.main(TestSuite.scala:8)

It seems like when returning the SELF type, Scala3 tries to find the returned class AND superclasses for some reason.

It might be a better idea to steer clear of this pattern until Scala3 side applies a fix, or we decide to make builder superclasses public.

Link for reference: scala/scala3#21797