Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
RE: [aspectj-users] A new radical use of Aspects: Fixing errors in Sun's JDK with AspectJ

AspectJ can already be used to make methods behave as if they were synchronized.  You just need to add a synchronized block instead of the synchronized modifier.  The code would look something like this (the non-static version would use the this() pcd to get the appropriate object for the lock):

 

pointcut needsStaticLock(): execution(BreakIterator BreakIterator.getBreakInstance(..));

 

Object around(): needsStaticLock() {

    synchronized(thisJoinPointStaticPart.getSignature().getDeclaringType()) {

        return proceed();

    }

}

 

AspectJ-1.1 doesn’t have support for adding checked exceptions or for marking fields as volatile.  We’ve had many discussions about a ‘declare throws’ clause for adding checked exceptions, but this hasn’t led to any conclusions.  This is a very invasive change to existing code that will be likely to break existing clients of those interfaces.  As far as I remember this is the first time I’ve seen this proposal for adding volatile to existing fields, and would be worth considering for the 1.2 language design.

 

-Jim

 

For this it would be nice if AspectJ would allow me to declare intertype type-modfications to existing types like below (modification in large letters):

// Fixing a JDK bug in a future version of AspectJ:

aspect MyAspect {

private static SYNCHRONIZED java.text.BreakIterator java.text.getBreakInstance(Locale where, int type, String rulesName, String dictionaryNamed).

}

Examples of other bug-fix modifications, would be to redeclare stuff as volatile, to add declared exception (such as adding RMI exceptions to non-RMI aware code) etc.:

The above solution would be cool, but unfortunately AspectJ does not support it. Maybe good for next version of AspectJ ?

Comments ? Suggestions ?

Cheers,

Morten Ch,


Back to the top