D2Method ClassCastException

Options
paul_wms
edited April 15, 2021 in Documentum #1

I am trying to invoke the D2CoreMethod from a Java program using the D2Method class. When I call the D2Method.start() method, I get the following exception:

java.lang.ClassCastException: com.documentum.fc.client.DfSysObject___PROXY cannot be cast to com.emc.common.dctm.methods.IC6MethodReturn
	at com.emc.d2.api.methods.D2Method.start(D2Method.java:484)
	at com.emc.d2.api.methods.D2Method.start(D2Method.java:298)
	at com.emc.d2.api.methods.D2Method.start(D2Method.java:275)

This D2Method and D2CoreMethod classes are in the D2-API-20.2.0.jar file. Has anyone used this D2Method successfully in D2 v20.2? This is a new content server and D2 installation.

TIA!

Tagged:

Comments

  • Karen Weir
    Options

    Hi @paul_wms , I see that your post hasn't garnered any comments from the community. Have you been able to resolve this on your own, or is it still open for discussion?

  • I have not resolved that issue. Due to the lack of response, I quit that approach and am invoking the method asynchronously on the server using session.apply(null, "DO_METHOD",...) instead. I don't think the method can be invoked successfully using the D2-API-20.2.0.jar as it is now.

  • I'm calling D2CoreMethod from a job and it works fine, e.g :

    D2CoreMethod.execute(userName, session, job, sysobjList, false, false, true, true, false);


    You need to retrieve the job first like this

    job = (IDfSysObject) session.getObjectByQualification("dm_job where object_name = 'D2JobCore'");

             if (job == null) {

                throw new JobException("Failed to retrieve D2JobCore");

             }

             // seems to be required before calling D2CoreMethod to avoid class cast issues

             D2Session.initTBO(session);

  • The exaception thrown to indicate that your code has attempted to cast an object to a subclass of which it is not an instance. This means that ClassCastException occurs when you try to cast an instance of an Object to a type that it is not. Type Casting 5 only works when the casted object follows an is a relationship to the type you are trying to cast to.

    It is good practice to guard any explicit casts with an instanceof check first:

    if (myApple instanceof Fruit) {

     Fruit myFruit = (Fruit)myApple;

    }

    When will be ClassCastException is thrown:

    • When you try to cast an object of Parent class to its Child class type, this exception will be thrown.
    • When you try to cast an object of one class into another class type that has not extended the other class or they don’t have any relationship between them


  • Thanks for your comment, but as stated in the post, the exception occurs in the D2 API code. So, stating the obvious here is not responsive or productive.