realm-java icon indicating copy to clipboard operation
realm-java copied to clipboard

java.lang.IllegalArgumentException: Field '***': type mismatch.

Open mkovalyk opened this issue 11 years ago • 37 comments

Hello. I have weird issue with Realm. My app is on google play store , but I have this error: java.lang.IllegalArgumentException: Field 'cityId': type mismatch. Was INTEGER, expected MIXED. at io.realm.RealmQuery.getColumnIndices(:164) at io.realm.RealmQuery.equalTo(:244) at com.eway.dal.PlaceDao.readAll(:188) Sometimes there is another type: Fatal Exception: java.lang.IllegalArgumentException Field 'cityId': type mismatch. Was INTEGER, expected BOOLEAN. and Fatal Exception: java.lang.IllegalArgumentException Field 'cityId': type mismatch. Was INTEGER, expected STRING.

Weird situation because I can't reproduce it and I have no idea what is the reason of this Exception. On all testing devices everything is OK, but in production, sometimes I have this Exception. To be more precisely - app installed on ~ 1.2k devices, this Exception occurs 26 times..

mkovalyk avatar Jul 24 '15 11:07 mkovalyk

That is very weird indeed. Did you change your model classes during the lifetime of your app? Meaning, did you deal with migrations?

emanuelez avatar Jul 24 '15 11:07 emanuelez

No and Yes.) I have migration, but on Google Play Store we have only first version of the app. So as far as I understand there is no model changes.. In Migration class I didn't touch this field.

mkovalyk avatar Jul 24 '15 11:07 mkovalyk

Is the Realm file created on the device or was it (even partially) pre-packaged with the app?

emanuelez avatar Jul 24 '15 11:07 emanuelez

Created on the device.

mkovalyk avatar Jul 24 '15 11:07 mkovalyk

Hmmm... hard to figure out more with the code. Is there any way for you to share your code for us to take a look?

emanuelez avatar Jul 24 '15 11:07 emanuelez

Migration class:

public class RealmMigrationTest implements RealmMigration {
    @Override
    public long execute(final Realm realm, final long l) {
           if (l == 1) {
            Table infoTable = realm.getTable(CityInfo.class);
            infoTable.removeColumn(infoTable.getColumnIndex("lastUpdate"));
            infoTable.removeColumn(infoTable.getColumnIndex("lastUserUpdate"));
        }
        if (l == 2) {
            Table userPlaceTable = realm.getTable(UserPlace.class);
            userPlaceTable.addColumn(ColumnType.INTEGER, "time");
            Table placeTable = realm.getTable(Place.class);
            placeTable.addColumn(ColumnType.INTEGER, "time");
        }
        return 3;
    }
}

Model:

@JsonIgnoreProperties(ignoreUnknown = true)
public class Place extends RealmObject {

    private String address = "";
    @Expose
    private int cityId;
    private boolean favorite = false;
    private long id;
    private String imageURL = "";
    @JsonIgnore
    @PrimaryKey
    private String key;
    private double lat;
    private double lng;
    private String name = "";
    @Index
    private String nameLower = "";
    private long order = 0;
    @Ignore
    @JsonIgnore
    private PlaceType placeType;
    private String placeTypeString = "";
    private String refreshDate = "";
    private long time = 0;

.... getters and setters }

Configuration to get Realm:

    public static RealmConfiguration getConfigurationForCity(@NonNull final Context context, int cityId) {
        final String key = formatUuid(context);
        return new RealmConfiguration.Builder(context)
                .name(String.valueOf(cityId) + ".realm")
                .encryptionKey(key.getBytes())
                .migration(new RealmMigrationTest())
                .schemaVersion(VERSION_DATABASE)
                .build();
    }

mkovalyk avatar Jul 24 '15 12:07 mkovalyk

And I have similar exception java.lang.IllegalArgumentException: Invalid native column type at io.realm.internal.ColumnType.fromNativeValue(:91) at io.realm.internal.Table.getColumnType(:313) at io.realm.RealmQuery.getColumnIndices(:162) at io.realm.RealmQuery.equalTo(:244)

46 times in ~1500 devices.

mkovalyk avatar Jul 24 '15 13:07 mkovalyk

and part of code that throws an exception:

    realm.where(Place.class)
                        .equalTo(FIELD_CITY_ID, cityId)   
                 .findAllSorted(FIELD_ORDER, true, FIELD_NAME, true);

mkovalyk avatar Jul 24 '15 13:07 mkovalyk

if you need any additional info, please let me know.

mkovalyk avatar Jul 24 '15 18:07 mkovalyk

In your RealmMigration.execute, the l is not increased in l == 1 block. So if user update if from version 1, the code inside l == 2 is not actually executed. Is that a mistake?

beeender avatar Jul 25 '15 06:07 beeender

I doubt it. I will try without any migration and let you know. I have some other exceptions maybe related to this one: Build fingerprint: 'Lenovo/S650_ROW/S650_ROW:4.4.2/KOT49H/S650_ROW_S308_150121.:user/release-keys' pid: 12262, tid: 12262, name: _.* >>> **.**_*<<< signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 00000004 r0 00000d28 r1 ffffde1d r2 00000000 r3 65304ac0 r4 00000000 r5 65304a30 r6 00000000 r7 651d31d8 r8 00000d28 r9 00000e00 sl bea9d0d0 fp 653034d0 ip 00000001 sp bea9cf60 lr 65142eab pc 6517ddda cpsr 600e0030

backtrace: #00 pc 0007fdda /data/app-lib/com.eway-1/librealm-jni.so #01 pc 00044ea9 /data/app-lib/com.eway-1/librealm-jni.so

code around pc: 6517ddb8 fdaef7d2 f1019907 60230308 039cf101 6517ddc8 f10160a3 612303ac 61632300 e00061a3 6517ddd8 68632400 99039a08 621961da f8d59a04 6517dde8 99053448 f1a1509c 2b01030c e008d82e 6517ddf8 e000e001 4605e7ff e7fce667 e7fae7fb 6517de08 f505e7f9 4631702c f83ef7c5 0008f080 6517de18 00c0f3c0 46287620 ff79f7b8 46074631 6517de28 f7b99802 4601f96c 704ef505 f82cf7c5 6517de38 ea4f084b 46380230 f7d44611 f890fcbf 6517de48 46073480 42a8bb0b e01ed163 2a0e9a05 6517de58 4628d11b 774ef505 ff59f7b8 46804631 6517de68 f7b99802 4601f94c f7c54638 084bf80d 6517de78 0230ea4f 46114640 fca0f7d4 3480f890 6517de88 2b004680 42a8d050 f505d04e 4631702c 6517de98 fffaf7c4 f0106823 d01f0f01 0704f080 6517dea8 46206a9b 0780f3c7 b1284798 46206823

code around lr: 65142e88 4770000c 000798fb 6a836ac2 0f01f012 65142e98 0262ea4f bf18b510 44105884 58e3bf18 65142ea8 bd104798 3088b508 ffeef7ff b508bd08 65142eb8 ffeaf7ff f7ffbd08 68c1bffa f7ff3901 65142ec8 b508bfe3 fff9f7ff 18c00fcb 0100f141 65142ed8 ea4f1049 bd080030 7e036840 68c0b90b 65142ee8 f7ff4770 6840bfee b90b7e03 477068c0 65142ef8 bfe7f7ff 7e036840 7e83b933 f8d0b913 65142f08 47700094 477068c0 bfdbf7ff 7e036840 65142f18 7e43b943 7e83b123 f8d0b913 47700094 65142f28 477068c0 bfcdf7ff 7e036840 68c0b90b 65142f38 f7ff4770 6883bfc6 b113685b f7ff3004 65142f48 4618bff3 30044770 bfeef7ff 6803b508 65142f58 4798695b b508bd08 691b6803 bd084798 65142f68 44196843 29006803 bfb8460a 021ff101 65142f78 eb031152 4b070282 2b00400b 3b01da03

And last question: If I have clean app without migration, database version is 1. Then I want to change database schema and set version to 2. Of course I have migration. If I install changed version on device without previously installed app will migration be performed? I mean will version of the realm on the installed app be 1? Thanks!

mkovalyk avatar Jul 25 '15 10:07 mkovalyk

@mkovalyk If you are doing a fresh install, the database version will be whatever you set in the RealmConfiguration. Default is 0.

new RealmConfiguration.Builder(context)
  .schemaVersion(2) // Fresh installs will set the version to 2
  .build();

cmelchior avatar Jul 25 '15 10:07 cmelchior

So, if I set schemaVersion(2) and migration(new Migration(...)), on all fresh installed apps migration is never called. Am I right?

mkovalyk avatar Jul 25 '15 10:07 mkovalyk

Yes, that is correct.

cmelchior avatar Jul 25 '15 10:07 cmelchior

This means that in my app Migration is not even called. My VERSION_DATABASE is 3. Do you have any idea what is the reason of this Exception? Do you need some additional information?

mkovalyk avatar Jul 25 '15 11:07 mkovalyk

Hi guys, the situation is not getting any better, here is a direct Google Play link for the above mentioned app with the problem - https://play.google.com/store/apps/details?id=com.eway. It crashes severely, pretty often on Lenovo devices. I understand it is weekend, but we are having really hard times here, daily crash rate is 7-10% with the issue, which is not suppose to happen. Appreciate your input.

eway7 avatar Jul 26 '15 04:07 eway7

This line looks really odd java.lang.IllegalArgumentException: Field 'cityId': type mismatch. Was INTEGER, expected MIXED

MIXED is an internal datatype in Realm that isn't used anywhere in the model classes.

Can you post the content of PlaceRealmProxy. It should be located under /build/intermediates/classes/debug/io/realm/PlaceRealmProxy

Also, are you by any chance accessing the Realm file from two different processes?

cmelchior avatar Jul 27 '15 07:07 cmelchior

No, I have only app and internal service.. public class PlaceRealmProxy extends Place implements RealmObjectProxy { private static long INDEX_ADDRESS; private static long INDEX_CITYID; private static long INDEX_FAVORITE; private static long INDEX_ID; private static long INDEX_IMAGEURL; private static long INDEX_KEY; private static long INDEX_LAT; private static long INDEX_LNG; private static long INDEX_NAME; private static long INDEX_NAMELOWER; private static long INDEX_ORDER; private static long INDEX_PLACETYPESTRING; private static long INDEX_REFRESHDATE; private static long INDEX_TIME; private static Map<String, Long> columnIndices; private static final List FIELD_NAMES;

public PlaceRealmProxy() {
}

public String getAddress() {
    this.realm.checkIfValid();
    return this.row.getString(INDEX_ADDRESS);
}

public void setAddress(String value) {
    this.realm.checkIfValid();
    this.row.setString(INDEX_ADDRESS, value);
}

public int getCityId() {
    this.realm.checkIfValid();
    return (int)this.row.getLong(INDEX_CITYID);
}

public void setCityId(int value) {
    this.realm.checkIfValid();
    this.row.setLong(INDEX_CITYID, (long)value);
}

public boolean isFavorite() {
    this.realm.checkIfValid();
    return this.row.getBoolean(INDEX_FAVORITE);
}

public void setFavorite(boolean value) {
    this.realm.checkIfValid();
    this.row.setBoolean(INDEX_FAVORITE, value);
}

public long getId() {
    this.realm.checkIfValid();
    return this.row.getLong(INDEX_ID);
}

public void setId(long value) {
    this.realm.checkIfValid();
    this.row.setLong(INDEX_ID, value);
}

public String getImageURL() {
    this.realm.checkIfValid();
    return this.row.getString(INDEX_IMAGEURL);
}

public void setImageURL(String value) {
    this.realm.checkIfValid();
    this.row.setString(INDEX_IMAGEURL, value);
}

public String getKey() {
    this.realm.checkIfValid();
    return this.row.getString(INDEX_KEY);
}

public void setKey(String value) {
    this.realm.checkIfValid();
    this.row.setString(INDEX_KEY, value);
}

public double getLat() {
    this.realm.checkIfValid();
    return this.row.getDouble(INDEX_LAT);
}

public void setLat(double value) {
    this.realm.checkIfValid();
    this.row.setDouble(INDEX_LAT, value);
}

public double getLng() {
    this.realm.checkIfValid();
    return this.row.getDouble(INDEX_LNG);
}

public void setLng(double value) {
    this.realm.checkIfValid();
    this.row.setDouble(INDEX_LNG, value);
}

public String getName() {
    this.realm.checkIfValid();
    return this.row.getString(INDEX_NAME);
}

public void setName(String value) {
    this.realm.checkIfValid();
    this.row.setString(INDEX_NAME, value);
}

public String getNameLower() {
    this.realm.checkIfValid();
    return this.row.getString(INDEX_NAMELOWER);
}

public void setNameLower(String value) {
    this.realm.checkIfValid();
    this.row.setString(INDEX_NAMELOWER, value);
}

public long getOrder() {
    this.realm.checkIfValid();
    return this.row.getLong(INDEX_ORDER);
}

public void setOrder(long value) {
    this.realm.checkIfValid();
    this.row.setLong(INDEX_ORDER, value);
}

public String getPlaceTypeString() {
    this.realm.checkIfValid();
    return this.row.getString(INDEX_PLACETYPESTRING);
}

public void setPlaceTypeString(String value) {
    this.realm.checkIfValid();
    this.row.setString(INDEX_PLACETYPESTRING, value);
}

public String getRefreshDate() {
    this.realm.checkIfValid();
    return this.row.getString(INDEX_REFRESHDATE);
}

public void setRefreshDate(String value) {
    this.realm.checkIfValid();
    this.row.setString(INDEX_REFRESHDATE, value);
}

public long getTime() {
    this.realm.checkIfValid();
    return this.row.getLong(INDEX_TIME);
}

public void setTime(long value) {
    this.realm.checkIfValid();
    this.row.setLong(INDEX_TIME, value);
}

public static Table initTable(ImplicitTransaction transaction) {
    if(!transaction.hasTable("class_Place")) {
        Table table = transaction.getTable("class_Place");
        table.addColumn(ColumnType.STRING, "address");
        table.addColumn(ColumnType.INTEGER, "cityId");
        table.addColumn(ColumnType.BOOLEAN, "favorite");
        table.addColumn(ColumnType.INTEGER, "id");
        table.addColumn(ColumnType.STRING, "imageURL");
        table.addColumn(ColumnType.STRING, "key");
        table.addColumn(ColumnType.DOUBLE, "lat");
        table.addColumn(ColumnType.DOUBLE, "lng");
        table.addColumn(ColumnType.STRING, "name");
        table.addColumn(ColumnType.STRING, "nameLower");
        table.addColumn(ColumnType.INTEGER, "order");
        table.addColumn(ColumnType.STRING, "placeTypeString");
        table.addColumn(ColumnType.STRING, "refreshDate");
        table.addColumn(ColumnType.INTEGER, "time");
        table.addSearchIndex(table.getColumnIndex("key"));
        table.addSearchIndex(table.getColumnIndex("nameLower"));
        table.setPrimaryKey("key");
        return table;
    } else {
        return transaction.getTable("class_Place");
    }
}

public static void validateTable(ImplicitTransaction transaction) {
    if(!transaction.hasTable("class_Place")) {
        throw new RealmMigrationNeededException(transaction.getPath(), "The Place class is missing from the schema for this Realm.");
    } else {
        Table table = transaction.getTable("class_Place");
        if(table.getColumnCount() != 14L) {
            throw new RealmMigrationNeededException(transaction.getPath(), "Field count does not match - expected 14 but was " + table.getColumnCount());
        } else {
            HashMap columnTypes = new HashMap();

            for(long i = 0L; i < 14L; ++i) {
                columnTypes.put(table.getColumnName(i), table.getColumnType(i));
            }

            columnIndices = new HashMap();
            Iterator var7 = getFieldNames().iterator();

            while(var7.hasNext()) {
                String fieldName = (String)var7.next();
                long index = table.getColumnIndex(fieldName);
                if(index == -1L) {
                    throw new RealmMigrationNeededException(transaction.getPath(), "Field \'" + fieldName + "\' not found for type Place");
                }

                columnIndices.put(fieldName, Long.valueOf(index));
            }

            INDEX_ADDRESS = table.getColumnIndex("address");
            INDEX_CITYID = table.getColumnIndex("cityId");
            INDEX_FAVORITE = table.getColumnIndex("favorite");
            INDEX_ID = table.getColumnIndex("id");
            INDEX_IMAGEURL = table.getColumnIndex("imageURL");
            INDEX_KEY = table.getColumnIndex("key");
            INDEX_LAT = table.getColumnIndex("lat");
            INDEX_LNG = table.getColumnIndex("lng");
            INDEX_NAME = table.getColumnIndex("name");
            INDEX_NAMELOWER = table.getColumnIndex("nameLower");
            INDEX_ORDER = table.getColumnIndex("order");
            INDEX_PLACETYPESTRING = table.getColumnIndex("placeTypeString");
            INDEX_REFRESHDATE = table.getColumnIndex("refreshDate");
            INDEX_TIME = table.getColumnIndex("time");
            if(!columnTypes.containsKey("address")) {
                throw new RealmMigrationNeededException(transaction.getPath(), "Missing field \'address\'");
            } else if(columnTypes.get("address") != ColumnType.STRING) {
                throw new RealmMigrationNeededException(transaction.getPath(), "Invalid type \'String\' for field \'address\'");
            } else if(!columnTypes.containsKey("cityId")) {
                throw new RealmMigrationNeededException(transaction.getPath(), "Missing field \'cityId\'");
            } else if(columnTypes.get("cityId") != ColumnType.INTEGER) {
                throw new RealmMigrationNeededException(transaction.getPath(), "Invalid type \'int\' for field \'cityId\'");
            } else if(!columnTypes.containsKey("favorite")) {
                throw new RealmMigrationNeededException(transaction.getPath(), "Missing field \'favorite\'");
            } else if(columnTypes.get("favorite") != ColumnType.BOOLEAN) {
                throw new RealmMigrationNeededException(transaction.getPath(), "Invalid type \'boolean\' for field \'favorite\'");
            } else if(!columnTypes.containsKey("id")) {
                throw new RealmMigrationNeededException(transaction.getPath(), "Missing field \'id\'");
            } else if(columnTypes.get("id") != ColumnType.INTEGER) {
                throw new RealmMigrationNeededException(transaction.getPath(), "Invalid type \'long\' for field \'id\'");
            } else if(!columnTypes.containsKey("imageURL")) {
                throw new RealmMigrationNeededException(transaction.getPath(), "Missing field \'imageURL\'");
            } else if(columnTypes.get("imageURL") != ColumnType.STRING) {
                throw new RealmMigrationNeededException(transaction.getPath(), "Invalid type \'String\' for field \'imageURL\'");
            } else if(!columnTypes.containsKey("key")) {
                throw new RealmMigrationNeededException(transaction.getPath(), "Missing field \'key\'");
            } else if(columnTypes.get("key") != ColumnType.STRING) {
                throw new RealmMigrationNeededException(transaction.getPath(), "Invalid type \'String\' for field \'key\'");
            } else if(table.getPrimaryKey() != table.getColumnIndex("key")) {
                throw new RealmMigrationNeededException(transaction.getPath(), "Primary key not defined for field \'key\'");
            } else if(!table.hasSearchIndex(table.getColumnIndex("key"))) {
                throw new RealmMigrationNeededException(transaction.getPath(), "Index not defined for field \'key\'");
            } else if(!columnTypes.containsKey("lat")) {
                throw new RealmMigrationNeededException(transaction.getPath(), "Missing field \'lat\'");
            } else if(columnTypes.get("lat") != ColumnType.DOUBLE) {
                throw new RealmMigrationNeededException(transaction.getPath(), "Invalid type \'double\' for field \'lat\'");
            } else if(!columnTypes.containsKey("lng")) {
                throw new RealmMigrationNeededException(transaction.getPath(), "Missing field \'lng\'");
            } else if(columnTypes.get("lng") != ColumnType.DOUBLE) {
                throw new RealmMigrationNeededException(transaction.getPath(), "Invalid type \'double\' for field \'lng\'");
            } else if(!columnTypes.containsKey("name")) {
                throw new RealmMigrationNeededException(transaction.getPath(), "Missing field \'name\'");
            } else if(columnTypes.get("name") != ColumnType.STRING) {
                throw new RealmMigrationNeededException(transaction.getPath(), "Invalid type \'String\' for field \'name\'");
            } else if(!columnTypes.containsKey("nameLower")) {
                throw new RealmMigrationNeededException(transaction.getPath(), "Missing field \'nameLower\'");
            } else if(columnTypes.get("nameLower") != ColumnType.STRING) {
                throw new RealmMigrationNeededException(transaction.getPath(), "Invalid type \'String\' for field \'nameLower\'");
            } else if(!table.hasSearchIndex(table.getColumnIndex("nameLower"))) {
                throw new RealmMigrationNeededException(transaction.getPath(), "Index not defined for field \'nameLower\'");
            } else if(!columnTypes.containsKey("order")) {
                throw new RealmMigrationNeededException(transaction.getPath(), "Missing field \'order\'");
            } else if(columnTypes.get("order") != ColumnType.INTEGER) {
                throw new RealmMigrationNeededException(transaction.getPath(), "Invalid type \'long\' for field \'order\'");
            } else if(!columnTypes.containsKey("placeTypeString")) {
                throw new RealmMigrationNeededException(transaction.getPath(), "Missing field \'placeTypeString\'");
            } else if(columnTypes.get("placeTypeString") != ColumnType.STRING) {
                throw new RealmMigrationNeededException(transaction.getPath(), "Invalid type \'String\' for field \'placeTypeString\'");
            } else if(!columnTypes.containsKey("refreshDate")) {
                throw new RealmMigrationNeededException(transaction.getPath(), "Missing field \'refreshDate\'");
            } else if(columnTypes.get("refreshDate") != ColumnType.STRING) {
                throw new RealmMigrationNeededException(transaction.getPath(), "Invalid type \'String\' for field \'refreshDate\'");
            } else if(!columnTypes.containsKey("time")) {
                throw new RealmMigrationNeededException(transaction.getPath(), "Missing field \'time\'");
            } else if(columnTypes.get("time") != ColumnType.INTEGER) {
                throw new RealmMigrationNeededException(transaction.getPath(), "Invalid type \'long\' for field \'time\'");
            }
        }
    }
}

public static String getTableName() {
    return "class_Place";
}

public static List<String> getFieldNames() {
    return FIELD_NAMES;
}

public static Map<String, Long> getColumnIndices() {
    return columnIndices;
}

public static Place createOrUpdateUsingJsonObject(Realm realm, JSONObject json, boolean update) throws JSONException {
    Object obj = null;
    if(update) {
        Table table = realm.getTable(Place.class);
        long pkColumnIndex = table.getPrimaryKey();
        if(!json.isNull("key")) {
            long rowIndex = table.findFirstString(pkColumnIndex, json.getString("key"));
            if(rowIndex != -1L) {
                obj = new PlaceRealmProxy();
                ((Place)obj).realm = realm;
                ((Place)obj).row = table.getUncheckedRow(rowIndex);
            }
        }
    }

    if(obj == null) {
        obj = (Place)realm.createObject(Place.class);
    }

    if(!json.isNull("address")) {
        ((Place)obj).setAddress(json.getString("address"));
    }

    if(!json.isNull("cityId")) {
        ((Place)obj).setCityId(json.getInt("cityId"));
    }

    if(!json.isNull("favorite")) {
        ((Place)obj).setFavorite(json.getBoolean("favorite"));
    }

    if(!json.isNull("id")) {
        ((Place)obj).setId(json.getLong("id"));
    }

    if(!json.isNull("imageURL")) {
        ((Place)obj).setImageURL(json.getString("imageURL"));
    }

    if(!json.isNull("key")) {
        ((Place)obj).setKey(json.getString("key"));
    }

    if(!json.isNull("lat")) {
        ((Place)obj).setLat(json.getDouble("lat"));
    }

    if(!json.isNull("lng")) {
        ((Place)obj).setLng(json.getDouble("lng"));
    }

    if(!json.isNull("name")) {
        ((Place)obj).setName(json.getString("name"));
    }

    if(!json.isNull("nameLower")) {
        ((Place)obj).setNameLower(json.getString("nameLower"));
    }

    if(!json.isNull("order")) {
        ((Place)obj).setOrder(json.getLong("order"));
    }

    if(!json.isNull("placeTypeString")) {
        ((Place)obj).setPlaceTypeString(json.getString("placeTypeString"));
    }

    if(!json.isNull("refreshDate")) {
        ((Place)obj).setRefreshDate(json.getString("refreshDate"));
    }

    if(!json.isNull("time")) {
        ((Place)obj).setTime(json.getLong("time"));
    }

    return (Place)obj;
}

public static Place createUsingJsonStream(Realm realm, JsonReader reader) throws IOException {
    Place obj = (Place)realm.createObject(Place.class);
    reader.beginObject();

    while(true) {
        while(reader.hasNext()) {
            String name = reader.nextName();
            if(name.equals("address") && reader.peek() != JsonToken.NULL) {
                obj.setAddress(reader.nextString());
            } else if(name.equals("cityId") && reader.peek() != JsonToken.NULL) {
                obj.setCityId(reader.nextInt());
            } else if(name.equals("favorite") && reader.peek() != JsonToken.NULL) {
                obj.setFavorite(reader.nextBoolean());
            } else if(name.equals("id") && reader.peek() != JsonToken.NULL) {
                obj.setId(reader.nextLong());
            } else if(name.equals("imageURL") && reader.peek() != JsonToken.NULL) {
                obj.setImageURL(reader.nextString());
            } else if(name.equals("key") && reader.peek() != JsonToken.NULL) {
                obj.setKey(reader.nextString());
            } else if(name.equals("lat") && reader.peek() != JsonToken.NULL) {
                obj.setLat(reader.nextDouble());
            } else if(name.equals("lng") && reader.peek() != JsonToken.NULL) {
                obj.setLng(reader.nextDouble());
            } else if(name.equals("name") && reader.peek() != JsonToken.NULL) {
                obj.setName(reader.nextString());
            } else if(name.equals("nameLower") && reader.peek() != JsonToken.NULL) {
                obj.setNameLower(reader.nextString());
            } else if(name.equals("order") && reader.peek() != JsonToken.NULL) {
                obj.setOrder(reader.nextLong());
            } else if(name.equals("placeTypeString") && reader.peek() != JsonToken.NULL) {
                obj.setPlaceTypeString(reader.nextString());
            } else if(name.equals("refreshDate") && reader.peek() != JsonToken.NULL) {
                obj.setRefreshDate(reader.nextString());
            } else if(name.equals("time") && reader.peek() != JsonToken.NULL) {
                obj.setTime(reader.nextLong());
            } else {
                reader.skipValue();
            }
        }

        reader.endObject();
        return obj;
    }
}

public static Place copyOrUpdate(Realm realm, Place object, boolean update, Map<RealmObject, RealmObjectProxy> cache) {
    if(object.realm != null && object.realm.getPath().equals(realm.getPath())) {
        return object;
    } else {
        PlaceRealmProxy realmObject = null;
        boolean canUpdate = update;
        if(update) {
            Table table = realm.getTable(Place.class);
            long pkColumnIndex = table.getPrimaryKey();
            if(object.getKey() == null) {
                throw new IllegalArgumentException("Primary key value must not be null.");
            }

            long rowIndex = table.findFirstString(pkColumnIndex, object.getKey());
            if(rowIndex != -1L) {
                realmObject = new PlaceRealmProxy();
                realmObject.realm = realm;
                realmObject.row = table.getUncheckedRow(rowIndex);
                cache.put(object, (RealmObjectProxy)realmObject);
            } else {
                canUpdate = false;
            }
        }

        return canUpdate?update(realm, realmObject, object, cache):copy(realm, object, update, cache);
    }
}

public static Place copy(Realm realm, Place newObject, boolean update, Map<RealmObject, RealmObjectProxy> cache) {
    Place realmObject = (Place)realm.createObject(Place.class, newObject.getKey());
    cache.put(newObject, (RealmObjectProxy)realmObject);
    realmObject.setAddress(newObject.getAddress() != null?newObject.getAddress():"");
    realmObject.setCityId(newObject.getCityId());
    realmObject.setFavorite(newObject.isFavorite());
    realmObject.setId(newObject.getId());
    realmObject.setImageURL(newObject.getImageURL() != null?newObject.getImageURL():"");
    realmObject.setKey(newObject.getKey() != null?newObject.getKey():"");
    realmObject.setLat(newObject.getLat());
    realmObject.setLng(newObject.getLng());
    realmObject.setName(newObject.getName() != null?newObject.getName():"");
    realmObject.setNameLower(newObject.getNameLower() != null?newObject.getNameLower():"");
    realmObject.setOrder(newObject.getOrder());
    realmObject.setPlaceTypeString(newObject.getPlaceTypeString() != null?newObject.getPlaceTypeString():"");
    realmObject.setRefreshDate(newObject.getRefreshDate() != null?newObject.getRefreshDate():"");
    realmObject.setTime(newObject.getTime());
    return realmObject;
}

static Place update(Realm realm, Place realmObject, Place newObject, Map<RealmObject, RealmObjectProxy> cache) {
    realmObject.setAddress(newObject.getAddress() != null?newObject.getAddress():"");
    realmObject.setCityId(newObject.getCityId());
    realmObject.setFavorite(newObject.isFavorite());
    realmObject.setId(newObject.getId());
    realmObject.setImageURL(newObject.getImageURL() != null?newObject.getImageURL():"");
    realmObject.setLat(newObject.getLat());
    realmObject.setLng(newObject.getLng());
    realmObject.setName(newObject.getName() != null?newObject.getName():"");
    realmObject.setNameLower(newObject.getNameLower() != null?newObject.getNameLower():"");
    realmObject.setOrder(newObject.getOrder());
    realmObject.setPlaceTypeString(newObject.getPlaceTypeString() != null?newObject.getPlaceTypeString():"");
    realmObject.setRefreshDate(newObject.getRefreshDate() != null?newObject.getRefreshDate():"");
    realmObject.setTime(newObject.getTime());
    return realmObject;
}

public String toString() {
    if(!this.isValid()) {
        return "Invalid object";
    } else {
        StringBuilder stringBuilder = new StringBuilder("Place = [");
        stringBuilder.append("{address:");
        stringBuilder.append(this.getAddress());
        stringBuilder.append("}");
        stringBuilder.append(",");
        stringBuilder.append("{cityId:");
        stringBuilder.append(this.getCityId());
        stringBuilder.append("}");
        stringBuilder.append(",");
        stringBuilder.append("{favorite:");
        stringBuilder.append(this.isFavorite());
        stringBuilder.append("}");
        stringBuilder.append(",");
        stringBuilder.append("{id:");
        stringBuilder.append(this.getId());
        stringBuilder.append("}");
        stringBuilder.append(",");
        stringBuilder.append("{imageURL:");
        stringBuilder.append(this.getImageURL());
        stringBuilder.append("}");
        stringBuilder.append(",");
        stringBuilder.append("{key:");
        stringBuilder.append(this.getKey());
        stringBuilder.append("}");
        stringBuilder.append(",");
        stringBuilder.append("{lat:");
        stringBuilder.append(this.getLat());
        stringBuilder.append("}");
        stringBuilder.append(",");
        stringBuilder.append("{lng:");
        stringBuilder.append(this.getLng());
        stringBuilder.append("}");
        stringBuilder.append(",");
        stringBuilder.append("{name:");
        stringBuilder.append(this.getName());
        stringBuilder.append("}");
        stringBuilder.append(",");
        stringBuilder.append("{nameLower:");
        stringBuilder.append(this.getNameLower());
        stringBuilder.append("}");
        stringBuilder.append(",");
        stringBuilder.append("{order:");
        stringBuilder.append(this.getOrder());
        stringBuilder.append("}");
        stringBuilder.append(",");
        stringBuilder.append("{placeTypeString:");
        stringBuilder.append(this.getPlaceTypeString());
        stringBuilder.append("}");
        stringBuilder.append(",");
        stringBuilder.append("{refreshDate:");
        stringBuilder.append(this.getRefreshDate());
        stringBuilder.append("}");
        stringBuilder.append(",");
        stringBuilder.append("{time:");
        stringBuilder.append(this.getTime());
        stringBuilder.append("}");
        stringBuilder.append("]");
        return stringBuilder.toString();
    }
}

public int hashCode() {
    String realmName = this.realm.getPath();
    String tableName = this.row.getTable().getName();
    long rowIndex = this.row.getIndex();
    byte result = 17;
    int result1 = 31 * result + (realmName != null?realmName.hashCode():0);
    result1 = 31 * result1 + (tableName != null?tableName.hashCode():0);
    result1 = 31 * result1 + (int)(rowIndex ^ rowIndex >>> 32);
    return result1;
}

public boolean equals(Object o) {
    if(this == o) {
        return true;
    } else if(o != null && this.getClass() == o.getClass()) {
        PlaceRealmProxy aPlace = (PlaceRealmProxy)o;
        String path = this.realm.getPath();
        String otherPath = aPlace.realm.getPath();
        if(path != null) {
            if(!path.equals(otherPath)) {
                return false;
            }
        } else if(otherPath != null) {
            return false;
        }

        label30: {
            String tableName = this.row.getTable().getName();
            String otherTableName = aPlace.row.getTable().getName();
            if(tableName != null) {
                if(tableName.equals(otherTableName)) {
                    break label30;
                }
            } else if(otherTableName == null) {
                break label30;
            }

            return false;
        }

        if(this.row.getIndex() != aPlace.row.getIndex()) {
            return false;
        } else {
            return true;
        }
    } else {
        return false;
    }
}

static {
    ArrayList fieldNames = new ArrayList();
    fieldNames.add("address");
    fieldNames.add("cityId");
    fieldNames.add("favorite");
    fieldNames.add("id");
    fieldNames.add("imageURL");
    fieldNames.add("key");
    fieldNames.add("lat");
    fieldNames.add("lng");
    fieldNames.add("name");
    fieldNames.add("nameLower");
    fieldNames.add("order");
    fieldNames.add("placeTypeString");
    fieldNames.add("refreshDate");
    fieldNames.add("time");
    FIELD_NAMES = Collections.unmodifiableList(fieldNames);
}

}

mkovalyk avatar Jul 27 '15 07:07 mkovalyk

Hmm, that proxy class looks fine. Currently my best bet is that there is something wrong with how our column indices are calculated (at least for queries), but your native crashes indicate that the Realm file on disc is wrong compared to what is expected which hint to some migration code being run.

A couple of other questions:

  • Can you post your manifest section for your service?
  • You create a database for each user that logs in, is that correct?
  • Do you manually call Realm.migrateRealm() anywhere?

cmelchior avatar Jul 27 '15 07:07 cmelchior

  1. Well, actually 2 services:
  2. I create different types of database:
    1. common.realm
    2. temp.realm
    3. cityId.realm, where cityId = 1, 2,... info for city
  3. No.

mkovalyk avatar Jul 27 '15 08:07 mkovalyk