Clover Knowledge Base : Compilation error with Clover enabled - variable of type Object


Clover instrumented code fails to compile with following error:

src/ error: cannot find symbol
                .filter(e -> {;return !e.isEmpty();});
  symbol:   method isEmpty()
  location: variable e of type Object
src/ error: incompatible types: Stream<Object> cannot be converted to Stream<String>
                .filter(e -> {;return !e.isEmpty();});
2 errors

Where original code looks like:

public static Stream<String> test(List<String> input) {
            .filter(e -> !e.isEmpty());



Clover proxies lambda expression with method wrapper defined with generic signatures. Type inferring algorithm JDK 8 the compiler uses has its own limitations and the compiler may not be able to infer proper type when a method reference is used and which results in compilation error. Since it's not possible to apply the same heuristics for method references as Clover uses for lambda expressions compilation of instrumented code fails. 


  1. Rewrite method references into lambda expressions, ideally into lambda block, i.e

    public static Stream<String> test(List<String> input) {
                .map(e -> e.toUpperCase)  // was String::toUpperCase
                .filter(e -> !e.isEmpty());

  2. Disable instrumentation of method references (since 4.0.5) 

    Use instrumentLambda = "all_but_reference", "block", "expression" or "none"

    1. Ant - build.xml

      <clover-setup instrumentLambda="all_but_reference"/>


    2. Maven - pom.xml

    3. Grails - BuildConfig.groovy

      clover {
         instrumentLambda = "all_but_reference"
    4. Eclipse

      Open Project PropertiesClover page > Instrumentation tab. 
      In Miscellaneous box select proper value in Instrument lambda functions drop-down.

    5. IntelliJ IDEA
      Open File > Settings > Project Settings > Clover page > Compilation.
      In Miscellaneous box select proper value in Instrument lambda functions drop-down. 



Bug tracker:

CLOV-1762 - Instrumentation of method references with no compilation errors Open

CLOV-1465 - Instrumentation of expression-like lambdas with no compilation errors in all cases Open