Clover Knowledge Base : Compilation error with Clover enabled - unexpected return value


Clover-instrumented code fails to compile with a following error:

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



Since version 4.0.5, Clover tries to resolve some compilation errors listed here by rewriting some of lambda expressions to lambda blocks. Clover looks for JDK's and some of Guava classes' with lambda expression as an argument and rewrites them into a lambda block. However, if the lambda passed as argument returns void, it will cause a compilation error:

For example, a lambda expression: -> System.out.println("Hello: " + a))

will be rewritten as follows: -> { return System.out.println("Hello: " + a);}) 

The full list of methods which are affected can be found here


1) Please use CLOVER:VOID directive to instruct Clover that this specific lambda does not return a value, as follows:

(a) -> /*CLOVER:VOID*/ System.out.println("Hello: " + a)


(a) -> //CLOVER:VOID
		System.out.println("Hello: " + a)

2) Alternatively, you can disable instrumentation of lambda functions (use instrumentLambda = block or none).