bossadvisors / memcached-session-manager

Automatically exported from code.google.com/p/memcached-session-manager
0 stars 0 forks source link

Provide findbugs detector for directly initialized fields that lead to a ThreadLocal access #64

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
A wicket application comes with thread locals like Session, Application, 
Injector etc. which may cause issues during deserialization.

For kryo there's already the ComponentSerializerFactory that ensures that the 
possibly existing default constructor is not called, as this invokes 
Application.get(), which causes an error as the threadlocal is not yet 
initialized.

Still, you might create classes that access threadlocals in field 
initialization (with any levels of indirection), e.g.

class BadClass1 {
   private final Application _a = Application.get(); // bad!
   ...
}

Another example, with one level of indirection:

class SomeClass {
   private final BadClass2 _b = new BadClass2();
   ...
}
class BadClass2() {
   ...
   public BadClass2() {
      InjectorHolder.get().inject(this); // bad!
   }
}

Some static analysis like findbugs seems to be suitable to detect such 
potential errors.

Original issue reported on code.google.com by martin.grotzke on 15 Nov 2010 at 3:53