rharter / auto-value-parcel

An Android Parcelable extension for Google's AutoValue.
Apache License 2.0
655 stars 64 forks source link

Stack overflow by using auto-value-parcel #115

Closed vogella closed 7 years ago

vogella commented 7 years ago

I try to use auto-value-parcel is a new project and receive a stackoverflow:

Here is my class

package com.vogella.android.autovalue;

import android.os.Parcelable;

import com.google.auto.value.AutoValue;

@AutoValue public abstract class Task implements Parcelable{

    public abstract long id();
    public abstract String summary();
    public abstract String description();

    public static Task create(long id, String summary, String descriptoin) {
        return new AutoValue_Task(id, summary, descriptoin);
    }
}

Build file

apply plugin: 'com.android.application'

android {
    compileSdkVersion 25
    buildToolsVersion "25.0.2"
    defaultConfig {
        applicationId "com.vogella.android.autovalue"
        minSdkVersion 24
        targetSdkVersion 25
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    testCompile 'junit:junit:4.12'
    compile 'com.android.support.constraint:constraint-layout:1.0.2'
    annotationProcessor 'com.google.auto.value:auto-value:1.4'
    annotationProcessor 'com.ryanharter.auto.value:auto-value-parcel:0.2.5'
    provided 'com.jakewharton.auto.value:auto-value-annotations:1.4'
}

Is this something I'm doing wrong or an error in the library?

Stacktrace:

04-20 12:59:20.203 9069-9069/com.vogella.android.autovalue D/Error: ERR: exClass=java.lang.StackOverflowError 04-20 12:59:20.203 9069-9069/com.vogella.android.autovalue D/Error: ERR: exMsg=stack size 8MB 04-20 12:59:20.203 9069-9069/com.vogella.android.autovalue D/Error: ERR: file=ComponentName.java 04-20 12:59:20.203 9069-9069/com.vogella.android.autovalue D/Error: ERR: class=android.content.ComponentName 04-20 12:59:20.203 9069-9069/com.vogella.android.autovalue D/Error: ERR: method=writeToParcel line=318 04-20 12:59:20.204 9069-9069/com.vogella.android.autovalue D/Error: ERR: stack=java.lang.IllegalStateException: Could not execute method for android:onClick at android.view.View$DeclaredOnClickListener.onClick(View.java:4725) at android.view.View.performClick(View.java:5637) at android.view.View$PerformClick.run(View.java:22429) at android.os.Handler.handleCallback(Handler.java:751) at android.os.Handler.dispatchMessage(Handler.java:95) at android.os.Looper.loop(Looper.java:154) at android.app.ActivityThread.main(ActivityThread.java:6119) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776) Caused by: java.lang.reflect.InvocationTargetException at java.lang.reflect.Method.invoke(Native Method) at android.view.View$DeclaredOnClickListener.onClick(View.java:4720) at android.view.View.performClick(View.java:5637)  at android.view.View$PerformClick.run(View.java:22429)  at android.os.Handler.handleCallback(Handler.java:751)  at android.os.Handler.dispatchMessage(Handler.java:95)  at android.os.Looper.loop(Looper.java:154)  at android.app.ActivityThread.main(ActivityThread.java:6119)  at java.lang.reflect.Method.invoke(Native Method)  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)  Caused by: java.lang.StackOverflowError: stack size 8MB at android.content.ComponentName.writeToParcel(ComponentName.java:318) at android.content.ComponentName.writeToParcel(ComponentName.java:333) at android.content.Intent.writeToParcel(Intent.java:8654) at android.os.Parcel.writeParcelable(Parcel.java:1496) at android.os.Parcel.writeValue(Parcel.java:1402) at android.os.Parcel.writeArrayMapInternal(Parcel.java:724) at android.os.BaseBundle.writeToParcelInner(BaseBundle.java:1408) at android.os.Bundle.writeToParcel(Bundle.java:1157) at android.os.Parcel.writeBundle(Parcel.java:764) at android.content.Intent.writeToParcel(Intent.java:8687) at android.os.Parcel.writeParcelable(Parcel.java:1496) at android.os.Parcel.writeValue(Parcel.java:1402) at android.os.Parcel.writeArrayMapInternal(Parcel.java:724) at android.os.BaseBundle.writeToParcelInner(BaseBundle.java:1408) at android.os.Bundle.writeToParcel(Bundle.java:1157) at android.os.Parcel.writeBundle(Parcel.java:764) at android.content.Intent.writeToParcel(Intent.java:8687) at android.os.Parcel.writeParcelable(Parcel.java:1496) at android.os.Parcel.writeValue(Parcel.java:1402) at android.os.Parcel.writeArrayMapInternal(Parcel.java:724) at android.os.BaseBundle.writeToParcelInner(BaseBundle.java:1408) at android.os.Bundle.writeToParcel(Bundle.java:1157) at android.os.Parcel.writeBundle(Parcel.java:764) at android.content.Intent.writeToParcel(Intent.java:8687) at android.os.Parcel.writeParcelable(Parcel.java:1496) at android.os.Parcel.writeValue(Parcel.java:1402) at android.os.Parcel.writeArrayMapInternal(Parcel.java:724) at android.os.BaseBundle.writeToParcelInner(BaseBundle.java:1408) at android.os.Bundle.writeToParcel(Bundle.java:1157) at android.os.Parcel.writeBundle(Parcel.java:764) at android.content.Intent.writeToParcel(Intent.java:8687) at android.os.Parcel.writeParcelable(Parcel.java:1496) at android.os.Parcel.writeValue(Parcel.java:1402) at android.os.Parcel.writeArrayMapInternal(Parcel.java:724) at android.os.BaseBundle.writeToParcelInner(BaseBundle.java:1408) at android.os.Bundle.writeToParcel(Bundle.java:1157) at android.os.Parcel.writeBundle(Parcel.java:764) at android.content.Intent.writeToParcel(Intent.java:8687) at android.os.Parcel.writeParcelable(Parcel.java:1496) at android.os.Parcel.writeValue(Parcel.java:1402) at android.os.Parcel.writeArrayMapInternal(Parcel.java:724) at android.os.BaseBundle.writeToParcelInner(BaseBundle.java:1408) at android.os.Bundle.writeToParcel(Bundle.java:1157) at android.os.Parcel.writeBundle(Parcel.java:764) at android.content.Intent.writeToParcel(Intent.java:8687) at android.os.Parcel.writeParcelable(Parcel.java:1496) at android.os.Parcel.writeValue(Parcel.java:1402) at android.os.Parcel.writeArrayMapInternal(Parcel.java:724) at android.os.BaseBundle.writeToParcelInner(BaseBundle.java:1408) at android.os.Bundle.writeToParcel(Bundle.java:1157) at android.os.Parcel.writeBundle(Parcel.java:764) at android.content.Intent.writeToParcel(Intent.java:8687) at android.os.Parcel.writeParcelable(Parcel.java:1496) at android.os.Parcel.writeValue(Parcel.java:1402) at android.os.Parcel.writeAr
rharter commented 7 years ago

Looks like the stack Trace didn't get added.

vogella commented 7 years ago

Sorry for the missing trace. I updated the "Details" section in the first comment with it.

rharter commented 7 years ago

Can you share the generated file? Look in the build directories for AutoValue_Task.

vogella commented 7 years ago

The generated file looks like the following:

package com.vogella.android.butterknifeexample;

import android.os.Parcel; import android.os.Parcelable; import java.lang.Override; import java.lang.String;

final class AutoValue_Task extends $AutoValue_Task { public static final Parcelable.Creator CREATOR = new Parcelable.Creator() { @Override public AutoValue_Task createFromParcel(Parcel in) { return new AutoValue_Task( in.readLong(), in.readString(), in.readString() ); } @Override public AutoValue_Task[] newArray(int size) { return new AutoValue_Task[size]; } };

AutoValue_Task(long id, String summary, String description) { super(id, summary, description); }

@Override public void writeToParcel(Parcel dest, int flags) { dest.writeLong(id()); dest.writeString(summary()); dest.writeString(description()); }

@Override public int describeContents() { return 0; } }

vogella commented 7 years ago

Sorry for the noise. I make the silly error to put something else into the intent data which created the loop.

jffiorillo commented 7 years ago

Do you have the solution @vogella ?

vogella commented 7 years ago

@jffiorillo works fine for me, after putting the correct value into the intent. See http://www.vogella.com/tutorials/AutoValue/article.html for my setup.