Open kriegaex opened 2 years ago
Hi @kriegaex, I am a student attending the master's degree in computer science. I am studying and using aspectJ
on a daily basis, the idea behind it is brilliant. I have a background in writing reflective code and bytecode engineering as well.
I was wondering if this part was implemented? Taking time away from other things, I wanted to start studying the repo, I saw that you are currently the maintainer, is it right?
I was wondering if this part was implemented?
@FedericoBruzzone: This has not been implemented yet, hence the open issue.
I saw that you are currently the maintainer, is it right?
Yes, this is basically correct. While not being the official project lead - that would be @aclement - I am currently the most active committer. Do you have any specific questions?
Yes, this is basically correct. While not being the official project lead - that would be @aclement - I am currently the most active committer. Do you have any specific questions?
Thanks for your time. @kriegaex I have not run into the problem of this issue. But in the next few days I will study the repo and maybe I'll ask you some question if I'm allowed.
The original enhancement request Bugzilla #95716 exists since 2005. I think it should be implemented. I needed this many times myself, and e.g. it also came up on Stack Overflow lately and last year.
Now we want to create an aspect logging something if the write access changes the field value, i.e. we need access to the old value. Another example might be to use the old value in order to calculate something from it for validation, say the new value must be no more than 25% higher than the old one.
The current workaround for
around()
looks like this:For
before()
, we need an additionalfield.setAccessible(true)
, because the code accessing the field is generated in the aspect rather than in the target class:Of course, in an AspectJ implementation there would be no reflection from the user's perspective, and a privileged aspect would be able to access non-public fields.
Syntax-wise I would keep it simple and not use something new like
oldargs(oldValue)
, but instead simply an optional second argument, i.e.set(* *) && args(newValue, oldValue)
, which would, if present, bind the old value.BTW, a reminder to myself and whoever else might need it: The way to get the field value in
get()
is toaround()
, get the current value viaproceed()
and then either pass it through or return something else,after() returning(Object value)
.