Compilation error with Clover enabled - variable of type Object

Still need help?

The Atlassian Community is here for you.

Ask the community

Symptoms

Clover instrumented code fails to compile with following error:

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

Where original code looks like:

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

 

Cause

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. 

Solution 

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

    public static Stream<String> test(List<String> input) {
    	return input.stream()
                .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

      <configuration>
         <instrumentLambda>all_but_reference</instrumentLambda>
      </configuration>
    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 - Getting issue details... STATUS

CLOV-1465 - Getting issue details... STATUS

 

Last modified on Jul 9, 2015

Was this helpful?

Yes
No
Provide feedback about this article
Powered by Confluence and Scroll Viewport.