Skip to main content

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

At our company we have had the unfortunate experience of being forced to downgrade to JDK1.3.x because of numerous errors in JDK1.4.x. Error reports to Sun have been made but we got few if any answers (I guess the people at Sun are currently busy with other things than reacting to bug-reports). Therefore we have had to do the workarounds/fixes ourselves (none of them being very nice so far).

Most of our problems can clearly be identified as MT-bugs in the Java source files (missing synchronized declarations).

Here is an example extract from Sun's JDK1.4.2 source:

package java.text; // Extract (nb. (c) Sun & Taligent. See orginal source for details).

public abstract class BreakIterator implements Cloneable

{

private static final SoftReference[] iterCache = new SoftReference[4];

public static BreakIterator getWordInstance(Locale where) {

return getBreakInstance(where, WORD_INDEX, "WordBreakRules", "WordBreakDictionary");

}

private static BreakIterator getBreakInstance(Locale where, int type, String rulesName, String dictionaryName) {

if (iterCache[type] != null) {

BreakIteratorCache cache = (BreakIteratorCache) iterCache[type].get();

if (cache != null) {

if (cache.getLocale().equals(where)) {

return cache.createBreakInstance();

}

}

}

BreakIterator result = createBreakInstance(where, type, rulesName, dictionaryName);

BreakIteratorCache cache = new BreakIteratorCache(where, result);

iterCache[type] = new SoftReference(cache);

return result;

}

}

 

Clearly the JDK1.4.2 code above is not MT-safe (see statements involving iterCache). One of the methods need to be syncrhonized to fix the problem.

Since I do not know when/if Sun will fix it, the big question now is: Can I use AspectJ to fix this and similar bugs ?

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,

AArhus, Denmark

 

 

------------
Yahoo! Mail - Gratis: 6 MB lagerplads, spamfilter og virusscan


Back to the top