Skip to content

Property type misdetection with Kotlin + default methods #314

@mvysny

Description

@mvysny

Thank you very much for your awesome work on Sql2o! I've built a small library on top of sql2o which also handles entity CRUD: the vok-orm.

However, there is a subtle bug in Sql2o which sometimes misdetects the property type. The problem is related to mvysny/vok-orm#10 . The problem is as follows.

In vok-orm there is an interface Entity<T> which all entities implement. The interface contains the T getId() method. When a class implements this interface, Kotlin compiler outputs two getId() methods: one that returns Object and the other which returns T (the same with setters, setId(Object) and setId(T).

The problem is in PojoMetadata:117 cycle: JVM lists those getters/setters in random order, and sometimes the T-typed one wins, and sometimes the Object-typed wins. That then causes Sql2o to not to pick up a proper converter for that field, and the setter fails.

I'm thinking of a fix of prioritising the T-typed getters/setters over Object-typed ones: if there is a setter with Object already in the propertyGetters/propertySetters map, overwrite it with a new one.

I can create a PR for this, I'm just wondering whether the project is alive and you're interested in PR and releasing 1.6.1 eventually :) Thanks!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions