Details
-
Type:
Bug
-
Status:
Closed
-
Priority:
Major
-
Resolution: Won't Fix
-
Affects Version/s: 1.5
-
Fix Version/s: 1.6-rc-2
-
Component/s: None
-
Labels:None
-
Environment:Groovy Version: 1.5.0 JVM: 1.6.0_01-b06
os.name=Windows XP
os.version=5.1
-
Testcase included:yes
-
Number of attachments :
Description
Try this part from Groovy in Action(Listing_7_23_GPath.groovy):
class Invoice { //|#1
List items //|#1
Date date //|#1
} //|#1
class LineItem { //|#1
Product product //|#1
int count //|#1
int total() { //|#1
return product.dollar * count //|#1
} //|#1
} //|#1
class Product { //|#1
String name //|#1
def dollar //|#1
} //|#1
def ulcDate = new Date(107,0,1)
def ulc = new Product(dollar:1499, name:'ULC') //|#2
def ve = new Product(dollar:499, name:'Visual Editor') //|#2
//|#2
def invoices = [ //|#2
new Invoice(date:ulcDate, items: [ //|#2
new LineItem(count:5, product:ulc), //|#2
new LineItem(count:1, product:ve) //|#2
]), //|#2
new Invoice(date:[107,1,2], items: [ //|#2
new LineItem(count:4, product:ve) //|#2
]) //|#2
] //|#2
assert [5*1499, 499, 4*499] == invoices.items*.total() //#3
Fails at last line //#3 with:
Caught: groovy.lang.MissingMethodException: No signature of method: java.util.ArrayList.total() is applicable for argument types: () values: {}
at Listing_7_23_GPath.run(Listing_7_23_GPath.groovy:31)
at Listing_7_23_GPath.main(Listing_7_23_GPath.groovy)
Hint
If I restore the org.codehaus.groovy.runtime.DefaultGroovyMethods.getAt(Collection coll, String property) from groovy 1.0 code regarding answer like this:
// groovy 1.0 if (value instanceof Collection) { answer.addAll((Collection) value); } else { answer.add(value); }
istead of
// groovy 1.5.0
answer.add(value)
then the Listing_7_23_GPath.groovy works fine
With the current 1.5.0 behavior, the last line becomes:
assert [5 * 1499, 499, 4 * 499] == invoices.items.collect{ it*.total() }.flatten()assert [5 * 1499, 499, 4 * 499] == invoices.items.collect{ it*.total() }.flatten()