[GRADLE-2566] Regression with file pattern matching: GStringImpl cannot be cast to String Created: 22/Nov/12  Updated: 17/Nov/14  Resolved: 03/Jan/13

Status: Resolved
Project: Gradle
Affects Version/s: 1.3
Fix Version/s: 1.4-rc-1

Type: Bug
Reporter: Szczepan Faber Assignee: Unassigned
Resolution: Fixed Votes: 0

Known Issue Of:


An example that demonstrates the problem:

//the include pattern is GString:
def tree = fileTree(dir: '.', includes: ["${'x'}"])
//force evaluation:

Above works with Gradle < 1.3. With Gradle 1.3 it yields:

Caused by: java.lang.ClassCastException: org.codehaus.groovy.runtime.GStringImpl cannot be cast to java.lang.String
	at org.gradle.api.tasks.util.PatternSet.getAsSpec(PatternSet.java:124)
	at org.gradle.api.internal.file.collections.DirectoryFileTree.visit(DirectoryFileTree.java:114)
	at org.gradle.api.internal.file.collections.FileTreeAdapter.visit(FileTreeAdapter.java:96)
	at org.gradle.api.internal.file.AbstractFileTree.isEmpty(AbstractFileTree.java:48)
	at org.gradle.api.internal.file.CompositeFileCollection.isEmpty(CompositeFileCollection.java:57)

Workaround - use toString()

def tree = fileTree(dir: '.', includes: ["${'x'}".toString()])

Comment by Luke Daley [ 22/Nov/12 ]

From this change: https://github.com/gradle/gradle/commit/037a2d54d5c0493003aa9dc483c712dfa0d83a7b

Comment by Szczepan Faber [ 22/Nov/12 ]

I'm wondering if it makes sense to add information about this bug in 'known issues' section in the release notes.

Comment by Luke Daley [ 22/Nov/12 ]

We don't really have a way to do that.

Comment by Adam Murdoch [ 06/Dec/12 ]

The known issues are all the issues with 'affects version' == the version the release notes are for. We could just dynamically include these issues in the release notes the same way that the fixed issues are.

Comment by Luke Daley [ 06/Dec/12 ]

That's what I was thinking.

We should add this for 1.4. We could also add it to the deployed 1.3 notes by hand

Comment by Denys Slipetskyy [ 04/Feb/14 ]

Just got the same error with Gradle 1.10
Provided workaround works for me.

I have some string property in gradle.properties file (in project's root)
Later I use it in build.gradle to configure flyway plugin, like:

placeholders = ['execUserName' : "${project.execUserName}"]

and it gives metioned exception.

placeholders = ['execUserName' : "${project.execUserName}".toString()]

works like expected.

Not sure if it is Flyway plugin specific error.

Comment by Luke Daley [ 04/Feb/14 ]

Denys Slipetskyy that will be a specific problem with the flyway plugin.

Comment by wolfgang häfelinger [ 17/Nov/14 ]

No, this problem is not related to Flyway.

Had quite similar problem using Gradle 1.12 using 'filter(ReplaceTokens, ..)' and the workaround given above - i.e. toString() - solved the problem.

Generated at Wed Jun 30 12:25:25 CDT 2021 using Jira 8.4.2#804003-sha1:d21414fc212e3af190e92c2d2ac41299b89402cf.