Hi Andrew,

thanks, i changed it in the suggested way.

I've got one last question. I'm trying to capture the finalize calls of the
IO objects.

The pointcut(s) I use are these:

public pointcut writerFinalize() : call(void finalize())
            &&(target(FileWriter)||target(PrintWriter));
public pointcut randomAccessFileFinalize() : call(void finalize())
     &&target(RandomAccessFile);

public pointcut finalizeAll() : writerFinalize() ||
randomAccessFileFinalize() || ...

the advice:

    after() : finalizeAll(){
        System.err.println("finalize...");
        close(thisJoinPoint.getTarget());
    }

I added the JRE to the inpath

Again, the warning "advice has not been applied" occurs.

Changing the pointcuts into execution-pointcuts, the warning disappears,
although the advice isn't executed.
In addition, I tried to change the advice into before(): finalizeAll(),
without success.
Is there a possibility to capture finalize at all?
Or does the execution-pointcut apply and it is simply the VM that does not
call finalize?

Christoph


2009/10/13 Andrew Eisenberg <[email protected]>

> Hi Christoph,
>
> Your problem here is that for call() pointcuts, there is no target
> object (ie- it is always null).  The best way I can think of
> implementing your strategy is by using an internal map to keep track
> of boundTo objects.
>
> Can anyone think of a better solution?
>
> On Tue, Oct 13, 2009 at 6:55 AM, Christoph Kurrat
> <[email protected]> wrote:
> > Hi,
> >
> > I'm trying to log read and write accesses with aspectJ.
> > To do this, I want to capture the constructor calls, read and write calls
> > and close calls of, for example, RandomAccessFile objects.
> > The logged data shall be saved inside the aspect. For this reason, I want
> to
> > use pertarget to capture constructor invocations. The problem is, that
> the
> > used pointcut doesn't seem to work; neither an aspect instance is
> created,
> > nor the advice for the constructor is used; i get a "advice has not been
> > applied" message.
> >
> > These are the pointcuts used to capture the constructor calls.
> >
> > public pointcut randomAccessFileCreation() :
> call(RandomAccessFile.new(..));
> > public pointcut writerCreation() : (call(FileWriter.new(..)) ||
> > call(PrintWriter.new(File,..)) || call(PrintWriter.new(String,..)));
> >
> > These pointcuts (and more, for example readerCreation() following the
> same
> > principle) are joined with the newAspect() pointcut:
> >
> > public pointcut newAspect() : writerCreation() ||
> > randomAccessFileCreation();
> >
> >
> > The aspect is defined like this:
> > public privileged aspect loggingAspect pertarget(newAspect()){
> >
> >
> > The advice belonging to the newAspect() pointcut:
> >     after() returning(Object obj) : newAspect(){
> >         boundTo = obj;
> >         System.err.println("new Object " + boundTo);
> >         log.setTimeOpen(Calendar.getInstance().getTime());
> >         }
> >     }
> >
> > In the constructor of the aspect, i print a log message, too.
> >
> > None of the log messages is printed during the execution of the program.
> >
> > What am i doing wrong here?
> >
> > Thanks
> >
> > Christoph
> >
> > _______________________________________________
> > aspectj-users mailing list
> > [email protected]
> > https://dev.eclipse.org/mailman/listinfo/aspectj-users
> >
> >
> _______________________________________________
> aspectj-users mailing list
> [email protected]
> https://dev.eclipse.org/mailman/listinfo/aspectj-users
>
_______________________________________________
aspectj-users mailing list
[email protected]
https://dev.eclipse.org/mailman/listinfo/aspectj-users

Reply via email to