java: V1Secret equals always returns false

Two V1Secret instances deserialized from the same YAML are not equal. In fact, V1Secret.equals(Object o) always returns false. This is because V1Secret.data = Map<String, byte[]>.

https://github.com/kubernetes-client/java/blob/f895344023e1a40900c60716560f3667c3bf90ce/kubernetes/src/main/java/io/kubernetes/client/models/V1Secret.java#L40

The equals method on a Java array type is equivalent to ==. So this line returns false.

https://github.com/kubernetes-client/java/blob/f895344023e1a40900c60716560f3667c3bf90ce/kubernetes/src/main/java/io/kubernetes/client/models/V1Secret.java#L189

Would you be open to patches for this? If so, what’s the right approach? Keep the V1Secret.data = Map<String, byte[]> and modify the line above to loop through the map checking keys are equal with Objects.equals() and byte[] values are equal with java.util.Arrays.equals(...)?

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Comments: 16 (11 by maintainers)

Most upvoted comments

am in favor of an upstream fix before we migrating to openapi-generator #595, and so do the other issues complaining about the template’d codes.

This is really very unfortunate. That code is generated, so we can’t manually patch it. We could override it with our own class (similar to IntToString or Quantity) if we really wanted to.

Alternately, we could update the SwaggerCodegen here:

https://github.com/swagger-api/swagger-codegen/blob/master/modules/swagger-codegen/src/main/resources/Java/pojo.mustache#L164

To be smarter…