Details
-
Bug
-
Status: Closed
-
Major
-
Resolution: Duplicate
-
2.4.12
-
None
-
None
-
Windows 10, Gradle 4.2.1
Description
I'm sorry for the hard repro, but I couldn't figure it out with a smaller one.
1. https://github.com/TWiStErRob/net.twisterrob.gradle.quality/tree/groovy-cast-bug
2. gradlew test (if you're lucky it runs and fails, otherwise don't fret there's an other way)
Test fails:
Caused by: java.lang.ClassCastException: java.lang.Class cannot be cast to org.gradle.api.reporting.ConfigurableReport at net.twisterrob.gradle.checkstyle.CheckStyleTask$TaskConfig$_setupReports_closure2$_closure3.doCall(CheckStyleTask.groovy:95) at net.twisterrob.gradle.checkstyle.CheckStyleTask$TaskConfig$_setupReports_closure2$_closure3.call(CheckStyleTask.groovy) at net.twisterrob.gradle.checkstyle.CheckStyleTask$TaskConfig$_setupReports_closure2.doCall(CheckStyleTask.groovy:94) at net.twisterrob.gradle.checkstyle.CheckStyleTask$TaskConfig$_setupReports_closure2.call(CheckStyleTask.groovy) at net.twisterrob.gradle.checkstyle.CheckStyleTask$TaskConfig.setupReports(CheckStyleTask.groovy:91) at net.twisterrob.gradle.checkstyle.CheckStyleTask$TaskConfig.execute(CheckStyleTask.groovy:42) at net.twisterrob.gradle.checkstyle.CheckStyleTask$TaskConfig.execute(CheckStyleTask.groovy) at org.gradle.api.internal.tasks.DefaultTaskContainer.create(DefaultTaskContainer.java:148)
Now, that's obviously not my error, because 1) it worked in the previous commit (when the class wasn't an inner class) and 2) I'm using ast(groovy.transform.CompileStatic) to build.
Another way: gradlew groovyCompile, and then observe the build directory:
static def setupReports(CheckStyleTask task) { task.reports.with { def reportsDir = task.project.extensions.findByType(ReportingExtension).baseDir xml.with { enabled = true setDestination(new File(reportsDir, 'checkstyle.xml'))
compiles to
public Object doCall(Object it) { boolean var2 = true; ((ConfigurableReport)CheckStyleTask.class).setEnabled(var2); Object var10001 = null; ((ConfigurableReport)((_closure4)this).getDelegate()).setDestination(new File((File)ScriptBytecodeAdapter.castToType(this.reportsDir.get(), File.class), "checkstyle.html")); Object var10000 = null;
Note: the first cast is wrong, the second one is using getDelegate properly.
Attachments
Issue Links
- duplicates
-
GROOVY-8873 Fails at runtime with @CompileStatic and two nested with
- Closed