jclouds/jclouds — pull request #374 by aledsage (2014-05-17 21:06:14+00:00)
Title: JCLOUDS-549: Fix NPE in LoginCredentials.toString

Was seeing NPE if LoginCredentials was constructed with a null password or null privateKey (rather than Optional.Absent).

See https://github.com/jclouds/jclouds/pull/353 for fix to 1.7.x branch, which fixed it by guarding against null in the toString.

Instead, here the fix is in LoginCredential's constructor, to never have null `Optional password` field. This is based on discussion with @demobox in https://github.com/jclouds/jclouds/pull/353.

Note this risks consequences for usages. The only non-test I can see though is `RunScriptOptions.hasLoginPasswordOption()`, which returns false if `LoginCredential.password` is null and true otherwise. That is then used by `BaseComputeService.updateNodeCredentialsIfPresent(NodeMetadata node, RunScriptOptions options)`. However, it looks to me like `updateNodeCredentialsIfPresent` will always set the LoginCredential on the given NodeMetadata (even if not present) so we should get the same behaviour.

This change risks not being backwards compatible if downstream projects have "unusual" uses of LoginCredential, relying on the `@Nullable` on `getOptionalPassword()` having special meaning for null, which now will never be returned. I presume we can live with that.

Note this fix meant I also needed to change AWSEC2ImageParserTest. I don't think that's important as it's only producing json of the parsed result as a convenience for a deep-equals; others won't be producing json from this presumably so we can rely on the call hierarchy shown by the IDE.