Project: clover
Issue CLOV-1481: Invalid instrumentation code for test methods inside anonymous inline classes
Clover generates incorrect reference to the static field __CLR3_2_2_TEST_NAME_SNIFFER in case when a test method is declared inside an inner (static or non-static) or inside an anonymous inline class, which are located inside a non-test top-level class. In such case, the top-level class doesn't have the __CLR3_2_2_TEST_NAME_SNIFFER field (as it's not a test class), but inner/inline classes (which are test ones) are trying to access this field. {noformat} [clover] 2 test methods detected. [javac] ---------- [javac] 1. ERROR in ... [javac] public boolean test() {__CLR3_2_262c962c9htee2hlb.R.globalSliceStart(getClass().getName(),284284);int $CLV_p$=0;java.lang.Throwable $CLV_t$=null;try {boolean $CLV_r$=__CLR3_2_2qua64563cs();$CLV_p$=1;return $CLV_r$;} catch(java.lang.Throwable $CLV_t2$){if($CLV_p$==0&&$CLV_t$==null){$CLV_t$=$CLV_t2$;}_CLR3_2_262c962c9htee2hlb.R.rethrow($CLV_t2$);return false;}finally{CLR3_2_262c962c9htee2hlb.R.globalSliceEnd(getClass().getName(),"com.xyz.RuntimeDebugger.SaveTestCaseAction.getDefaultAvailablePredicate.test",CLR3_2_2_TEST_NAME_SNIFFER.getTestName(),284284,$CLV_p$,$CLV_t$);}}private boolean __CLR3_2_2qua64563cs(){_CLR3_2_262c962c9htee2hlb.R.inc(284284); [javac] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ [javac] __CLR3_2_2_TEST_NAME_SNIFFER cannot be resolved [javac] ---------- [javac] 1 problem (1 error) {noformat} Code example: {code:java} public class SnifferInInnerAndInline { interface TestAction { boolean test(); } static class InnerStaticTest { public void testInnerStatic() { // FAILS HERE } } class InnerTest { public void testInnerNonStatic() { // FAILS HERE } } TestAction testWithInline() { return new TestAction() { public boolean test() { // FAILS HERE (assuming that we have a custom test pattern which matches it) return true; } }; } public static void main(String[] args) { new SnifferInInnerAndInline.InnerStaticTest().testInnerStatic(); new SnifferInInnerAndInline().new InnerTest().testInnerNonStatic(); new SnifferInInnerAndInline().testWithInline().test(); } } {code}
Story points: 2