Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [aspectj-users] Help: annotation introduction not working

Hi Matthew,
as Andy pointed out, currently AspectJ reweaving assumes that the class has not been modified since it was first weaved. Jarjar renames some classes, and using bytecode manipulation "refactors" existing classes to use the new names it generated. This unfortunately breaks AspectJ reweaving. See bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=263105

You could act in two ways. Either you don't weave them the first time, then package them using jarjar then do all the weaving later, or you do the opposite and perform all the weaving before jarjar modifies .class files.

Don't weaving them the first time could be a problem if you are using ITDs. For example, if an aspect of yours is adding a method, and then you are using your method somewhere in your code, plain javac will not compile, making the first round of weaving necessary. In this case, try using -XterminateAfterCompile, cause it will still correctly check for ITDs but will not emit weaved .class files. Unfortunately, .class files produced with that -X option are not ready to be directly loaded by a JVM, they need to be reweaved by AspectJ (either with another round of ajc or with LTW), but that could be your case.

Hope this help,
Simone

Matthew Adams wrote:
Yes, the classes are being rewoven.  In their original form, the
classes are vanilla data transfer objects that then have aspect(s)
applied to them at compile time (the classes and the aspects are in
source form, compiled with the maven-aspectj-plugin).  Then, in
another project, the binary, already-woven classes are being
repackaged during Maven's initialize phase via jarjar, and unzipped
into a classes directory, then I apply more aspects to them, but this
time using the -inpath argument.

Is there a better way for me to do this?

Thanks,
Matthew

On Mon, Aug 24, 2009 at 3:42 PM, Andy Clement<andrew.clement@xxxxxxxxx> wrote:
Seeing this:

processReweavableStateIfPresent()

in the trace makes me think it is reweaving that is your problem.  Due
to the implementation of reweaving you cannot run another transform
tool between when the type is first woven and when it is rewoven.  Not
quite clear from your description if that is happening - do you think
you are doing reweaving? (ie. weaving something twice - once with
aspects early on, then later on with different aspects).  If you need
to morph the package names you could do it before the first weave and
that would work fine...  I'm afraid it is a limitation of our
reweaving approach.

cheers,
Andy

2009/8/24 Matthew Adams <matthew@xxxxxxxxxxxxxxx>:
Hi Andy,

Thanks for you quick response.  I have a feeling that an upstream tool
might be to blame.  I'm using jarjar to repackage some DTOs in one
jar, then introducing an annotation (XmlRootElement) and an
implementation of a customer-specific interface.

After updating to the latest version of JarJar (1.0), I now am causing
iajc to core dump.  Exception stack is below.

You could repro if you took any old class from one jar, repackaged it
using jarjar 1.0, then tried the same thing.

org.aspectj.apache.bcel.classfile.ClassFormatException: Invalid byte
tag in constant pool: 33
       at org.aspectj.apache.bcel.classfile.Constant.readConstant(Constant.java:135)
       at org.aspectj.apache.bcel.classfile.ConstantPool.<init>(ConstantPool.java:45)
       at org.aspectj.apache.bcel.classfile.ClassParser.readConstantPool(ClassParser.java:186)
       at org.aspectj.apache.bcel.classfile.ClassParser.parse(ClassParser.java:131)
       at org.aspectj.weaver.bcel.Utility.makeJavaClass(Utility.java:455)
       at org.aspectj.weaver.bcel.BcelWeaver.processReweavableStateIfPresent(BcelWeaver.java:1460)
       at org.aspectj.weaver.bcel.BcelWeaver.weave(BcelWeaver.java:1198)
       at org.aspectj.ajdt.internal.compiler.AjPipeliningCompilerAdapter.weaveQueuedEntries(AjPipeliningCompilerAdapter.java:435)
       at org.aspectj.ajdt.internal.compiler.AjPipeliningCompilerAdapter.queueForWeaving(AjPipeliningCompilerAdapter.java:371)
       at org.aspectj.ajdt.internal.compiler.AjPipeliningCompilerAdapter.afterProcessing(AjPipeliningCompilerAdapter.java:358)
       at org.aspectj.ajdt.internal.compiler.CompilerAdapter.ajc$after$org_aspectj_ajdt_internal_compiler_CompilerAdapter$5$6b85518
4(CompilerAdapter.aj:98)
       at org.aspectj.org.eclipse.jdt.internal.compiler.Compiler.process(Compiler.java:652)
       at org.aspectj.org.eclipse.jdt.internal.compiler.Compiler.compile(Compiler.java:392)
       at org.aspectj.ajdt.internal.core.builder.AjBuildManager.performCompilation(AjBuildManager.java:1003)
       at org.aspectj.ajdt.internal.core.builder.AjBuildManager.performBuild(AjBuildManager.java:267)
       at org.aspectj.ajdt.internal.core.builder.AjBuildManager.batchBuild(AjBuildManager.java:181)
       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:355)
       at org.aspectj.tools.ajc.Main.runMain(Main.java:234)
       at org.aspectj.tools.ant.taskdefs.AjcTask.executeInSameVM(AjcTask.java:1211)
       at org.aspectj.tools.ant.taskdefs.AjcTask.execute(AjcTask.java:1021)
       at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:275)
       at org.apache.tools.ant.Task.perform(Task.java:364)
       at org.apache.tools.ant.Target.execute(Target.java:341)
       at org.apache.maven.plugin.antrun.AbstractAntMojo.executeTasks(AbstractAntMojo.java:108)
       at org.apache.maven.plugin.antrun.AntRunMojo.execute(AntRunMojo.java:83)
       at org.apache.maven.plugin.DefaultPluginManager.executeMojo(DefaultPluginManager.java:451)
       at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoals(DefaultLifecycleExecutor.java:558)
       at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoalWithLifecycle(DefaultLifecycleExecutor.java:499)
       at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoal(DefaultLifecycleExecutor.java:478)
       at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoalAndHandleFailures(DefaultLifecycleExecutor.java:330)
       at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeTaskSegments(DefaultLifecycleExecutor.java:291)
       at org.apache.maven.lifecycle.DefaultLifecycleExecutor.execute(DefaultLifecycleExecutor.java:142)
       at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:336)
       at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:129)
       at org.apache.maven.cli.MavenCli.main(MavenCli.java:287)
       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.classworlds.Launcher.launchEnhanced(Launcher.java:315)
       at org.codehaus.classworlds.Launcher.launch(Launcher.java:255)
       at org.codehaus.classworlds.Launcher.mainWithExitCode(Launcher.java:430)
       at org.codehaus.classworlds.Launcher.main(Launcher.java:375)

On Mon, Aug 24, 2009 at 1:54 PM, Andy Clement<andrew.clement@xxxxxxxxx> wrote:
I'm trying to recreate this locally but not having much luck.  The
annotations are always there for me.  You could try turning off
pipeline compilation in case that is affecting things - put
X="-Xset:pipelineCompilation=false" in your iajc command.  But I'm not
hopeful that will address it as you are doing binary weaving.  You are
on a recent AspectJ I take it?

Andy

2009/8/24 Matthew Adams <matthew@xxxxxxxxxxxxxxx>
I'm using the ant task iajc to achieve some binary weaving of .class
files, where I want to introduce not only fields and methods but also
class-level annotations.

The iajc compiler is emitting messages that say that it is adding the
annotations, but when I decompile or use reflection against the woven
classes, there are none on the class.

Anyone know why this might be happening?

Here is my iajc invocation (run from within maven-antrun-plugin):
<iajc destDir="${project.build.outputDirectory}" source="1.6"
       target="1.6" debug="true" preserveAllLocals="true"
       showWeaveInfo="true" verbose="true" classpathref="cp" noimporterror="false">
       <sourceroots>
               <pathelement location="${project.build.sourceDirectory}" />
               <pathelement location="${project.build.sourceDirectory}/../aspect" />
       </sourceroots>
       <inpath>
               <pathelement location="${resource.entity.source.classes.path}" />
       </inpath>
</iajc>

Above, classpathref cp evaluates to a path that is
maven.compile.classpath, and resource.entity.source.classes.path is
the directory containing the .class files that I'm trying to weave.

The ajc compiler says (package names abbreviated with "org...." to
protect the innocent):
    [iajc] ajc [-source, 1.6, -verbose, -target, 1.6, -g, -d,
C:\dev\ECO\svn\trunk\case\case-rest-resource-entity\target\classes,
-showWeaveInfo, -preserveAllLocals, -classpath, ...
    ...
    [iajc] info Pipelining compilation
    ...
    [iajc] info weaver operating in reweavable mode.  Need to verify
any required types exist.
    ...
    [iajc] weaveinfo 'org.....rest.entity.Person' (Person.java) is
annotated with @XmlRootElement type annotation from
'org.....rest.entity.aspects.RestResourceEntityMixin'
(RestResourceEntityMixin.aj:14)
    [iajc] weaveinfo 'org.....rest.entity.Person' (Person.java) is
annotated with @Generated type annotation from
'org.....rest.entity.aspects.RestResourceEntityMixin'
(RestResourceEntityMixin.aj:13)
    [iajc] weaveinfo 'org.....rest.entity.User' (User.java) is
annotated with @XmlRootElement type annotation from
'org.....rest.entity.aspects.RestResourceEntityMixin'
(RestResourceEntityMixin.aj:14)
    [iajc] weaveinfo 'org.....rest.entity.User' (User.java) is
annotated with @Generated type annotation from
'org.....rest.entity.aspects.RestResourceEntityMixin'
(RestResourceEntityMixin.aj:13)

Below is the aspect that's being applied.  Note interestingly that
while the @Generated and @XmlRootElements don't appear in the final
woven .class file, the introduced fields and methods actually do show
up.

import org.....rest.entity.annotations.Generated;
import javax.xml.bind.annotation.XmlRootElement;

public aspect RestResourceEntityMixin {

       public static interface Introduced {}

       declare @type: (org.....rest.entity.*) : @Generated;
       declare @type: (org.....rest.entity.*) : @XmlRootElement;

       declare parents: (@Generated *) implements Introduced;

       private String Introduced.etag;
       private String Introduced.href;

       public String Introduced.getEtag() {
               return etag;
       }
       public void Introduced.setEtag(String etag) {
               this.etag = etag;
       }

       public String Introduced.getHref() {
               return href;
       }
       public void Introduced.setHref(String href) {
               this.href = href;
       }
}

Can anyone help?

Thanks,
Matthew
_______________________________________________
aspectj-users mailing list
aspectj-users@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/aspectj-users
_______________________________________________
aspectj-users mailing list
aspectj-users@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/aspectj-users


--
mailto:matthew@xxxxxxxxxxxxxxx
skype:matthewadams12
yahoo:matthewadams
aol:matthewadams12
google-talk:matthewadams12@xxxxxxxxx
msn:matthew@xxxxxxxxxxxxxxx
http://matthewadams.me
http://www.linkedin.com/in/matthewadams
_______________________________________________
aspectj-users mailing list
aspectj-users@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/aspectj-users

_______________________________________________
aspectj-users mailing list
aspectj-users@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/aspectj-users






--
Simone Gianni            CEO Semeru s.r.l.           Apache Committer
http://www.simonegianni.it/



Back to the top