question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

GetResolver fails to generate properly with Kotlin nullable -> java boxed types

See original GitHub issue

Hi everyone! This is my data class for a StorIO table with 5 columns using Kotlin

@StorIOSQLiteType(table = AttachmentTable.TABLE)
data class Attachment @StorIOSQLiteCreator constructor(
        @get:StorIOSQLiteColumn(name = AttachmentTable.COLUMN_MESSAGE_ID) val messageId: String,
        @get:StorIOSQLiteColumn(name = AttachmentTable.COLUMN_URL) val url: String,
        @get:StorIOSQLiteColumn(name = AttachmentTable.COLUMN_THUMBNAIL_URL) val thumbnailUrl: String,
        @get:StorIOSQLiteColumn(name = AttachmentTable.COLUMN_ID, key = true) var id: Long? = null,
        @get:StorIOSQLiteColumn(name = AttachmentTable.COLUMN_BYTES) var bytes: Long? = null)

And this is the generated AttachmentStorIOSQLiteGetResolver

    @Override
    @NonNull
    public Attachment mapFromCursor(@NonNull Cursor cursor) {

        String messageId = cursor.getString(cursor.getColumnIndex("messageId"));
        String url = cursor.getString(cursor.getColumnIndex("url"));
        String thumbnailUrl = cursor.getString(cursor.getColumnIndex("thumbnailUrl"));
        Longid= null;
        if(!cursor.isNull(cursor.getColumnIndex("_id"))) {
            id = cursor.getLong(cursor.getColumnIndex("_id"));
        }
        Longbytes= null;
        if(!cursor.isNull(cursor.getColumnIndex("bytes"))) {
            bytes = cursor.getLong(cursor.getColumnIndex("bytes"));
        }

        Attachment object = new Attachment(messageId, url, thumbnailUrl, id, bytes);

        return object;
    }

As you can see, everything appears correct except there is a space missing between the type (Long) and the variable name (id, bytes) causing a compilation error. Should be an easy fix?

More examples of types (Kotlin -> Java Generated)

  • Okay ** Long -> long ** String -> String

  • Broken ** Long? -> Long ** Int? -> Integer

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:17 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
geralt-encorecommented, Jan 18, 2017

The problem was just in missing space for boxed types in Kotlin/AutoValue case. Now it’s fixed and fix will be available in the next version.

0reactions
blueberycommented, Jan 27, 2017

Hey thanks for fixing this @geralt-encore I’ll give it a go as soon as I can!!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Nullability in Java and Kotlin
This guide covers support for nullable types in Kotlin, how Kotlin treats nullable annotations from Java, and more.
Read more >
Why can a java nullable returned value be assigned to a ...
The Kotlin compiler has no way of determining if it can return a nullable value or not since for Java only nullable types...
Read more >
Chapter 6. The Kotlin type system - Kotlin in Action
This chapter covers. Nullable types and syntax for dealing with null s; Primitive types and their correspondence to the Java types; Kotlin collections...
Read more >
Use of Boolean? in Kotlin if Statement - Baeldung
Instead, we have “boxed” primitive types like Int and Boolean. Kotlin's nullable Boolean type Boolean? is pretty similar to Java's Boolean type.
Read more >
Kotlin is not primitive! (Primitives in Kotlin and Java) - Medium
Recently I had a little conversation about primitives. You known, that strange type of data you always put on stack, you cannot assign...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found