Details
-
Type:
Bug
-
Status:
Closed
-
Priority:
Major
-
Resolution: Fixed
-
Affects Version/s: 1.5.6
-
Fix Version/s: 1.6-rc-1, 1.5.8, 1.7-beta-1
-
Component/s: None
-
Labels:None
-
Environment:using groovy via gmaven-runtime-default 1.0-rc-3
-
Number of attachments :
Description
I have a constructor:
Foo( String foo, long bar, double... values )
in groovy, i am calling it with a String, a Long, and an Integer.
ParameterTypes.fitToVarArgs correctly determines that the array is a Double.
however, when MetaClassHelper.makeArray is called, it does:
Class baseClass = secondary; if (obj != null) { baseClass = obj.getClass(); }
which overrides the Double.class that is secondary, with Integer.class from the incoming value.
The constructor invocation then fails since the correct type was not passed.
Hi,
Attaching patches for the affected groovy versions and a test case.
The fix is basically to make coercing of double-type arguments consistent between DoubleCachedClass and ArrayCachedClass.
DoubleCachedClass allows all subclasses of java.lang.Number to be coerced into double type but ArrayCachedClass for varargs of double type allowed coercing only from float/double/BigDecimal types and not from other Number sub-classes and failed with "argument type mismatch" error.
rgds,
Roshan