Details
-
Bug
-
Status: Closed
-
Major
-
Resolution: Fixed
-
1.5.6
-
None
-
Windows XP SP2, Sun JDK 1.5.0_15-b04
Description
Running the example described here in the Groovy User Guide results in a ClassCastException.
Here is the testcase:
class XmlExampleTest extends GroovyTestCase {
void testThatChangingValueOfXmlWorks() {
def input = '''
<shopping>
<category type="groceries">
<item>Chocolate</item>
<item>Coffee</item>
</category>
<category type="supplies">
<item>Paper</item>
<item quantity="4">Pens</item>
</category>
<category type="present">
<item when="Aug 10">Kathryn's Birthday</item>
</category>
</shopping>
'''
def root = new XmlParser().parseText(input)
def groceries = root.category.findAll
{ it.@type == 'groceries' }.item
groceries.each
}
}
This results in a ClassCastExcpetion:
1) testThatChangingValueOfXmlWorks(com.xebia.proxy.maven.XmlExampleTest)java.lang.ClassCastException:
java.lang.String
at org.codehaus.groovy.reflection.CachedClass$IntegerCachedClass.coerceArgument(CachedClass.java:459)
at org.codehaus.groovy.reflection.ParameterTypes.coerceArgumentsToClasses(ParameterTypes.java:138)
at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:228)
at groovy.lang.MetaClassImpl.setProperty(MetaClassImpl.java:2007)
at groovy.lang.MetaClassImpl.setProperty(MetaClassImpl.java:2591)
at groovy.lang.DelegatingMetaClass.setProperty(DelegatingMetaClass.java:161)
at org.codehaus.groovy.runtime.InvokerHelper.setProperty(InvokerHelper.java:199)
at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.setProperty(ScriptBytecodeAdapter.java:506)
at com.xebia.proxy.maven.XmlExampleTest$_testThatChangingValueOfXmlWorks_closure2.doCall(XmlExampleTest.groovy:25)
..... (Rest of stacktrace omitted for readability)
Changing the values of attributes in XML does work however.