2

Running code like the following throws exception:

query = "SELECT Coverage FROM ApexCodeCoverageAggregate WHERE ApexClassOrTriggerId ='" + id + "'";
QueryResult q = project.getToolingConnection().query(query);

And the exception:

    SEVERE [org.openide.util.Exceptions]
java.lang.ClassCastException: [I cannot be cast to [Ljava.lang.Object;
    at com.sforce.ws.bind.TypeMapper.readArray(TypeMapper.java:578)
    at com.sforce.ws.bind.TypeMapper.readObject(TypeMapper.java:531)
    at com.sforce.soap.tooling.Coverage.loadFields(Coverage.java:83)
    at com.sforce.soap.tooling.Coverage.load(Coverage.java:75)
    at com.sforce.ws.bind.TypeMapper.readSingle(TypeMapper.java:653)
    at com.sforce.ws.bind.TypeMapper.readObject(TypeMapper.java:529)
    at com.sforce.soap.tooling.ApexCodeCoverageAggregate.loadFields(ApexCodeCoverageAggregate.java:346)
    at com.sforce.soap.tooling.ApexCodeCoverageAggregate.load(ApexCodeCoverageAggregate.java:329)
    at com.sforce.ws.bind.TypeMapper.readSingle(TypeMapper.java:653)
    at com.sforce.ws.bind.TypeMapper.readArray(TypeMapper.java:553)
    at com.sforce.ws.bind.TypeMapper.readObject(TypeMapper.java:531)
    at com.sforce.soap.tooling.QueryResult.loadFields(QueryResult.java:208)
    at com.sforce.soap.tooling.QueryResult.load(QueryResult.java:184)
    at com.sforce.ws.bind.TypeMapper.readSingle(TypeMapper.java:653)
    at com.sforce.ws.bind.TypeMapper.readObject(TypeMapper.java:529)
    at com.sforce.soap.tooling.QueryAllResponse_element.loadFields(QueryAllResponse_element.java:62)
    at com.sforce.soap.tooling.QueryAllResponse_element.load(QueryAllResponse_element.java:54)
    at com.sforce.ws.bind.TypeMapper.readSingle(TypeMapper.java:653)
    at com.sforce.ws.bind.TypeMapper.readObject(TypeMapper.java:529)
    at com.sforce.ws.transport.SoapConnection.bind(SoapConnection.java:178)
    at com.sforce.ws.transport.SoapConnection.receive(SoapConnection.java:152)
    at com.sforce.ws.transport.SoapConnection.send(SoapConnection.java:99)
    at com.sforce.soap.tooling.ToolingConnection.query(ToolingConnection.java:282)

Any chance I can do it?

P.S. Code like this runs fine:

String query = "Select Id from ApexClass Where Name='MyController'";
QueryResult qr = project.getToolingConnection().query(query);

2 Answers 2

1

Ok, having a look to the TypeMapper class of WSC, I found that there is an obvious error when a generated from wsdl tooling API method tries to cast Object which is actually an Object[] to int[]. So I changed these lines in TypeMapper.readArray():

Object array = Array.newInstance(component, results.size());
Object arrayResult = results.toArray((Object[]) array);

To:

Object arrayResult;
if(component == int.class) {
    int[] inn = new int[results.size()];
    for(int i = 0; i<results.size(); i++){
        inn[i] = ((Integer)results.get(i)).intValue();
    }
    arrayResult = (Object) inn;
} else {
    Object array = Array.newInstance(component, results.size());
    arrayResult = results.toArray((Object[]) array);
}

And it solved the issue. If this will not cause any issues later I will commit it to WSC repo.

0

I am going to guess that you are using WSC for your SOAP calls?

wsc (at least in v34) has a bug and can not deserialise Coverage field value. Not sure if this has been fixed in v35, but as a workaround you may want to consider using Tooling REST API for querying Coverage from ApexCodeCoverageAggregate.

2
  • I indeed was using Tooling api of version 34, but I compiled to version 35 and it still has the bug. How can I get it fixed? Would using REST require me to create a connected app? Commented Sep 20, 2015 at 10:05
  • Please check my answer to this question. Modified the WSC sources to make it work. Commented Sep 20, 2015 at 13:04

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .