bmuschko / gradle-clover-plugin

Gradle plugin for generating a code coverage report using Clover
Apache License 2.0
74 stars 49 forks source link

HTML Reporter throwing null pointer error (NPE) #146

Closed DSEyers closed 4 years ago

DSEyers commented 4 years ago

Getting NPE when request Clover to generate HTML file. If set to false can get XML file fine.

MacOS Catalina - version 10.15.3

build.gradle snippet // Declare Gradle plugins to be used plugins { id 'eclipse' // Add support for Eclipse id 'findbugs' // FindBugs plugin: http://findbugs.sourceforge.net/ id 'java-library' // Add support for building Java libraries id 'com.bmuschko.clover' version '2.2.4' // Add coverage reporting }

dependencies { // Project resources implementation( // External resources 'org.apache.commons:commons-lang3:3.9', 'org.apache.logging.log4j:log4j-api:2.8.2', 'org.apache.logging.log4j:log4j-core:2.8.2', 'org.json:json:20171018', 'org.ini4j:ini4j:0.5.4', 'mysql:mysql-connector-java:8.0.18', 'com.google.code.findbugs:annotations:3.0.1', ) // Test resources testImplementation( // External resources 'junit:junit:4.12', 'org.junit.jupiter:junit-jupiter-api:5.5.0', 'org.powermock:powermock-api-mockito:1.6.4', 'org.powermock:powermock-module-junit4:1.6.4', ) clover 'org.openclover:clover:4.3.1' }

// Settings for the Clover coverage report -- not a task; See cloverGenerateReport clover { enabled = true

    report {
            html = true
            xml  = true
            pdf = false

            // Support capturing test results from JUnix XML report
            testResultsInclude = 'TEST-*.xml'
            testResultsDir = reportDir
    }

}

Stacktrace What went wrong: Execution failed for task ':cloverGenerateReport'.

com.atlassian.clover.api.CloverException: java.lang.NullPointerException

Alex-Vol-SV commented 4 years ago

There is nothing I can see from this stack trace within the control of this plugin. The error appears internal to the OpenClover library implementation. I think you need to raise this as an issue with OpenClover instead.

marek-parfianowicz commented 4 years ago

Caused by: java.lang.NullPointerException at clover.org.jfree.chart.axis.ValueAxis.findMaximumTickLabelWidth(ValueAxis.java:916)

Code: >>> FontMetrics fm = g2.getFontMetrics(font);

A problem with graphics, maybe? A DISPLAY is missing? A font is missing?

Alex-Vol-SV commented 4 years ago

There is a very easy fix for this issue. Add the following to your gradle.properties

systemProp.java.awt.headless=true

Neither Gradle tools and plugins nor this plugin really need an actual graphics display to perform their work. I use this in my build and eliminate the problem.

Alex-Vol-SV commented 4 years ago

Since this is a common kind of failure when advanced options are used I will take the time to add a documentation pointer to this solution.

DSEyers commented 4 years ago

Afraid didn't work.


Gradle 4.4.1

Build time: 2017-12-20 15:45:23 UTC Revision: 10ed9dc355dc39f6307cc98fbd8cea314bdd381c

Groovy: 2.4.12 Ant: Apache Ant(TM) version 1.9.9 compiled on February 2 2017 JVM: 1.8.0_242 (Eclipse OpenJ9 openj9-0.18.1) OS: Mac OS X 10.15.3 x86_64

Error [ant:clover-report] null java.lang.NullPointerException at com.atlassian.clover.reporters.html.RenderFileAction.call(RenderFileAction.java:111) at com.atlassian.clover.util.CloverExecutors$LoggingCallable.call(CloverExecutors.java:91) at java.util.concurrent.FutureTask.run(FutureTask.java:266) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) at java.lang.Thread.run(Thread.java:821)

Build.gradle (snippets with clover in only) plugins { id 'com.bmuschko.clover' version '2.2.0' // Add coverage reporting: https://github.com/bmuschko/gradle-clover-plugin }

dependencies { clover 'org.openclover:clover:4.2.0' }

On Thu, 27 Feb 2020 at 17:28, Alexander Volanis (HPE) < notifications@github.com> wrote:

Since this is a common kind of failure when advanced options are used I will take the time to add a documentation pointer to this solution.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/bmuschko/gradle-clover-plugin/issues/146?email_source=notifications&email_token=AED2WD2KM5B6WW4TBDWBEJDRE7Z4NA5CNFSM4KQ7TET2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOENFG55Y#issuecomment-592080631, or unsubscribe https://github.com/notifications/unsubscribe-auth/AED2WD3FYEGBNETOOJUVUNDRE7Z4NANCNFSM4KQ7TETQ .

Alex-Vol-SV commented 4 years ago

Nothing more I can do for you, this failure is inside the shaded library org.jfree.chart within the OpenClover tools. You might want to try also setting GRADLE_OPTS=-Djava.awt.headless=true

marek-parfianowicz commented 4 years ago

com.atlassian.clover.reporters.html.RenderFileAction.call( RenderFileAction.java:111)

Corresponds to

https://bitbucket.org/openclover/clover/src/edf4c673a0e6f3967b80888714fb71109b38a6c4/clover-core/src/main/java/com/atlassian/clover/reporters/html/RenderFileAction.java#lines-111

So it has to throw NPE on columnsTL. Check how many rendering threads you use and please try with one thread whether it helps.

In Ant it is named "numThreads" see http://openclover.org/doc/manual/latest/ant--clover-report.html

I don't know if gradle plugin has corresponding option...

Also please check what columns you have defined - maybe they're empty and this is a cause of NPE?

On Fri, Feb 28, 2020, 17:20 Alexander Volanis (HPE) < notifications@github.com> wrote:

Nothing more I can do for you, this failure is inside the shaded library org.jfree.chart within the OpenClover tools. You might want to try also setting GRADLE_OPTS=-Djava.awt.headless=true

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/bmuschko/gradle-clover-plugin/issues/146?email_source=notifications&email_token=AFH6KQLWHRZB4774EO4Q4BTRFE2TVA5CNFSM4KQ7TET2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOENJCNTI#issuecomment-592586445, or unsubscribe https://github.com/notifications/unsubscribe-auth/AFH6KQJX4I26BZVGE4CSZYDRFE2TVANCNFSM4KQ7TETQ .

marek-parfianowicz commented 4 years ago

Also, did you try with the latest OpenClover version i.e. 4.4.1? I see 4.2.0 and 4.3.1 in logs...

On Fri, Feb 28, 2020, 17:28 Marek Parfianowicz marek.parfianowicz@gmail.com wrote:

com.atlassian.clover.reporters.html.RenderFileAction.call( RenderFileAction.java:111)

Corresponds to

https://bitbucket.org/openclover/clover/src/edf4c673a0e6f3967b80888714fb71109b38a6c4/clover-core/src/main/java/com/atlassian/clover/reporters/html/RenderFileAction.java#lines-111

So it has to throw NPE on columnsTL. Check how many rendering threads you use and please try with one thread whether it helps.

In Ant it is named "numThreads" see http://openclover.org/doc/manual/latest/ant--clover-report.html

I don't know if gradle plugin has corresponding option...

Also please check what columns you have defined - maybe they're empty and this is a cause of NPE?

On Fri, Feb 28, 2020, 17:20 Alexander Volanis (HPE) < notifications@github.com> wrote:

Nothing more I can do for you, this failure is inside the shaded library org.jfree.chart within the OpenClover tools. You might want to try also setting GRADLE_OPTS=-Djava.awt.headless=true

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/bmuschko/gradle-clover-plugin/issues/146?email_source=notifications&email_token=AFH6KQLWHRZB4774EO4Q4BTRFE2TVA5CNFSM4KQ7TET2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOENJCNTI#issuecomment-592586445, or unsubscribe https://github.com/notifications/unsubscribe-auth/AFH6KQJX4I26BZVGE4CSZYDRFE2TVANCNFSM4KQ7TETQ .

Alex-Vol-SV commented 4 years ago

For Gradle you can use --max-workers=1 to avoid running parallel tests that get Clover rendering in trouble.

Alex-Vol-SV commented 4 years ago

If this is is an option for the Ant tasks I can add it to the Gradle plugin, we are using Ant tasks for integration. Thanks @marek-parfianowicz

marek-parfianowicz commented 4 years ago

Exception is thrown during report generation, I'm talking about Clover's HTML rendering threads. So probably

you can use --max-workers=1 to avoid running parallel tests

won't help here.

On Fri, Feb 28, 2020, 17:37 Alexander Volanis (HPE) < notifications@github.com> wrote:

For Gradle you can use --max-workers=1 to avoid running parallel tests that get Clover rendering in trouble.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/bmuschko/gradle-clover-plugin/issues/146?email_source=notifications&email_token=AFH6KQPLHATC55O322LJIR3RFE4VDA5CNFSM4KQ7TET2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOENJEIVQ#issuecomment-592594006, or unsubscribe https://github.com/notifications/unsubscribe-auth/AFH6KQIG47WYUEU2TWQ5KXDRFE4VDANCNFSM4KQ7TETQ .

DSEyers commented 4 years ago

None of the solutions worked. Going to file ticker with OpenClover group and thanks for all your help.

Alex-Vol-SV commented 4 years ago

If I have time this week I will try to expose the maxThreads option for report generation so you can try that approach as well.

marek-parfianowicz commented 4 years ago
  1. Yes, it would be great to add a maxThreads option, at least we could check if the workaround works.

  2. What Java version do you use to execute Gradle? I'm asking, because Clover was tested up to JDK 9 and probably won't run on newer JDK.

  3. If the NPE is thrown from the columnsTL.get() then resetThreadLocals must have been called (as it sets the field to null, by default it's new ThreadLocal<List<Column>>()). It's being called on cleanup, see https://bitbucket.org/openclover/clover/src/24bfea8880f06e225e95a341813056b664dd3a1f/clover-core/src/main/java/com/atlassian/clover/reporters/html/HtmlReporter.java?at=default#lines-315

Maybe the Timeout of XXX reached during report generation. Please increase this value and try again. was reached? Could you check logs, please?

Alex-Vol-SV commented 4 years ago

I added the timeout interval and numThreads options in the 2.2.5 version. It should appear in the plugins portal within 24 hours.

Perhaps either or both of these options will make a difference.

DSEyers commented 4 years ago

Java 1.8.232 have been using

On Mon, 9 Mar 2020, 17:39 Marek Parfianowicz, notifications@github.com wrote:

1.

Yes, it would be great to add a maxThreads option, at least we could check if the workaround works. 2.

What Java version do you use to execute Gradle? I'm asking, because Clover was tested up to JDK 9 and probably won't run on newer JDK. 3.

If the NPE is thrown from the columnsTL.get() then resetThreadLocals must have been called (as it sets the field to null, by default it's new ThreadLocal<List>()). It's being called on cleanup, see https://bitbucket.org/openclover/clover/src/24bfea8880f06e225e95a341813056b664dd3a1f/clover-core/src/main/java/com/atlassian/clover/reporters/html/HtmlReporter.java?at=default#lines-315

Maybe the Timeout of XXX reached during report generation. Please increase this value and try again. was reached? Could you check logs, please?

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/bmuschko/gradle-clover-plugin/issues/146?email_source=notifications&email_token=AED2WD4DTBAOANOHGQU4X53RGUSULA5CNFSM4KQ7TET2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEOIIVLA#issuecomment-596675244, or unsubscribe https://github.com/notifications/unsubscribe-auth/AED2WD4MHZ6FFHTIRMB2Z4TRGUSULANCNFSM4KQ7TETQ .

DSEyers commented 4 years ago

I tried a few things, but not able to get the updated plugin seen.

Tried:

And in a lank new folder creating and running build.grade with full contents of:

buildscript { repositories { jcenter() }

    dependencies {
        classpath 'com.bmuschko:gradle-clover-plugin:2.2.5'
    }
}

Also just incrementing version in the project and running Gradle. We using Gradle 4.4.1 and plugin syntax used is:

plugins { id 'com.bmuschko.clover' version '2.2.5' }

repositories { mavenCentral() jcenter() }

Alex-Vol-SV commented 4 years ago

There was an issue with the Gradle plugin portal. The Gradle team is fixing it. The release will be available from there soon I hope.

Alex-Vol-SV commented 4 years ago

If you are trying it locally you need to add mavenLocal() to the repositories. You only have mavenCentral() and jcenter()

Alex-Vol-SV commented 4 years ago

When you use the plugins closure DSL to load it you also need to add mavenLocal() to the settings.gradle under pluginManagement closure.

Alex-Vol-SV commented 4 years ago

Plugin 2.2.5 is now available at the Gradle portal. Try it out with the suggestions @marek-parfianowicz made.

This is how you configure them

clover {
    report {
        numThreads = 1
        timeout = '30 seconds'
    }
}

Default timeout is no-timeout so it is unlikely you reached a timeout. numThreads = 0 according to OpenClover docs disables multithreading, I suppose it is probably better in some ways than 1 thread.

DSEyers commented 4 years ago

Afraid still get NPE issue

On earlier update around installing locally thanks info on gradle.settings file.

When trying to generate the plugin was showing on the console as:

Configure project : Reckoned version: 0.0.1-milestone.0.0+20200312T173042Z

A resolution was to add version o file build.gradle. gradlePlugin { plugins { gradleCloverPlugin { id = 'com.bmuschko.clover'

On Fri, 13 Mar 2020 at 00:12, Alexander Volanis (HPE) < notifications@github.com> wrote:

Plugin 2.2.5 is now available at the Gradle portal. Try it out with the suggestions @marek-parfianowicz https://github.com/marek-parfianowicz made.

This is how you configure them

clover { report { numThreads = 1 timeout = '30 seconds' } }

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/bmuschko/gradle-clover-plugin/issues/146#issuecomment-598486305, or unsubscribe https://github.com/notifications/unsubscribe-auth/AED2WDYUEUJVEHR2KPHNKC3RHF255ANCNFSM4KQ7TETQ .

Alex-Vol-SV commented 4 years ago

We use the reckon plugin to discover the version assuming you are cloning the git repository which brings in the release tags. You did not clone the repository which means you did not get the git tags therefore your version was 0.0.1.

Sorry this did not make your problem better. This is unique and completely within the OpenClover library so I cannot tell why you get this. Did you actually change the clover configuration as suggested above? That is how it would work, the new version would not be the fix, the configuration change would be the fix.