Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[aspectj-users] Thoughts about an AspectJ classloader

Warning: this is a "Connections" style message, but I eventually get to the
point :-)

Lately I've been running into situations where NullPointerExceptions have
been causing a great deal of grief. Namely, it's been taking hours to track
the source of these down and the end-user is very unhappy to see these. On
JSPs it results in a blank page or a stack trace dumped to the browser. In
the core application framework, it typically puts the user's session into an
indeterminate state.

Looking for solutions led me to the NoNullBeyondMethodScope, NullObject, and
JavaNullProxy wiki's at c2.com/cgi/wiki?<topic>. Combining these ideas with
various pointcuts in an aspect has led to an interesting solution, but it
only works if a return value from a method is an interface. Implementing
these ideas to include concrete types (classes that aren't interfaces) in a
general fashion has proven elusive. One nice thing this has bought me is
that calling any method on the NullProxy (returned earlier by around()
advice when the null assignment occured) will throw a NPE with the
information about when the null was "assigned" as well as the current
location. Not quite the same behavior discussed in the wiki's but just as
interesting and more helpful than the typical NPE.

One thought about a "future" solution would be an AspectJ classloader that
would dynamically create a subclass where NullObject information holders
could be introduced in a fashion similar to the magic provided by dynamic
proxies for interfaces. I guess the same thing could be accomplished by
introducing an interface and it's implementation on a  class (or classes)
but causes licensing issues with code libraries I don't have access to. The
overall objective is to localize class/interface introductions to only those
classes that are impacted within a non-static type of pointcut. That is, I
could currently write introduction code on _every_ object compiled into my
system as well as the Java system (all licensing issues aside) to get the
behavior from the ONE object where a null has been assigned, but this
doesn't seem to make sense. Also, although I'm willing to use introduction
in it's current form, it does strike me as having a slightly bad smell in
that it (arguably) breaks encapsulation. I think that having sub -interfaces
or -classes that contain the introductions might be a cleaner approach.



Back to the top