Using Source Directives

Clover supports a number of inline source directives that you can use in your source to control instrumentation. Directives can be on a line by themselves or part of any valid single or multi-line Java comment.

Switching Clover on and off


This directive will switch Clover instrumentation on/off. This might be useful if you don't want Clover to instrument a section of code for some reason. For example, some bytecode-manipulating frameworks require certain sections to be excluded (JMockit for instance). Note that the scope of this directive is the current file only.

Force Clover to flush


Clover will insert code to flush coverage data to disk. The flush code will be inserted as soon as possible after the directive. See Using a Flush Policy.

Mark lambda expression returning void (since Clover 4.0.5)


This directive will mark lambda expression as returning void. Clover applies heuristic for some of lambda expressions and rewrites them to lambda blocks. In case of unexpected return value compilation errors, it may be necessary to mark some lambda expressions as void to let Clover know it shouldn't instrument it with the return keyword. 


For example, the following code: -> internalMap.put("some", "some"));

may fail to compile if put() method returns void with the following error:

src/ error: incompatible types: bad return type in lambda expression -> {;
			return internalMap.put("some", "some");});           
    unexpected return value
1 error

It may be required to mark such lambda expression as void with CLOVER:VOID directive -> /* CLOVER:VOID */ internalMap.put("some", "some"));


More information about this compilation error may be found in one of the Clover KB articles


The CLOVER:VOID directive outside lambda context does not have any effect.