JakeWharton / hugo

Annotation-triggered method call logging for your debug builds.
Apache License 2.0
7.92k stars 798 forks source link

AspectJ exception #45

Closed vpratfr closed 9 years ago

vpratfr commented 10 years ago

I have noticed that Hugo stopped outputting anything in the logcat. At the same time, I got a bunch of aspectJ error logs in my app root folder. I think it has to do with the inner class you usually create when you need parcelables.

Here is basically what the logs say:

org.aspectj.weaver.BCException: Whilst processing type 'Lcom/wannacorp/api/model/VirtualZone$1;' - cannot cast the outer type to a reference type.  Signature=Lcom/wannacorp/api/model/VirtualZone; toString()=com.wannacorp.api.model.VirtualZone
when processing type mungers 
when weaving 
when batch building BuildConfig[null] #Files=0 AopXmls=#0

    at org.aspectj.weaver.AbstractReferenceTypeDelegate.getFormalTypeParametersFromOuterClass(AbstractReferenceTypeDelegate.java:110)
    at org.aspectj.weaver.bcel.BcelObjectType.ensureGenericSignatureUnpacked(BcelObjectType.java:767)
    at org.aspectj.weaver.bcel.BcelObjectType.getSuperclass(BcelObjectType.java:231)
    at org.aspectj.weaver.ReferenceType.getSuperclass(ReferenceType.java:897)
    at org.aspectj.weaver.bcel.BcelWeaver.weaveParentsFor(BcelWeaver.java:1302)
    at org.aspectj.weaver.bcel.BcelWeaver.weave(BcelWeaver.java:1121)
    at org.aspectj.ajdt.internal.compiler.AjPipeliningCompilerAdapter.weaveQueuedEntries(AjPipeliningCompilerAdapter.java:514)
    at org.aspectj.ajdt.internal.compiler.AjPipeliningCompilerAdapter.afterCompiling(AjPipeliningCompilerAdapter.java:375)
    at org.aspectj.ajdt.internal.compiler.CompilerAdapter.ajc$afterReturning$org_aspectj_ajdt_internal_compiler_CompilerAdapter$2$f9cc9ca0(CompilerAdapter.aj:73)
    at org.aspectj.org.eclipse.jdt.internal.compiler.Compiler.compile(Compiler.java:550)
    at org.aspectj.ajdt.internal.core.builder.AjBuildManager.performCompilation(AjBuildManager.java:1031)
    at org.aspectj.ajdt.internal.core.builder.AjBuildManager.performBuild(AjBuildManager.java:272)
    at org.aspectj.ajdt.internal.core.builder.AjBuildManager.batchBuild(AjBuildManager.java:185)
    at org.aspectj.ajdt.ajc.AjdtCommand.doCommand(AjdtCommand.java:112)
    at org.aspectj.ajdt.ajc.AjdtCommand.runCommand(AjdtCommand.java:60)
    at org.aspectj.tools.ajc.Main.run(Main.java:371)
    at org.aspectj.tools.ajc.Main$run.call(Unknown Source)
    at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:42)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:108)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:120)
    at hugo.weaving.plugin.HugoPlugin$_apply_closure2_closure3.doCall(HugoPlugin.groovy:55)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:90)
    (... 20 lines more of stack trace) 

And the source code of the class in question:

/**
 * A special zone that contains all spots of a country/zone that are not attached to any subzone within
 * that entity
 *
 * Created by Vincent Mimoun-Prat @ MarvinLabs, 04/07/2014.
 */
public class VirtualZone implements Zone, android.os.Parcelable {

    private Zone parentZone;
    private int spotCount;

    public VirtualZone() {
    }

    public VirtualZone(Zone parentZone, int spotCount) {
        assert (parentZone != null);

        this.parentZone = parentZone;
        this.spotCount = spotCount;
    }

    // =============================================================================================
    // Zone implementation
    // ==

    @Override
    public long getId() {
        return parentZone.getId();
    }

    @Override
    public int getSpotCount() {
        return spotCount;
    }

    @Override
    public Location getSouthWest() {
        return parentZone.getSouthWest();
    }

    @Override
    public Location getNorthEast() {
        return parentZone.getNorthEast();
    }

    @Override
    public String getName() {
        return parentZone.getName();
    }

    @Override
    public String getGeoPath() {
        return parentZone.getGeoPath();
    }

    @Override
    public List<Zone> getSubZones() {
        return Lists.newArrayListWithExpectedSize(0);
    }

    // =============================================================================================
    // Parcelable
    // ==

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

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeParcelable(this.parentZone, 0);
        dest.writeInt(this.spotCount);
    }

    private VirtualZone(Parcel in) {
        this.parentZone = in.readParcelable(Zone.class.getClassLoader());
        this.spotCount = in.readInt();
    }

    public static final Creator<VirtualZone> CREATOR = new Creator<VirtualZone>() {
        public VirtualZone createFromParcel(Parcel source) {
            return new VirtualZone(source);
        }

        public VirtualZone[] newArray(int size) {
            return new VirtualZone[size];
        }
    };

    // =============================================================================================
    // Accessors
    // ==

    public Zone getParentZone() {
        return parentZone;
    }

    // =============================================================================================
    // Other methods
    // ==

    @Override
    public boolean equals(Object o) {
        if (o == this) {
            return true;
        }

        if (o instanceof VirtualZone) {
            VirtualZone other = (VirtualZone) o;

            if (!Objects.equal(parentZone, other.parentZone)) {
                return false;
            }

            if (spotCount != other.spotCount) {
                return false;
            }

            return true;
        }

        return false;
    }

    @Override
    public String toString() {
        return Objects.toStringHelper(this)
                .add("parentZone", parentZone)
                .add("spotCount", spotCount)
                .toString();
    }
}
nicolasgramlich commented 9 years ago

Same here, seems to be related to static inner classes... =/ @vpratfr , found a solution for this?

vpratfr commented 9 years ago

Nothing I could trace. It started working again after an update of Android Studio (or maybe something else). I simply ignored the problem till then and just did not use Hugo in the meantime.

nicolasgramlich commented 9 years ago

I think I nailed it down to a enum implementing an interface and then aspectj weaver gets confused with the class being not what it expects. I'm hoping the aspectj update in the 1.1.1 release fixes it. But in the meantime I can't use it either =(

nicolasgramlich commented 9 years ago

Weird, I just turned Hugo 1.1.0 back on and it's working again. =/

JakeWharton commented 9 years ago

Try 1.2.0 which has a much smarter AspectJ version. Closing for now.

ins1der1211 commented 2 years ago

I have noticed that Hugo stopped outputting anything in the logcat. At the same time, I got a bunch of aspectJ error logs in my app root folder. I think it has to do with the inner class you usually create when you need parcelables.

Here is basically what the logs say:

org.aspectj.weaver.BCException: Whilst processing type 'Lcom/wannacorp/api/model/VirtualZone$1;' - cannot cast the outer type to a reference type.  Signature=Lcom/wannacorp/api/model/VirtualZone; toString()=com.wannacorp.api.model.VirtualZone
when processing type mungers 
when weaving 
when batch building BuildConfig[null] #Files=0 AopXmls=#0

    at org.aspectj.weaver.AbstractReferenceTypeDelegate.getFormalTypeParametersFromOuterClass(AbstractReferenceTypeDelegate.java:110)
    at org.aspectj.weaver.bcel.BcelObjectType.ensureGenericSignatureUnpacked(BcelObjectType.java:767)
    at org.aspectj.weaver.bcel.BcelObjectType.getSuperclass(BcelObjectType.java:231)
    at org.aspectj.weaver.ReferenceType.getSuperclass(ReferenceType.java:897)
    at org.aspectj.weaver.bcel.BcelWeaver.weaveParentsFor(BcelWeaver.java:1302)
    at org.aspectj.weaver.bcel.BcelWeaver.weave(BcelWeaver.java:1121)
    at org.aspectj.ajdt.internal.compiler.AjPipeliningCompilerAdapter.weaveQueuedEntries(AjPipeliningCompilerAdapter.java:514)
    at org.aspectj.ajdt.internal.compiler.AjPipeliningCompilerAdapter.afterCompiling(AjPipeliningCompilerAdapter.java:375)
    at org.aspectj.ajdt.internal.compiler.CompilerAdapter.ajc$afterReturning$org_aspectj_ajdt_internal_compiler_CompilerAdapter$2$f9cc9ca0(CompilerAdapter.aj:73)
    at org.aspectj.org.eclipse.jdt.internal.compiler.Compiler.compile(Compiler.java:550)
    at org.aspectj.ajdt.internal.core.builder.AjBuildManager.performCompilation(AjBuildManager.java:1031)
    at org.aspectj.ajdt.internal.core.builder.AjBuildManager.performBuild(AjBuildManager.java:272)
    at org.aspectj.ajdt.internal.core.builder.AjBuildManager.batchBuild(AjBuildManager.java:185)
    at org.aspectj.ajdt.ajc.AjdtCommand.doCommand(AjdtCommand.java:112)
    at org.aspectj.ajdt.ajc.AjdtCommand.runCommand(AjdtCommand.java:60)
    at org.aspectj.tools.ajc.Main.run(Main.java:371)
    at org.aspectj.tools.ajc.Main$run.call(Unknown Source)
    at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:42)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:108)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:120)
    at hugo.weaving.plugin.HugoPlugin$_apply_closure2_closure3.doCall(HugoPlugin.groovy:55)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:90)
    (... 20 lines more of stack trace) 

And the source code of the class in question:

/**
 * A special zone that contains all spots of a country/zone that are not attached to any subzone within
 * that entity
 *
 * Created by Vincent Mimoun-Prat @ MarvinLabs, 04/07/2014.
 */
public class VirtualZone implements Zone, android.os.Parcelable {

    private Zone parentZone;
    private int spotCount;

    public VirtualZone() {
    }

    public VirtualZone(Zone parentZone, int spotCount) {
        assert (parentZone != null);

        this.parentZone = parentZone;
        this.spotCount = spotCount;
    }

    // =============================================================================================
    // Zone implementation
    // ==

    @Override
    public long getId() {
        return parentZone.getId();
    }

    @Override
    public int getSpotCount() {
        return spotCount;
    }

    @Override
    public Location getSouthWest() {
        return parentZone.getSouthWest();
    }

    @Override
    public Location getNorthEast() {
        return parentZone.getNorthEast();
    }

    @Override
    public String getName() {
        return parentZone.getName();
    }

    @Override
    public String getGeoPath() {
        return parentZone.getGeoPath();
    }

    @Override
    public List<Zone> getSubZones() {
        return Lists.newArrayListWithExpectedSize(0);
    }

    // =============================================================================================
    // Parcelable
    // ==

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

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeParcelable(this.parentZone, 0);
        dest.writeInt(this.spotCount);
    }

    private VirtualZone(Parcel in) {
        this.parentZone = in.readParcelable(Zone.class.getClassLoader());
        this.spotCount = in.readInt();
    }

    public static final Creator<VirtualZone> CREATOR = new Creator<VirtualZone>() {
        public VirtualZone createFromParcel(Parcel source) {
            return new VirtualZone(source);
        }

        public VirtualZone[] newArray(int size) {
            return new VirtualZone[size];
        }
    };

    // =============================================================================================
    // Accessors
    // ==

    public Zone getParentZone() {
        return parentZone;
    }

    // =============================================================================================
    // Other methods
    // ==

    @Override
    public boolean equals(Object o) {
        if (o == this) {
            return true;
        }

        if (o instanceof VirtualZone) {
            VirtualZone other = (VirtualZone) o;

            if (!Objects.equal(parentZone, other.parentZone)) {
                return false;
            }

            if (spotCount != other.spotCount) {
                return false;
            }

            return true;
        }

        return false;
    }

    @Override
    public String toString() {
        return Objects.toStringHelper(this)
                .add("parentZone", parentZone)
                .add("spotCount", spotCount)
                .toString();
    }
}

I've also encountered with such problem when target jvm version of plugin (another plugin) was "1.7" and target version of project was 8. So it seems to be a problem with lambdas