6 Replies Latest reply on Mar 27, 2008 2:30 PM by rachmato

    Problem with annotation in test case AnnotatedSecureRunAsPOJ

    rachmato

      Dear All

      I'm trying to run a javadoc doclet against the AS 4.2.2 testsuite. My doclet is running into a problem with one test case which is spitting out errors during javadoc processing:

      /tmp/jboss-4.2.2.GA-src/testsuite/src/main/org/jboss/test/aop/bean/AnnotatedSecureRunAsPOJO.java:34: incompatible types
      [javadoc] found : org.jboss.aspects.security.SecurityDomain
      [javadoc] required: java.lang.annotation.Annotation
      [javadoc] @SecurityDomain("other")

      This occurs for three annotations: RunAS, Unchecked, and SecurityDomain. If I comment out the annotations, my doclet works fine.

      I am running the testsuite against Java 1.5. I tried to correct what I thought might be the error by replacing interface with @interface in the definition of the annotation, but the got a source 1.4 error when trying to rebuild.

      Can someone please advise?

      Richard

        • 1. Re: Problem with annotation in test case AnnotatedSecureRunA
          kabirkhan

          I have not tried this before, can you please describe a bit more what you want to do? Javadoc should not really care about @@org.jboss.aspects.security.SecurityDomain ("other") being an annotation?

          However, since AS 4.2.x is JDK 5 only, the tests should be merged as is the case for AS 5. I will let Shelly McGowan know

          • 2. Re: Problem with annotation in test case AnnotatedSecureRunA
            rachmato

            Hello Kabir

            I spoke with Shelly on the phone, but i'll reply here.

            My doclets are aimed at producing analysis reports of test suites based on javadoc processing of new tags (@functionUnderTest, @unitUnderTest, etc.). In the course of producing such reports, the doclet does some processing of annotations embedded in the test cases: for example, looking for @Test which can be used to differentiate test methods from non-test methods.

            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
            [javadoc] ^
            [javadoc] Adding non-annotated testsuite JBossTestSuite in package org.jboss.test
            [javadoc] javadoc: error - In doclet class org.jboss.testsuitetool.doclets.secrisks.SecurityRisksDoclet, method start has thrown an exception java.lang.reflect.InvocationTargetException
            [javadoc] java.lang.ClassCastException: com.sun.tools.javadoc.ClassDocImpl
            [javadoc] at com.sun.tools.javadoc.AnnotationDescImpl.annotationType(AnnotationDescImpl.java:46)
            [javadoc] at org.jboss.testsuitetool.Utilities.isAnnotatedTestSuite(Unknown Source)
            [javadoc] at org.jboss.testsuitetool.Utilities.constructTestSuiteDocsList(Unknown Source)
            [javadoc] at org.jboss.testsuitetool.doclets.secrisks.SecurityRisksDoclet.start(SecurityRisksDoclet.java:90)
            [javadoc] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
            [javadoc] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
            [javadoc] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
            [javadoc] at java.lang.reflect.Method.invoke(Method.java:585)
            [javadoc] at com.sun.tools.javadoc.DocletInvoker.invoke(DocletInvoker.java:269)
            [javadoc] at com.sun.tools.javadoc.DocletInvoker.start(DocletInvoker.java:143)
            [javadoc] at com.sun.tools.javadoc.Start.parseAndExecute(Start.java:340)
            [javadoc] at com.sun.tools.javadoc.Start.begin(Start.java:128)
            [javadoc] at com.sun.tools.javadoc.Main.execute(Main.java:41)
            [javadoc] at com.sun.tools.javadoc.Main.main(Main.java:31)
            [javadoc] 1 error
            [javadoc] 7 warnings

            In order to try and find out what was causing this problem, I removed the annotations in the offending test case. Then the doclet did not encounter the exception. I have tested my doclet on annotated test cases I wrote and have never seen this error there.

            So, in order to further investigate, I had a look at the annotations which were causing the problem. I noticed that the annotations did not have the familiar @interface keyword, but only interface. So I replaced interface with @interface and tried to recompile. My understanding of annotations is limited, and this may have been the way annotations were defined in earlier releases of JDK. I was just guessing.

            When I tried to recompile my changes using JDK 5, I got the error:
            ======================================================================
            == Executing 'most' in module 'aspects'...
            ==
            _buildmagic:init:
            configure:
            Overriding previous definition of reference to xdoclet.task.classpath
            init:
            _buildmagic:build-bypass-checker:
            _buildmagic:build-bypass-notice:
            _buildmagic:build-bypass-check:
            output:
            _buildmagic:init:
            init:
            _default:compile-etc:
            [mkdir] Created dir: /home/nrla/jboss-4.2.2.GA-src/aspects/output/etc
            [copy] Copying 4 files to /home/nrla/jboss-4.2.2.GA-src/aspects/output/etc
            compile-classes:
            [mkdir] Created dir: /home/nrla/jboss-4.2.2.GA-src/aspects/output/classes
            [javac] Compiling 193 source files to /home/nrla/jboss-4.2.2.GA-src/aspects/output/classes
            /home/nrla/jboss-4.2.2.GA-src/aspects/src/main/org/jboss/aspects/security/RunAs.java:30: annotations are not supported in -source 1.4
            (try -source 1.5 to enable annotations)
            public @interface RunAs
            ^
            1 error
            BUILD FAILED
            /home/nrla/jboss-4.2.2.GA-src/aspects/build.xml:194: Compile failed; see the compiler error output for details.
            Total time: 1 minute 26 seconds
            [nrla@crossover1 build]$ java -version
            java version "1.5.0_11"
            Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_11-b03)
            Java HotSpot(TM) Client VM (build 1.5.0_11-b03, mixed mode, sharing)

            So this is where I am. All I know is that javadoc complains about these annotations, but I don't know (i) if the change from interface to @interface for these annotations is correct, nor (ii) whether tinkering around with the source level restrictions is something I should be even thinking about. That's why I have asked for advice.

            If you need further info, please don't hesitate.

            Richard

            • 3. Re: Problem with annotation in test case AnnotatedSecureRunA
              shelly.mcgowan

              During class compilation, it seems the javac targets are getting set to 1.4 and should be 1.5. I'll checkout the latest branch and look at why this could be happening.
              target="${javac.target}"
              source="${javac.source}"

              • 4. Re: Problem with annotation in test case AnnotatedSecureRunA
                kabirkhan

                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

                • 5. Re: Problem with annotation in test case AnnotatedSecureRunA
                  rachmato

                  Kabir

                  Thank you very much for your detailed reply. I added the lines:


                  to my existing classpath and the problem "went away".

                  Thanks again.

                  Richard

                  • 6. Re: Problem with annotation in test case AnnotatedSecureRunA
                    rachmato

                    Seems my adeed pathelement lines also went away. I used the ones you suggested....