RPC Query response with empty element causes nullpointerexception

Issue #117 closed
Shahed Moolji created an issue

When I try and access the result of an XML RPC call and print the result, I get a null pointer exception.

I believe this may be due to empty elements being returned in the response.

Exception in thread "main" java.lang.NullPointerException at rocks.xmpp.extensions.rpc.model.Value.toString(Value.java:302) at java.lang.String.valueOf(String.java:2994) at java.lang.StringBuilder.append(StringBuilder.java:131) at rocks.xmpp.extensions.rpc.model.StructType.lambda$toString$4(StructType.java:56) at java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:193) at java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1374) at java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:481) at java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:471) at java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:708) at java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234) at java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:499) at rocks.xmpp.extensions.rpc.model.StructType.toString(StructType.java:56) at rocks.xmpp.extensions.rpc.model.Value.toString(Value.java:302) at java.lang.String.valueOf(String.java:2994) at java.lang.StringBuilder.append(StringBuilder.java:131) at com.xxx.Main$2.accept(Main.java:75) at com.xxx.Main$2.accept(Main.java:72) at java.util.concurrent.CompletableFuture.uniWhenComplete(CompletableFuture.java:760) at java.util.concurrent.CompletableFuture$UniWhenComplete.tryFire(CompletableFuture.java:736) at java.util.concurrent.CompletableFuture.postComplete(CompletableFuture.java:474) at java.util.concurrent.CompletableFuture.complete(CompletableFuture.java:1962) at rocks.xmpp.core.session.XmppSession.lambda$sendAndAwait$10(XmppSession.java:810) at rocks.xmpp.util.XmppUtils.lambda$notifyEventListeners$3(XmppUtils.java:188) at java.util.concurrent.CopyOnWriteArrayList.forEach(CopyOnWriteArrayList.java:890) at java.util.concurrent.CopyOnWriteArraySet.forEach(CopyOnWriteArraySet.java:404) at rocks.xmpp.util.XmppUtils.notifyEventListeners(XmppUtils.java:186) at rocks.xmpp.core.session.XmppSession.lambda$handleElement$21(XmppSession.java:1193) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) at java.lang.Thread.run(Thread.java:745)

<methodResponse><params><param><value><struct><member><name>username</name><value><string>xxx</string></value></member><member><name>branch_id</name><value><string>40277</string></value></member><member><name>first_name</name><value><string>xxx API</string></value></member><member><name>last_name</name><value><string>Test User</string></value></member><member><name>user_id</name><value><string>115524</string></value></member><member><name>xxx</name><value></value></member><member><name>reseller_id</name><value><string>43</string></value></member><member><name>role_id</name><value><string>1</string></value></member><member><name>organization_id</name><value><string>44316</string></value></member><member><name>call_center_agents</name><value><array><data><value><string>22873</string></value></data></array></value></member><member><name>extensions</name><value><array><data><value><string>496187</string></value><value><string>496528</string></value></data></array></value></member><member><name>primary_extension</name><value><string>496528</string></value></member><member><name>customer_id</name><value><string>45132</string></value></member><member><name>email</name><value><string>xxx@xxx</string></value></member></struct></value></param></params></methodResponse>

Comments (5)

  1. Shahed Moolji Account Deactivated reporter

    rocks.xmpp.extensions.rpc.model.Value.java

    This seems to work around the issue for me

    @Override public final String toString() {

        if(value == null) return "";
        return value.toString();
    }
    
  2. Log in to comment