[ 
https://issues.apache.org/jira/browse/CASSANDRA-21096?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18053757#comment-18053757
 ] 

rstest commented on CASSANDRA-21096:
------------------------------------

Send a simple fix for this!

> queryNames might cause NPE
> --------------------------
>
>                 Key: CASSANDRA-21096
>                 URL: https://issues.apache.org/jira/browse/CASSANDRA-21096
>             Project: Apache Cassandra
>          Issue Type: Bug
>          Components: Test/dtest/java
>            Reporter: rstest
>            Priority: Normal
>          Time Spent: 10m
>  Remaining Estimate: 0h
>
> The `MapMBeanWrapper.queryNames()` method in `TableMetricTest` returns `null` 
> instead of an empty `Set`, violating the `MBeanWrapper` interface contract. 
> This causes a `NullPointerException` when `GCInspector` is instantiated 
> during nodetool operations.
> {code:java}
> @Override
> public Set<ObjectName> queryNames(ObjectName name, QueryExp query)
> {
>     return null;
> } 
> {code}
> With this, we might meet NPE if queryNames() is called, for example, if we 
> restart a node and create a new GCInspector, then the GCInspector constructor 
> queries MBeans.
>  
> {code:java}
> // GCInspector.java:144-146
> ObjectName gcName = new 
> ObjectName(ManagementFactory.GARBAGE_COLLECTOR_MXBEAN_DOMAIN_TYPE + ",*");
>    for (ObjectName name : MBeanWrapper.instance.queryNames(gcName, null))  // 
> NPE HERE {code}
>  
> h2. StackTrace:
>  
> {code:java}
> java.lang.NullPointerException: Cannot invoke "java.util.Set.iterator()" 
> because the return value of 
> "org.apache.cassandra.utils.MBeanWrapper.queryNames(javax.management.ObjectName,
>  javax.management.QueryExp)" is null
>     at org.apache.cassandra.service.GCInspector.<init>(GCInspector.java:145)
>     at 
> org.apache.cassandra.distributed.mock.nodetool.InternalNodeProbe.connect(InternalNodeProbe.java:79)
>     at 
> org.apache.cassandra.distributed.mock.nodetool.InternalNodeProbe.<init>(InternalNodeProbe.java:58)
>     at 
> org.apache.cassandra.distributed.impl.Instance$DTestNodeTool.<init>(Instance.java:1079)
>     at 
> org.apache.cassandra.distributed.impl.Instance.lambda$nodetoolResult$51(Instance.java:986)
>  {code}
> A better way would be:
>  
> Change `MapMBeanWrapper.queryNames()` to return an empty set instead of null:
> {code:java}
> @Override
> public Set<ObjectName> queryNames(ObjectName name, QueryExp query)
> {
>     return Collections.emptySet();  // FIX: Return empty set, not null
> } {code}



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to