5 Replies Latest reply on Feb 5, 2004 8:13 AM by bill.burke

    Bug in ClassAdvisor

    rythos

      Hey yo,

      Found another one. ClassAdvisor.java line 466
      changed:
      pointcuts.add(pointcut);
      to:
      if( !pointcuts.contains( pointcut ) )
      pointcuts.add(pointcut);
      If a call to an advised method was made twice in the same method call, ClassAdvisor would happily add the same pointcut twice, making each call advised twice. Code to test:

      public class QuickSort {

      public static void quicksort(Comparable elements[],int start,int end) {
      if(start+1<end) {
      Middle middle=partition(elements[start],elements,start,end);
      quicksort(elements,start,middle.left);
      quicksort(elements,middle.right,end);
      }
      }
      public static class Middle {
      int left,right;
      Middle(int left,int right) {this.left=left; this.right=right;}
      }

      public static Middle partition(Comparable pivot,Comparable elements[],
      int start,int end) {
      int middle=start;
      while(middle<end) {
      if(pivot.compareTo(elements[middle]) < 0) {
      swap(elements,middle,end-1);
      end--;
      } else if(pivot.compareTo(elements[middle]) == 0) {
      middle++;
      } else {
      swap(elements,start,middle);
      start++; middle++;
      }
      }
      return new Middle(start,end);
      }
      public static void swap(Object elements[],int p1,int p2) {
      Object temp=elements[p1];
      elements[p1]=elements[p2];
      elements[p2]=temp;
      }
      }

      My calls to swap(..) are being advised. When the CallerExprEditor goes through the partition method looking for call advised calls, it finds two calls to swap and adds a pointcut object to ClassAdvisor for each one. So for each call to swap, invoke(..) on my interceptor gets called twice. No good.

      On another note, someone let me know if I'm doing the right thing here. Not much FEEDBACK being given in these forums. If there is somewhere else I should be reporting/fixing these, please let me know. I'm not experienced in open source development, a newbie as it were.

      Craig