Repository: kythe/kythe

Issue #4128: crossreferences for beam-pipelined tables panic with null SourceNode
Created: 2019-10-03T20:57:53Z
After using write_tables on some random entries, then using the kythe tools xref command, the server throws a null panic. It seems cr.SourceNode below is null (there's a check above in some case to see if it is non-null).
The hack below makes the error go away and references to appear, however I have no idea what am I doing.
diff --git a/kythe/go/serving/xrefs/xrefs.go b/kythe/go/serving/xrefs/xrefs.go
index 5b656651..aa8fe18f 100644
--- a/kythe/go/serving/xrefs/xrefs.go
+++ b/kythe/go/serving/xrefs/xrefs.go
@@ -550,9 +550,13 @@ func (t *Table) CrossReferences(ctx context.Context, req *xpb.CrossReferencesReq
                }
 
                // Read the set of indirection edge kinds for the given node kind.
-               nodeKind := nodeKind(cr.SourceNode)
-               indirections := experimentalCrossReferenceIndirectionKinds[nodeKind].
-                       Union(experimentalCrossReferenceIndirectionKinds["*"])
+
+               var indirections stringset.Set
+               if cr.SourceNode != nil {
+                       nodeKind := nodeKind(cr.SourceNode)
+                       indirections = experimentalCrossReferenceIndirectionKinds[nodeKind].
+                               Union(experimentalCrossReferenceIndirectionKinds["*"])
+               }
 
                for _, grp := range cr.Group {

/cc @schroederc for related recent changes.

Duplicate issue #4248: kythe xrefs crash with -api tables
Created: 2019-12-10T00:24:42Z
kythe nodes works with either the tables or the server.
`kythe xrerfs works with the server but crashes with the tables.
The following traceback is with the latest pull (2019-12-09 16:20 Pacific Time).
$ ../kythe/bazel-bin/kythe/go/serving/tools/kythe/kythe -api /tmp/pykythe_test/tables xrefs 'kythe://test-corpus?lang=python?root=test-root#.tmp.pykythe_test.SUBST.home.peter.src.pykythe.pykythe.pod.PlainOldData'
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x18 pc=0x85e446]

goroutine 1 [running]:
kythe.io/kythe/go/serving/xrefs.nodeKind(0x0, 0xc00009e380, 0x76)
	kythe/go/serving/xrefs/xrefs.go:735 +0x26
kythe.io/kythe/go/serving/xrefs.(*Table).CrossReferences(0xc00005b040, 0xa77ce0, 0xc000026140, 0xc000106000, 0x0, 0x0, 0x0)
	kythe/go/serving/xrefs/xrefs.go:556 +0x58e
kythe.io/kythe/go/serving/api.apiCloser.CrossReferences(...)
	kythe/go/serving/api/api.go:158
kythe.io/kythe/go/services/cli.xrefsCommand.Run(0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x9c3bfe, 0x7, 0x9c1205, ...)
	kythe/go/services/cli/commands_xrefs.go:130 +0x294
kythe.io/kythe/go/services/cli.(*commandWrapper).Execute(0xc00005b190, 0xa77ce0, 0xc000026140, 0xc0000707e0, 0xc00005b1a0, 0x1, 0x1, 0x7f0f3790b008)
	kythe/go/services/cli/cli.go:107 +0x149
github.com/google/subcommands.(*Commander).Execute(0xc0000e4d20, 0xa77ce0, 0xc000026140, 0xc00005b1a0, 0x1, 0x1, 0x1)
	external/com_github_google_subcommands/subcommands.go:142 +0x2f9
github.com/google/subcommands.Execute(...)
	external/com_github_google_subcommands/subcommands.go:420
kythe.io/kythe/go/services/cli.Execute(0xa77ce0, 0xc000026140, 0x7f0f378cf0c0, 0xc000020690, 0x7f0f378cf0f0, 0xc000020690, 0x7f0f378cf118, 0xc000020690, 0x7f0f378cf140, 0xc000020690, ...)
	kythe/go/services/cli/cli.go:84 +0x70d
main.main()
	kythe/go/serving/tools/kythe/kythe.go:60 +0x246

However, this works when accessing the server:
$ ../kythe/bazel-bin/kythe/go/serving/tools/kythe/kythe -api http://localhost:8080 xrefs 'kythe://test-corpus?lang=python?root=test-root#.tmp.pykythe_test.SUBST.home.peter.src.pykythe.pykythe.pod.PlainOldData'
Cross-References for kythe://test-corpus?lang=python?root=test-root#.tmp.pykythe_test.SUBST.home.peter.src.pykythe.pykythe.pod.PlainOldData
  Definitions:
    tmp/pykythe_test/SUBST/home/peter/src/pykythe/pykythe/pod.py	    [16:6-16:18)
      "class PlainOldData:"
  References:
    tmp/pykythe_test/SUBST/home/peter/src/pykythe/pykythe/ast.py	    [22:15-22:27)
      "class File(pod.PlainOldData):"
    tmp/pykythe_test/SUBST/home/peter/src/pykythe/pykythe/pod.py	    [37:27-37:39)
      "class PlainOldDataExtended(PlainOldData):"
    tmp/pykythe_test/SUBST/home/peter/src/pykythe/pykythe/pod.py	    [57:21-57:33)
      "        value: Union[PlainOldData, List[Any], bool, str, int, Dict[Any, Any], None,"
    tmp/pykythe_test/SUBST/home/peter/src/pykythe/pykythe/pod.py	    [61:25-61:37)
      "    if isinstance(value, PlainOldData):"
    tmp/pykythe_test/SUBST/home/peter/src/pykythe/pykythe/ast_raw.py	    [83:14-83:26)
      "class Ctx(pod.PlainOldData):"
    tmp/pykythe_test/SUBST/home/peter/src/pykythe/pykythe/ast_cooked.py	    [92:17-92:29)
      "class FqnCtx(pod.PlainOldData):"

Closing comment (2019-12-10T17:58:43Z): I believe this is a duplicate of #4128