kubernetes-client: Type inference broken in 6.9.0
Description
(From internal conversation with @iocanel and @metacosm)
PR #5138, in scope of #5135, provided changes to make Resources Editable
.
While this improvement allows for one line edit operations similar to what Lombok’s toBuilder
does, it has somehow broken type inference in some scenarios.
One such scenario is where you have elements that are parameterized as such: A<R extends HasMetadata, P>
. If you have several such objects which all have the same value for P
but different values for R
and you want to process them as a list.
Before 6.9.0, the list was correctly inferred to be a list containing elements of type A<? extends HasMetadata, P>
.
With 6.9.0, the list is now inferred to contain elements of type A<? extends Editable<? extends BaseFluent<? extends BaseFluent<?>>>, P>
.
With type erasure, this results in hard-to-diagnose errors because they occur outside of the user’s code, similar to:
accept(java.util.List<java.util.Map.Entry<java.lang.String,java.lang.Object>>,java.lang.String,io.fabric8.kubernetes.api.builder.Visitor...) in io.fabric8.kubernetes.api.builder.BaseFluent cannot implement accept(java.util.List<java.util.Map.Entry<java.lang.String,java.lang.Object>>,java.lang.String,io.fabric8.kubernetes.api.builder.Visitor...) in io.fabric8.kubernetes.api.builder.Visitable
[ERROR] return type capture#1 of ? is not compatible with capture#2 of ?
You can see such an error here: https://github.com/operator-framework/java-operator-sdk/actions/runs/6456675029/job/17526638395#step:5:2605 If you look at the code, you’ll see that none of the classes or method mentioned in the error are used, which makes for a very unpleasant diagnosing experience.
About this issue
- Original URL
- State: closed
- Created 9 months ago
- Comments: 16 (10 by maintainers)
Commits related to this issue
- simplifications to the typing of basefluent fixes fabric8io/kubernetes-client#5522 — committed to shawkins/sundrio by shawkins 8 months ago
- simplifications to the typing of basefluent fixes fabric8io/kubernetes-client#5522 — committed to sundrio/sundrio by shawkins 8 months ago
Similar problem is still ongoing in 6.9.3 (Sundrio 0.101.3)
Quarkus build reports:
Triggered at:
https://github.com/dekorateio/dekorate/blob/5a9d246bdd0ecbcbfabbbbc3070f757605366a21/core/src/main/java/io/dekorate/ResourceRegistry.java#L181
I wasn’t trying to be overly narrow, just using the class where the resolve method is introduced. I understand that it should work without the typing.
I expanded the test to inline definitions of an AltConfigMap and AltDeployment along with dummy builders. Based upon that the next observations are:
Further inlining all of the builder package with the test shows:
So I think there’s a viable workaround by removing the Editable interface from the resources (but the edit / toBuilder methods can stay) - however there just seems to be something pretty funky about the sundrio typing that is confusing the compiler. I’ll poke around a little more and see if there are any changes that could be made to BaseFluent to resolve this.