You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by "Robert Papp (JIRA)" <ji...@apache.org> on 2018/01/08 01:17:00 UTC
[jira] [Created] (GROOVY-8434) ClassCastException: Class cannot be
cast to type-of-with's-delegate
Robert Papp created GROOVY-8434:
-----------------------------------
Summary: ClassCastException: Class cannot be cast to type-of-with's-delegate
Key: GROOVY-8434
URL: https://issues.apache.org/jira/browse/GROOVY-8434
Project: Groovy
Issue Type: Bug
Components: Compiler
Affects Versions: 2.4.12
Environment: Windows 10, Gradle 4.2.1
Reporter: Robert Papp
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:
{code}
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)
{code}
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:
{code}
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'))
{code}
compiles to
{code}
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;
{code}
Note: the first cast is wrong, the second one is using getDelegate properly.
--
This message was sent by Atlassian JIRA
(v6.4.14#64029)