[jboss-user] [JBoss AOP] - Re: Problem with annotation in test case AnnotatedSecureRunA

kabir.khan@jboss.com do-not-reply at jboss.com
Thu Mar 27 11:55:02 EDT 2008

OK, let's start with an annotation 101 :-) Annotations are only supported from JDK 5 onwards, and the typical use is

Define annotation (this will implement the Annotation interface):

  | @interface SomeAnnotation{}

Use annotation

  | @SomeAnnotation
  | class SomeClass{}

In AOP we provided an annotation compiler, so that you could use "annotations" in jdk 1.4. The difference is that the annotations are simple java interfaces and thus don't implement the (non-existing on jdk 1.4) Annotation interface.

  | interface SomeAnnotation{}

Then you use that annotation as part of the javadoc

  | /**
  |  * @@SomeAnnotation
  |  */
  | class SomeClass{}

We then run the annotated classes through the annotation compiler, and the annotations are put in class attributes just the same as real annotations. What is happening here:

  | When I run the doclet against the AS 4.2.2 testsuite as is, using JDK 5, I get the exception:
  | [javadoc] /home/nrla/jboss-4.2.2.GA-src/testsuite/src/main/org/jboss/test/aop/bean/AnnotatedSecureRunAsPOJO.java:52: incompatible types
  | [javadoc] found : org.jboss.aspects.security.Unchecked
  | [javadoc] required: java.lang.annotation.Annotation
  | [javadoc] @Unchecked 
Is that when reading the annotation it tries to resolve "Unchecked", but finds the plain interface rather than the real annotation.

The problems you are seeing stem from that in AS 4.0.x we ran the testsuite both on jdk 1.4 and jdk 5. The annotations exist both in

testsuite/src/main (plain interfaces)
testsuite/src/jdk15 (real annotations)

and it would use different versions of these depending on the JDK version used to do the test.

Since AS 4.2.x is a JDK5 thing only, we no longer need the split. I suggested to Shelly to merge these. In more detail, what is required is something like what you suggested: 
* moving the src/jdk15 stuff into src/main so that you have the real annotations in the main classpath
* Using source=1.5 when running javac

See the AS trunk testsuite for more details on how to set this up.

I see that the aspects/ project in AS 4.2.2 still uses the split between jdk 1.5 and jdk 1.4 in its aspects/ project. Again see AS trunk for guidance. 

I don't think you can actually make any of the changes I suggested since 4.2.2 has been released.

The main problem is that your stuff uses the jdk 1.4 version of the aspects library, probably from this definition in tools/etc/buildmagic/modules.ent:

  |    <property name="jboss.aspects.root" value="${project.root}/aspects/output"/>
  |    <property name="jboss.aspects.lib" value="${jboss.aspects.root}/lib"/>
  |    <path id="jboss.aspects.classpath">
  |       <pathelement path="${jboss.aspects.lib}/jboss-aspect-library.jar"/>
  |    </path>

You need to use the JDK 5 version, which is what the testsuite build.xml does when compiling the JDK 5 version of the testsuite

  |   <target name="compile-annotated-classes-50" if="HAVE_JDK_1.5">
  |     <mkdir dir="${build.classes}"/>
  |     <!-- Make sure that jdk 50 aspect library comes first, since that contains the
  |     JDK 5 version of the annotation types
  |     -->
  |     <path id="annotations.classpath">
  |       <pathelement path="${jboss.aop.lib}/jboss-aop-jdk50.jar"/>
  |       <pathelement path="${jboss.aspects.lib}/jboss-aspect-library-jdk50.jar"/>
  |       <path refid="tests.compile.classpath"/>
  |     </path>
  |     <javac destdir="${build.classes}" optimize="${javac.optimize}" source="1.5" target="1.5" debug="${javac.debug}" depend="${javac.depend}" verbose="${javac.verbose}"
  |       deprecation="${javac.deprecation}" includeAntRuntime="${javac.include.ant.runtime}" includeJavaRuntime="${javac.include.java.runtime}"
  |       failonerror="${javac.fail.onerror}">
  |       <src path="${source.java.5}"/>
  |       <classpath refid="annotations.classpath"/>
  |     </javac>
  |   </target>

If you do something similar, you should be fine

View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4139352#4139352

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4139352

More information about the jboss-user mailing list