Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

When converting from VARIANT to Java type the target type should be boxed #74

Open
tonyroberts opened this issue May 30, 2018 · 0 comments

Comments

@tonyroberts
Copy link

When a COM method returns a VARIANT and the Java return type is a primitive type, the conversion function Variant.convertTo falls back to converting based on the type of the variant, and not the Java type.

This is because all the Java types in the SetterEntry mapping are the boxed types, and the type that is tested against is the primitive type.

Falling back to the VTTYPE is usually fine as the variant should be the type expected. This is not always the case though, and so com4j should handle coercing the type into the expected type. For example, many Excel COM methods that are described in the typelib as returning VT_I4 (long) actually return VT_R8 (double). These methods cause a problem when called through com4j as variant gets converted to the type matching the variant which doesn't match the expected return type.

To fix this, when converting to the java return type the target type should be the boxed type.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant