This is an automated email from the ASF dual-hosted git repository.

rxl pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/pulsar-client-go.git


The following commit(s) were added to refs/heads/master by this push:
     new d9d535c  Fix nil pointer dereference in PartitionMetadataResponse 
(#182)
d9d535c is described below

commit d9d535caef16c690e3b272e359cce1b2bdeda02a
Author: 冉小龙 <[email protected]>
AuthorDate: Fri Feb 7 18:27:36 2020 +0800

    Fix nil pointer dereference in PartitionMetadataResponse (#182)
    
    Signed-off-by: xiaolong.ran <[email protected]>
    
    Fix nil pointer dereference of PartitionMetadataResponse
---
 pulsar/client_impl.go | 19 +++++++++++--------
 1 file changed, 11 insertions(+), 8 deletions(-)

diff --git a/pulsar/client_impl.go b/pulsar/client_impl.go
index ba5fac9..6dfda15 100644
--- a/pulsar/client_impl.go
+++ b/pulsar/client_impl.go
@@ -143,17 +143,20 @@ func (c *client) TopicPartitions(topic string) ([]string, 
error) {
        }
 
        r := res.Response.PartitionMetadataResponse
-       if r.Error != nil {
-               return nil, newError(ResultLookupError, r.GetError().String())
-       }
+       if r != nil {
+               if r.Error != nil {
+                       return nil, newError(ResultLookupError, 
r.GetError().String())
+               }
 
-       if r.GetPartitions() > 0 {
-               partitions := make([]string, r.GetPartitions())
-               for i := 0; i < int(r.GetPartitions()); i++ {
-                       partitions[i] = fmt.Sprintf("%s-partition-%d", topic, i)
+               if r.GetPartitions() > 0 {
+                       partitions := make([]string, r.GetPartitions())
+                       for i := 0; i < int(r.GetPartitions()); i++ {
+                               partitions[i] = fmt.Sprintf("%s-partition-%d", 
topic, i)
+                       }
+                       return partitions, nil
                }
-               return partitions, nil
        }
+
        // Non-partitioned topic
        return []string{topicName.Name}, nil
 }

Reply via email to