Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cobertura-maven-plugin does not support Java 1.8 properly #21

Open
MEZk opened this issue Jun 19, 2016 · 3 comments
Open

cobertura-maven-plugin does not support Java 1.8 properly #21

MEZk opened this issue Jun 19, 2016 · 3 comments

Comments

@MEZk
Copy link

MEZk commented Jun 19, 2016

Hello!

I have the following class which uses stream feature from Java 1.8:

import java.util.Arrays;

public class Main {
    public static boolean containsEvenNumbers(int... array) {
        return Arrays.stream(array).anyMatch(number -> isEven(number));
    }

    private static boolean isEven(int number) {
        return number % 2 == 0;
    }

}

I also wrote UT for the class:

import static org.junit.Assert.assertTrue;
import org.junit.Test;

public class MainTest {
    @Test
    public void testContainsEvenNumbers() {
        final int[] array = {1, 2, 3, 4, 5, 6, 7};
        assertTrue(Main.containsEvenNumbers(array));
    }
}

My pom.xml:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>test</groupId>
    <artifactId>com-test</artifactId>
    <version>1.0-SNAPSHOT</version>
    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>cobertura-maven-plugin</artifactId>
                <version>2.7</version>
                <configuration>
                    <check>
                    </check>
                </configuration>
                <executions>
                    <execution>
                        <goals>
                            <goal>clean</goal>
                            <goal>check</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
    <dependencies>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>RELEASE</version>
            <scope>test</scope>
        </dependency>
    </dependencies>
</project>

When I try to execute the following command:

mvn clean cobertura:cobertura

Cobertura crashes. Stack trace:

[ERROR] net.sourceforge.cobertura.javancss.parser.ParseException: Encountered " ">" "> "" at line 6, column 54.
Was expecting one of:
    "assert" ...
    "boolean" ...
    "byte" ...
    "char" ...
    "double" ...
    "enum" ...
    "false" ...
    "float" ...
    "int" ...
    "long" ...
    "new" ...
    "null" ...
    "short" ...
    "super" ...
    "this" ...
    "true" ...
    "void" ...
    <INTEGER_LITERAL> ...
    <FLOATING_POINT_LITERAL> ...
    <CHARACTER_LITERAL> ...
    <STRING_LITERAL> ...
    <IDENTIFIER> ...
    "(" ...
    "!" ...
    "~" ...
    "++" ...
    "--" ...
    "+" ...
    "-" ...

        at net.sourceforge.cobertura.javancss.parser.JavaParser.generateParseException(JavaParser.java:10490)
        at net.sourceforge.cobertura.javancss.parser.JavaParser.jj_consume_token(JavaParser.java:10366)
        at net.sourceforge.cobertura.javancss.parser.JavaParser.UnaryExpression(JavaParser.java:3175)
        at net.sourceforge.cobertura.javancss.parser.JavaParser.MultiplicativeExpression(JavaParser.java:3090)
        at net.sourceforge.cobertura.javancss.parser.JavaParser.AdditiveExpression(JavaParser.java:3085)
        at net.sourceforge.cobertura.javancss.parser.JavaParser.ShiftExpression(JavaParser.java:3027)
        at net.sourceforge.cobertura.javancss.parser.JavaParser.RelationalExpression(JavaParser.java:2990)
        at net.sourceforge.cobertura.javancss.parser.JavaParser.InstanceOfExpression(JavaParser.java:2977)
        at net.sourceforge.cobertura.javancss.parser.JavaParser.AssigmentExpression(JavaParser.java:2959)
        at net.sourceforge.cobertura.javancss.parser.JavaParser.EqualityExpression(JavaParser.java:2886)
        at net.sourceforge.cobertura.javancss.parser.JavaParser.AndExpression(JavaParser.java:2860)
        at net.sourceforge.cobertura.javancss.parser.JavaParser.ExclusiveOrExpression(JavaParser.java:2843)
        at net.sourceforge.cobertura.javancss.parser.JavaParser.InclusiveOrExpression(JavaParser.java:2826)
        at net.sourceforge.cobertura.javancss.parser.JavaParser.ConditionalAndExpression(JavaParser.java:2808)
        at net.sourceforge.cobertura.javancss.parser.JavaParser.ConditionalOrExpression(JavaParser.java:2790)
        at net.sourceforge.cobertura.javancss.parser.JavaParser.ConditionalExpression(JavaParser.java:2774)
        at net.sourceforge.cobertura.javancss.parser.JavaParser.Expression(JavaParser.java:2718)
        at net.sourceforge.cobertura.javancss.parser.JavaParser.ArgumentList(JavaParser.java:3620)
        at net.sourceforge.cobertura.javancss.parser.JavaParser.Arguments(JavaParser.java:3610)
        at net.sourceforge.cobertura.javancss.parser.JavaParser.PrimarySuffix(JavaParser.java:3511)
        at net.sourceforge.cobertura.javancss.parser.JavaParser.PrimaryExpression(JavaParser.java:3384)
        at net.sourceforge.cobertura.javancss.parser.JavaParser.PostfixExpression(JavaParser.java:3330)
        at net.sourceforge.cobertura.javancss.parser.JavaParser.UnaryExpressionNotPlusMinus(JavaParser.java:3237)
        at net.sourceforge.cobertura.javancss.parser.JavaParser.UnaryExpression(JavaParser.java:3171)
        at net.sourceforge.cobertura.javancss.parser.JavaParser.MultiplicativeExpression(JavaParser.java:3090)
        at net.sourceforge.cobertura.javancss.parser.JavaParser.AdditiveExpression(JavaParser.java:3061)
        at net.sourceforge.cobertura.javancss.parser.JavaParser.ShiftExpression(JavaParser.java:3027)
        at net.sourceforge.cobertura.javancss.parser.JavaParser.RelationalExpression(JavaParser.java:2990)
        at net.sourceforge.cobertura.javancss.parser.JavaParser.InstanceOfExpression(JavaParser.java:2977)
        at net.sourceforge.cobertura.javancss.parser.JavaParser.AssigmentExpression(JavaParser.java:2959)
        at net.sourceforge.cobertura.javancss.parser.JavaParser.EqualityExpression(JavaParser.java:2886)
        at net.sourceforge.cobertura.javancss.parser.JavaParser.AndExpression(JavaParser.java:2860)

The full stacktrace.txt.

Nevertheless, Cobertura works fine if it is run with the following command:

mvn clean cobertura:check
@hongdili
Copy link

"cobertura:cobertura" still generates the coverage report, with the error on lamdas "->" syntax. The report looks fine in my simple case.

@MEZk
Copy link
Author

MEZk commented Feb 21, 2017

Cobertura also skips classes which have import from java.util.stream package. For example, if the class imports java.util.stream.Stream, Cobertura will not generate coverage report for the class. The problem is also mentioned in #18 where you can find an example project.

@langley-agm
Copy link

Also fails when using the "default" keyword in interface methods:

[ERROR] net.sourceforge.cobertura.javancss.parser.ParseException: Encountered " "default" "default "" at line 38, column 5.
Was expecting one of:
    "abstract" ...
    "boolean" ...

joschi pushed a commit to Graylog2/graylog2-server that referenced this issue Mar 5, 2018
The Cobertura Maven plugin (and Cobertura itself) doesn't support Java 8.

Additionally, code coverage metrics are currently not used anywhere in the build,
so we can as well remove it.

Refs mojohaus/cobertura-maven-plugin#21
Refs cobertura/cobertura#166
bernd pushed a commit to Graylog2/graylog2-server that referenced this issue Mar 9, 2018
The Cobertura Maven plugin (and Cobertura itself) doesn't support Java 8.

Additionally, code coverage metrics are currently not used anywhere in the build,
so we can as well remove it.

Refs mojohaus/cobertura-maven-plugin#21
Refs cobertura/cobertura#166
michael-schnell added a commit to fuinorg/units4j that referenced this issue May 19, 2018
oyarzun added a commit to oyarzun/netbeans-mavenutils-nbm-maven-plugin that referenced this issue Jan 10, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants