I don't understand why I am getting the following error. Any thoughts?
I am getting error:
Cannot cast object 'true' with class 'java.lang.Boolean' to class 'java.io.File'
This is the code producing the error at line 'if (envProp.exists()...':
static private File envProp = new File('env.properties')
static private File envPropBak = new File('env.properties.bak')
@BeforeClass
static void beforeAll() {
if (envProp.exists()) {
envPropBak.write( envProp.text )
}
}
I don't understand why envProp.exists()
is trying to cast anything as another object. Method .exists()
should just return a boolean
.
Thanks
I had the same problem today, but in my case was:
org.codehaus.groovy.runtime.typehandling.GroovyCastException: Cannot cast object 'true' with class 'java.lang.Boolean' to class 'java.util.List'
The thing is that if your have something like this:
public List<Foo> method(){
methodThatReturnsTrue()
}
Because Groovy uses the last sentence's return as the method's return value, it tries to cast true to <some_not_boolean_type>
and so the error you and I are getting.
For the sake of completeness I need to say that I got a similar message:
Cannot cast object 'true' with class 'java.lang.Boolean' to class 'java.util.List'
When I invoked:
final List<String> reportedChangedFiles = linesOfChangedFiles.removeAll([null])
I was expecting removeAll() to return a new collection but I forgot that it modifies the current collection and returns a boolean instead. So it was as easy as:
linesOfChangedFiles.removeAll([null])
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With