Yes. It's hard to ban it completely; unless it's a constant primitive an assignment to a field will be moved to a static initializer. I would personally disallow it, but I can also feel the pain others must feel when they're forced to @BeforeClass every single thing, however trivial...
Dawid On Mon, Sep 1, 2014 at 10:44 PM, Ramkumar R. Aiyengar <[email protected]> wrote: > > On Mon, Sep 1, 2014 at 8:54 PM, Dawid Weiss <[email protected]> > wrote: >> >> To be honest you shouldn't have any static initializers at all, >> including final fields (unless they're really immutable, simple data >> types). The reason for this is that static initializers (including >> those for final field assignments) are invoked when the class is >> initialized and this may be happening outside of the scope of the test >> runner. @BeforeClass or class rules are the way to "properly" >> initialize before-test-suite things. > > > I was trying to see if I hack something to see if this can be checked and > realized there's a StaticFieldsInvariantRule set up in LuceneTestCase which > was checking for memory leaks on exactly such fields. So I am guessing we > are still using them a bit :) (and a quick grep confirms the same..) --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
