Kubernetes-client: Always getting class sun.reflect.generics.reflectiveObjects.ParameterizedTypeImpl cannot be cast to class java.lang.Class

Created on 10 Dec 2020  路  6Comments  路  Source: fabric8io/kubernetes-client

Always getting this exception with such code

Binding binding = new BindingBuilder()
                    .withNewMetadata().withName(pod.getMetadata().getName()).endMetadata()
                    .withNewTarget().withKind("Node").withApiVersion("v1").withName(node.getMetadata().getName()).endTarget()
                    .build();

kubernetesClient.bindings().inNamespace(pod.getMetadata().getNamespace()).create(binding);

java.lang.ClassCastException: class sun.reflect.generics.reflectiveObjects.ParameterizedTypeImpl cannot be cast to class java.lang.Class (sun.reflect.generics.reflectiveObjects.ParameterizedTypeImpl and java.lang.Class are in module java.base of loader 'bootstrap')
    at io.fabric8.kubernetes.client.dsl.internal.core.v1.BindingOperationsImpl.<init>(BindingOperationsImpl.java:42) ~[kubernetes-client-4.10.3.jar:na]
    at io.fabric8.kubernetes.client.dsl.internal.core.v1.BindingOperationsImpl.<init>(BindingOperationsImpl.java:34) ~[kubernetes-client-4.10.3.jar:na]
    at io.fabric8.kubernetes.client.dsl.internal.core.v1.BindingOperationsImpl.<init>(BindingOperationsImpl.java:30) ~[kubernetes-client-4.10.3.jar:na]
    at io.fabric8.kubernetes.client.DefaultKubernetesClient.bindings(DefaultKubernetesClient.java:198) ~[kubernetes-client-4.10.3.jar:na]
bug

Most helpful comment

Hi, I'm creating a fix + adding a unit test + IT which will prevent this from happening again.

All 6 comments

Thanks a lot for reporting this! This error seems to be coming from this line:
https://github.com/fabric8io/kubernetes-client/blob/8e3f4be591e725384a422186da71764853f49389/kubernetes-client/src/main/java/io/fabric8/kubernetes/client/dsl/internal/core/v1/BindingOperationsImpl.java#L43

When I added support for Binding in https://github.com/fabric8io/kubernetes-client/pull/1819 . It looked like this:

  public BindingOperationsImpl(OperationContext context) {
    super(context
      .withApiGroupVersion("v1")
      .withPlural("bindings"));
    this.type = Binding.class;
    this.listType = KubernetesResourceList.class;
    this.doneableType = DoneableBinding.class;
  }

I'm not 100% sure since I haven't tried it myself but reverting to the old state should fix this issue.

Version 4.9.2 works for me, any newer version start failing with such exception.
Do you have any work around for this exception ? Because i also want to use undo() which is absent in this version

@jarorosFork: Unfortunately, I can't think of any workaround for this since it's the Operation class initialization that's failing :-( . I tried using generic resource API but since Binding hasn't get any dedicated List type, it fails this error:

// Fails with 'No handler found for object:Binding'
kubernetesClient.resource(binding).inNamespace("default").createOrReplace();

Would it be possible for you to submit a PR to fix this if you have some time?

what's undo()? Is this some new operation supported by Binding? I would suggest creating another issue for this new feature.

undo is
kubernetesClient.apps().deployments() .inNamespace(deployment.getMetadata().getNamespace()) .withName(deployment.getMetadata().getName()) .rolling().undo();
No starting from 4.10.0 client has undo method but starting from 4.10 i'm getting this exception
Thanks, will submit PR

Hi, I'm creating a fix + adding a unit test + IT which will prevent this from happening again.

Relates to:

  • #1816
  • #1819
  • #2278
Was this page helpful?
0 / 5 - 0 ratings

Related issues

jeffmaury picture jeffmaury  路  5Comments

Fabian-K picture Fabian-K  路  4Comments

zregvart picture zregvart  路  4Comments

if6was9 picture if6was9  路  5Comments

cld378632668 picture cld378632668  路  3Comments