Spotless 6.0.4 fails with `Object.hashCode` exception
See original GitHub issueToday, I received a Dependabot update for Spotless on Mockito: https://github.com/mockito/mockito/pull/2501 The build failed (https://github.com/mockito/mockito/runs/4450375421?check_suite_focus=true) with the following exception:
Execution failed for task ':compileJava'.
> Cannot invoke "Object.hashCode()" because "key" is null
Gradle version: 7.2 Spotless: 6.0.4 (works fine with 6.0.2)
Configuration:
spotless {
// We run the check separately on CI, so don't run this by default
enforceCheck = false
java {
licenseHeaderFile rootProject.file('config/spotless/spotless.header')
custom 'google-java-format', { source ->
com.google.googlejavaformat.java.JavaFormatterOptions options = new com.google.googlejavaformat.java.JavaFormatterOptions.Builder()
.style(com.google.googlejavaformat.java.JavaFormatterOptions.Style.AOSP)
.formatJavadoc(false)
.build()
com.google.googlejavaformat.java.Formatter formatter = new com.google.googlejavaformat.java.Formatter(options)
return formatter.formatSource(source)
}
// This test contains emulation of same-line stubbings. The formatter would put them on a separate line.
targetExclude 'src/test/java/org/mockitousage/internal/junit/UnusedStubbingsFinderTest.java'
}
}
Issue Analytics
- State:
- Created 2 years ago
- Comments:6 (2 by maintainers)
Top Results From Across the Web
Latest spotless and gradle fails to recognize gradle 'build' task
1 Answer 1 ... while I can't fully explain what was happening that is working with the older version of spotless, the 'magical'...
Read more >Java equals() and hashCode() - DigitalOcean
Object class equals() method implementation returns true only when both the references are pointing to same object. Java hashCode(). Java Object ...
Read more >Plugin: com.diffplug.gradle.spotless
Using the plugins DSL: plugins { id "com.diffplug.gradle.spotless" version "6.12.0" }. Using legacy plugin application: buildscript { repositories { maven ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Hmm, very strange. I can confirm on my machine that the mockito build with Spotless
6.0.2
works, and bumping to6.0.4
breaks. But the failed task is:compileJava
, not a spotless task, and the stacktrace doesn’t touch any Spotless classes…stacktrace
The null is from L71 of the little section below.
https://github.com/gradle/gradle/blob/a773786b58bb28710e3dc96c4d1a7063628952ad/subprojects/language-java/src/main/java/org/gradle/api/internal/tasks/compile/tooling/JavaCompileTaskSuccessResultPostProcessor.java#L70-L76
It’s passing null on a get() of this ConcurrentHashMap.
https://github.com/gradle/gradle/blob/a773786b58bb28710e3dc96c4d1a7063628952ad/subprojects/language-java/src/main/java/org/gradle/api/internal/tasks/compile/tooling/JavaCompileTaskSuccessResultPostProcessor.java#L45
Updating Gradle to
7.3.1
(which is technically the first version to support Java 17) fixes the issue, even with Spotless6.0.4
. I suspect the issue was actually caused by #1014 where we changed the order in which Spotless hooks theclean
task. I think this change was correct, but exposed a bug in the Gradle task graph, which got fixed between7.2
and7.3.1
.Can you update Gradle to
7.3.1
?This sounds a bit similar to #1087 but maybe it is only superficially related.