Golang/neoism: calling methods of objects returned by query leads to panic

rob74 :

When trying to call a method of a Node object returned by a call to neoism.CypherQuery, I keep getting "invalid memory address or nil pointer dereference" panics. The query returns something (accessing the Data property of the Node works), but calling any method leads to a panic. The methods have the receiver *Node, not Node, but AFAIK that should work nevertheless? Anyway, I have already tried getting a pointer to the object and calling the method on that, but that didn't work either. I'm really stuck here...

Example code to reproduce the problem (needs neoism and go-uuid packages and a Neo4J DB running on localhost):

package main

import (
    "code.google.com/p/go-uuid/uuid"
    "fmt"
    "github.com/jmcvetta/neoism"
)

func main() {
    neo, _ := neoism.Connect("http://localhost:7474/db/data")

    // create a node with a random id
    nodeId := uuid.New()
    _, err := neo.CreateNode(neoism.Props{"NodeId": nodeId})
    if err != nil {
        fmt.Println(err)
        return
    }
    fmt.Println("node created, id", nodeId)

    // find the node by the id
    res := []struct {
        Node neoism.Node `json:"nodes"`
    }{}
    err = neo.Cypher(&neoism.CypherQuery{
        Statement:  `MATCH (nodes {NodeId:{NodeId}}) RETURN nodes`,
        Parameters: neoism.Props{"NodeId": nodeId},
        Result:     &res,
    })
    if err != nil {
        fmt.Println(err)
        return
    }
    fmt.Println("query executed")

    // try to work with the query results
    if len(res) > 0 {
        // get Data -> works
        fmt.Println(res[0].Node.Data)
        // call method -> panics
        err = res[0].Node.SetProperty("TestProp", "TestValue")
        if err != nil {
            fmt.Println(err)
            return
        }
    }
}

Here's the relevant part of the stack trace:

goroutine 1 [running]:
github.com/jmcvetta/neoism.(*entity).SetProperty(0x119abc00, 0x5d3a68, 0x8, 0x5d3a88, 0x9, ...)
        .../src/github.com/jmcvetta/neoism/entity.go:26 +0x104
main.main()
        .../src/nieware/neoprob/neoprob.go:41 +0x4cb
Jeremy Wall :

Looking at the source for the SetProperty method: https://github.com/jmcvetta/neoism/blob/master/entity.go#L22

It looks like it comes from an embedded struct and is not actually a method on the Node struct. The embedded entity struct is not a pointer however so it also should not be null.

The stack trace shows that the panic occurs at line 26, because e.Db is not initialized:

resp, err := e.Db.Session.Put(url, &value, nil, &ne)

setting e.Db before calling SetProperty solves the problem:

res[0].Node.Db = neo

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Calling methods on objects in an arraylist

From Dev

Calling methods on objects Java

From Dev

Javascript registry for calling methods and objects

From Dev

Using objects/calling methods inside event response

From Dev

calling objects from other methods in java

From Dev

Using variables for creating objects and calling methods in Java

From Dev

Handling null objects when calling methods

From Dev

Calling main methods in other objects in Scala

From Dev

Processing - draw() is run after the calling methods have already returned

From Java

Are JPA's Query objects returned by an EntityManager reusable?

From Dev

How to limit number of returned objects in group query

From Dev

Iterating over DOM Objects being returned by Java methods in XSLT

From Dev

How to execute async methods for each document returned in a mongoose query

From Dev

How to define classes using 2 different objects calling the same methods

From Java

Calling many methods of many objects many times per second

From Java

Issues calling methods on web context objects in thymeleaf template

From Dev

How to add objects to an array by using their class name, then calling any of their methods?

From Dev

calling generic methods with custom objects from list (automate)

From Dev

How could I sort the array of entity objects returned by this doctrine query?

From Dev

Calling query builder methods from an eloquent model instance

From Dev

Checking whether the returned dict key leads to a list

From Dev

What is returned by calling 'where'?

From Dev

Calling a returned function

From Java

Better to query once, then organize objects based on returned column value, or query twice with different conditions?

From Dev

Query using MockContentResolver leads to NullPointerException

From Java

Java generics + static factory methods = [panic]

From Dev

Comparing object methods leads to different results in 3.8

From Dev

How can I make order irrelevant when calling fluent methods of inherited objects?

From Java

How to fix NullPointerException error when calling methods from page objects in selenium testcases using TestNG?

Related Related

  1. 1

    Calling methods on objects in an arraylist

  2. 2

    Calling methods on objects Java

  3. 3

    Javascript registry for calling methods and objects

  4. 4

    Using objects/calling methods inside event response

  5. 5

    calling objects from other methods in java

  6. 6

    Using variables for creating objects and calling methods in Java

  7. 7

    Handling null objects when calling methods

  8. 8

    Calling main methods in other objects in Scala

  9. 9

    Processing - draw() is run after the calling methods have already returned

  10. 10

    Are JPA's Query objects returned by an EntityManager reusable?

  11. 11

    How to limit number of returned objects in group query

  12. 12

    Iterating over DOM Objects being returned by Java methods in XSLT

  13. 13

    How to execute async methods for each document returned in a mongoose query

  14. 14

    How to define classes using 2 different objects calling the same methods

  15. 15

    Calling many methods of many objects many times per second

  16. 16

    Issues calling methods on web context objects in thymeleaf template

  17. 17

    How to add objects to an array by using their class name, then calling any of their methods?

  18. 18

    calling generic methods with custom objects from list (automate)

  19. 19

    How could I sort the array of entity objects returned by this doctrine query?

  20. 20

    Calling query builder methods from an eloquent model instance

  21. 21

    Checking whether the returned dict key leads to a list

  22. 22

    What is returned by calling 'where'?

  23. 23

    Calling a returned function

  24. 24

    Better to query once, then organize objects based on returned column value, or query twice with different conditions?

  25. 25

    Query using MockContentResolver leads to NullPointerException

  26. 26

    Java generics + static factory methods = [panic]

  27. 27

    Comparing object methods leads to different results in 3.8

  28. 28

    How can I make order irrelevant when calling fluent methods of inherited objects?

  29. 29

    How to fix NullPointerException error when calling methods from page objects in selenium testcases using TestNG?

HotTag

Archive