robotoworks / mechanoid

Eclipse plugin providing a set of DSL's for the rapid development of Android apps
58 stars 26 forks source link

[MECHDB] Exception during unmarshaling of an ActiveRecord created from a view #155

Closed imhoff closed 11 years ago

imhoff commented 11 years ago

When adding an ActiveRecord (representing a view) to an intent via 'Intent.putParceableArrayListExtra()' the following unmarshaling to retrieve the extra leads to an Exception.

Sample Project: https://github.com/imhoff/MechanoidIssues/tree/master/issue155

Exception:

Caused by: java.lang.RuntimeException: bad array lengths
    at android.os.Parcel.readBooleanArray(Parcel.java:613)
    at [..].db.model.MyTable.<init>(MyTable.java:282)
    at [..].db.model.MyTable.<init>(MyTable.java:259)
    at [..].db.model.MyTable$2.createFromParcel(MyTable.java:40)
    at [..].db.model.MyTable$2.createFromParcel(MyTable.java:1)
    at android.os.Parcel.readParcelable(Parcel.java:1981)
    at android.os.Parcel.readValue(Parcel.java:1846)
    at android.os.Parcel.readListInternal(Parcel.java:2092)
    at android.os.Parcel.readArrayList(Parcel.java:1536)
    at android.os.Parcel.readValue(Parcel.java:1867)
    at android.os.Parcel.readMapInternal(Parcel.java:2083)
    at android.os.Bundle.unparcel(Bundle.java:215)
    at android.os.Bundle.containsKey(Bundle.java:256)
    at android.content.Intent.hasExtra(Intent.java:3576)
    at [..]MyActivity.onCreate(PresentationActivity.java:301)
    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1048)
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1715)

This is caused because a boolean array of the wrong length is provided at this point in the generated code.

Database File:

package com.example.mysampleproject.db

database SampleDB {

    migration {
        create table artists (
            _id integer primary key autoincrement,
            name text
        );

        create view artists_view as
            select 
                a._id as _id,
                a.name as name
            from artists as a;
    }
}

Generated faulty code in ArtistViewRecord.java

private ArtistsViewRecord(Parcel in) {
        super(ArtistsView.CONTENT_URI);

        setId(in.readLong());

        mName = in.readString();

        boolean[] dirtyFlags = new boolean[2];
        in.readBooleanArray(dirtyFlags);
        mNameDirty = dirtyFlags[0];
    }

The line boolean[] dirtyFlags = new boolean[2]; should say boolean[] dirtyFlags = new boolean[1];

fluxtah commented 11 years ago

Cheers looks like this is only happening with views? will fixed ASAP