713

Get the value of the accessed field within a get pointcut

Question:

I have a pointcut which listens to access to an field in DBRow and all subclasses

before(DBRow targ) throws DBException: get(@InDB * DBRow+.*) && target(targ) { targ.load(); }

I now need to determine the value of the accesed field, that is specified by the get pointcut. Is this possible in AspectJ?

Answer1:

For set() pointcuts you can bind the value via args(), but not for get() pointcuts. So in order to get the value without any hacky reflection tricks, just use an around() advice instead of before(). This way you can get the field value as a return value of proceed():

<pre class="lang-java prettyprint-override">Object around(DBRow dbRow) : get(@InDB * DBRow+.*) && target(dbRow) { Object value = proceed(dbRow); System.out.println(thisJoinPoint); System.out.println(" " + dbRow + " -> " + value); dbRow.load(); return value; }

Recommend

  • berkeley DB: can't compile c++ codes
  • org.aspectj.lang.NoAspectBoundException - method ()V not found
  • Spring Boot Ambiguous mapping. Cannot map method
  • no longer possible in Spring 3.1
  • Spring AOP :- Getting parameterNames as null in the joinPoint
  • How to determine the CCSID used in CPYFRMIMPF command?
  • How to discover Font Type?
  • How can i dump blob fields from mysql tables
  • How do I get the list of bad records that didn't load in Bigquery?
  • Hash Code in SQL Server?
  • How to autopopulate a field in SugarCRM form
  • Login not working in Firefox in Meteor
  • C# program and C++ DLL compiled for 32-bit system crash on 64-bit system
  • Loading .coffee files via a view in Rails
  • Inline R code in YAML for rmarkdown doesn't run
  • Thread safety of a fluent like class using clone() and non final fields
  • Create DicomImage from scratch using Dcmtk
  • Retrieve list of sent friend requests from friend_request FQL table
  • MongoDb aggregation
  • The plugin 'org.apache.maven.plugins:maven-jboss-as-plugin' does not exist or no valid ver
  • How to rebase a series of branches?
  • Using variable in a value field in jMeter
  • Linq Objects Group By & Sum
  • Retrieving value from sql ExecuteScalar()
  • Shallow update not allowed (git > 1.9)
  • jquery mobile loadPage not working
  • Rearranging Cells in UITableView Bug & Saving Changes
  • Apache 2.4 - remove | delete | uninstall
  • Circular dependency while pushing http interceptor
  • Linker errors when using intrinsic function via function pointer
  • Windows forms listbox.selecteditem displaying “System.Data.DataRowView” instead of actual value
  • How to include full .NET prerequisite for Wix Burn installer
  • Unit Testing MVC Web Application in Visual Studio and Problem with QTAgent
  • KeystoneJS: Relationships in Admin UI not updating
  • Benchmarking RAM performance - UWP and C#
  • Hits per day in Google Big Query
  • FormattedException instead of throw new Exception(string.Format(…)) in .NET
  • Qt: Run a script BEFORE make
  • Checking variable from a different class in C#
  • How to load view controller without button in storyboard?