jooby-apt: invalid generated Kotlin code in certain edge cases

Offen
#4,045 0 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Maintainer antworten meist innerhalb von 1 Tag

Dieses Issue hat noch niemand übernommen.

Bewertung

Schwierigkeit
3/5
Geschätzter Aufwand
1-2 Tage
Anfängerfreundlichkeit
55/100
Issue-Typ
Bug
Klarheit
Klar beschrieben
Aktivitätsstatus
Aktiv
Tech-Stack
java, kotlin

Rechercherichtung

Everything lives in the jooby-apt module, which renders handler signatures as source text. Start by reproducing with the snippet given, then grep the module for the places that map Java types to Kotlin names (the byte[] output) and that emit Reified.set(...)/primitive class lookups for parameterized types, and for the code that writes the package line. Done means the three generated-code defects disappear and existing jooby-apt tests still pass.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Beschreibung

jooby-apt seems to generate uncompilable Kotlin code in some edge cases.

Source code:

import io.jooby.annotation.GET
import io.jooby.annotation.Path

@Path("test")
class Test {
    @GET fun test(payload: Set<Int>): ByteArray = byteArrayOf()
}

Generated code:

package 

@io.jooby.annotation.Generated(Test::class)
open class Test_ : io.jooby.Extension {
    // Omitted for brevity
    fun test(ctx: io.jooby.Context): byte[] {
      val c = this.factory.apply(ctx)
      return c.test(ctx.body(io.jooby.Reified.set<Int>(Integer::class.java).getType()))
    }
}

Gradle configuration for good measure:

implementation("io.jooby:jooby:4.6.0")
implementation("io.jooby:jooby-kotlin:4.6.0")
kapt("io.jooby:jooby-apt:4.6.0")

Couple of issues:

  • ByteArray is converted to byte[], which is not a valid Kotlin syntax
  • Set<Int> is converted to Reified.set<Int>(Integer::class.java), which fails at runtime with IllegalArgumentException: Not a primitive type: int. I believe the correct form should be Reified.set<Int>(Int::class.javaObjectType)
  • Dangling package statement (not a big issue since package-less classes are rare, but I thought I'd report it anyway)
Vorherrschende Sprache
Java
Sterne
1.8k
Forks
205
Ø Merge
1 T. 3 Std.
Gemergte PRs (30 T.)
15

Entwicklungsumgebung

  • Enthält ein Dockerfile oder eine Docker-Compose-Datei
  • Keine Pull-Request-Vorlage
  • Kein Beitragsleitfaden

Erste Schritte

  1. Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
  3. Forken Sie das Repository und arbeiten Sie in einem Branch.
  4. Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.

Mehr aus jooby-project/jooby

Alle Issues in jooby-project/jooby

Ähnliche Issues

Weitere Issues zu Java

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.