With Spring 2.5.6, Spring agent 2.5.6 and AspectJ 1.6.2 (no application server whatsoever involved---I have an SWT application), I've recently observed two obscure problems concerning LTW and @Configurable auto-wiring that occur only under certain rare circumstances and are thus hard to reproduce.
1. Assignment To Instance Fields May Fail
Auto-wiring may not work if a newly-created object is assigned to an instance field somewhere in a compilation unit. I've experienced situations where code like this wouldn't work although I think it should:
Code:
public class MyApp {
@Configurable
static class MyWindow extends Window {
@Resource
ApplicationContext context;
}
MyWindow field;
void init1() {
// Assignment to instance field: auto-wiring fails
field = new MyWindow();
}
void init2() {
// This, however, will work, but only if ‘init1()’ is commented out!!
MyWindow var = new MyWindow();
}
}
2. Auto-Wiring Seems to Be Thread-Dependent
I've seen situations where auto-wiring configurables fails when they are created in separate threads, like this:
Code:
new Thread(new Runnable() {
public void run() {
// We are in a separate thread---auto-wiring may fail!
MyWindow win = new MyWindow();
}
}).start();
However, creating a ‘MyWindow’ instance beforehands in the main thread will be a workaround and ensure the load-time weaver will work as expected in other threads as well.
*
Admittedly, I'm neither a Spring nor an AOP expert, but I'm puzzled and believe things shouldn't behave the way they apparently do. It's not easy to set up small stand-alone Maven projects that reveal these spooky problems. So, before taking the effort to do this, I'd like to pose two questions:
1) Is any of this familiar to anyone or known already?
2) Who'd actually be able to look into and, more importantly, look after this? Have I come to the right place at all?
Best
Phil