Uncaught java.io.NotSerializableException: antlr.CommonToken in Function Execution
search cancel

Uncaught java.io.NotSerializableException: antlr.CommonToken in Function Execution

book

Article ID: 294336

calendar_today

Updated On:

Products

VMware Tanzu Gemfire

Issue/Introduction

The following severe serialization exceptions are seen in the Cache Server logs.
[severe xxxx/xx/xx xx:xx:xx.xxx xxx xxxxx tid=0xyyyy] Uncaught exception processing partitioned.PartitionedRegionFunctionStreamingMessage(prid=x (name = "XXX") processorId=YYY ,distTx=false) org.apache.geode.InternalGemFireException: java.io.NotSerializableException: antlr.CommonToken at org.apache.geode.distributed.internal.ClusterDistributionManager.putOutgoing(ClusterDistributionManager.java:1724) at org.apache.geode.distributed.internal.ReplyMessage.send(ReplyMessage.java:111) at org.apache.geode.internal.cache.partitioned.PartitionMessage.sendReply(PartitionMessage.java:436) at org.apache.geode.internal.cache.partitioned.PartitionMessage.process(PartitionMessage.java:416) at org.apache.geode.distributed.internal.DistributionMessage.scheduleAction(DistributionMessage.java:378) at org.apache.geode.distributed.internal.DistributionMessage$1.run(DistributionMessage.java:444) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) at org.apache.geode.distributed.internal.ClusterDistributionManager.runUntilShutdown(ClusterDistributionManager.java:1121) at org.apache.geode.distributed.internal.ClusterDistributionManager.access$000(ClusterDistributionManager.java:109) at org.apache.geode.distributed.internal.ClusterDistributionManager$9$1.run(ClusterDistributionManager.java:990) at java.lang.Thread.run(Thread.java:745) Caused by: java.io.NotSerializableException: antlr.CommonToken


Note: This occurs in a PartitionedRegionFunctionStreamingMessage and therefore, we know that it is happening within a GemFire function. 


Environment

Product Version: 9.5

Resolution

In this case, the issue is the function execution called newQuery method without catching QueryInvalidException.

The newQuery method may throw a QueryInvalidException that needs to be handled carefully. This is because it may contain non-serializable elements such as 'antlr.CommonToken', which is used internally in the query parser.

For an example of the correct handling, you can do something similar to the following:
try {
    ...
    Query query = queryService.newQuery(queryString);
    SelectResults<?> results = (SelectResults<?>) query.execute(...);
    ...
    
} catch (QueryException qex) {
    ...
} catch (QueryInvalidException qiex} 
  // Log the exception and the necessary details.
}

Reference

  • https://gemfire-910-javadocs.docs.pivotal.io/org/apache/geode/cache/query/QueryService.html#newQuery-java.lang.String-