Details
-
Bug
-
Status: Closed
-
Critical
-
Resolution: Duplicate
-
3.0.10, 3.0.11
-
None
-
None
Description
Hi team!
I have 2 classes:
- Invoice extends AbstractInvoice
- Quote extends AbstractInvoice
And I try to run
AbstractInvoice abstractInvoice = new Invoice() if (abstractInvoice.newRecord || abstractInvoice instanceof Quote) { abstractInvoice.setContact(new Contact()) }
I get "Exception in thread "main" org.codehaus.groovy.runtime.typehandling.GroovyCastException: Cannot cast object 'groov.Invoice@3f2a3a5' with class 'groov.Invoice' to class 'groov.Quote'"
I investigated build files and I saw this:
Invoice abstractInvoice = new Invoice(); Object var10000; if (((Invoice)abstractInvoice).isNewRecord() || abstractInvoice instanceof Quote) { ((Quote)ScriptBytecodeAdapter.castToType(abstractInvoice, Quote.class)).setContact(new Contact()); var10000 = null; }
Groovy sees 'abstractInvoice instanceof Quote' and tries to cast Class to Quote. But It forgets about || condition.
In our project we use 2.5.15 version and we upgrading it to 4.0.2 version. After investigation I found that this behavior appeared in 3.0.11 version. 3.0.10 and older work correct.
If I use Main Java class it works correct as well.
I localized issue here (minimum classes and dependancies): ErrorWithCast.zip
Part from our project(more inheritance): [^TestJavaGroovyGradleProject 2.zip][^TestJavaGroovyGradleProject.zip]
Attachments
Attachments
Issue Links
- is related to
-
GROOVY-7971 @CS flow typing incorrectly casting to map at runtime
- In Progress