Skip to content

Commit

Permalink
Fix NullPointerException in cquery --output=graph.
Browse files Browse the repository at this point in the history
Fixes bazelbuild#12915.

The repro from the bug crashes because these two deps are compared:

`Target: @remote_java_tools_linux//:java_tools/src/tools/singlejar/singlejar_local`
`Config: d8d0eb07eb92791668ac973282be1523379b0025b22f0ade56b13d519f2feb2a`

`Target: @remote_java_tools_linux//:java_tools/src/tools/singlejar/singlejar_local`
`Config: null`

This is a `cc_binary`: https://github.com/bazelbuild/bazel/blob/0c1257ed4e1b83f8d0f6c79d641f6bfcf4d1cfc4/src/tools/singlejar/BUILD#L92-L93

I have no idea why the graph visitor tags one of its instances with a null configuration. Nevertheless, this code is still safer.

Closes bazelbuild#13002.

PiperOrigin-RevId: 357259481
  • Loading branch information
gregestren authored and copybara-github committed Feb 12, 2021
1 parent 8d6ac07 commit 97bc48d
Showing 1 changed file with 12 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,18 @@ Iterable<KeyedConfiguredTarget> getDirectDeps(KeyedConfiguredTarget target)
// Order graph output first by target label, then by configuration hash.
Label label1 = ct1.getLabel();
Label label2 = ct2.getLabel();
return label1.equals(label2)
? ct1.getConfigurationChecksum().compareTo(ct2.getConfigurationChecksum())
: label1.compareTo(label2);
if (!label1.equals(label2)) {
return label1.compareTo(label2);
}
String checksum1 = ct1.getConfigurationChecksum();
String checksum2 = ct2.getConfigurationChecksum();
if (checksum1 == null) {
return -1;
} else if (checksum2 == null) {
return 1;
} else {
return checksum1.compareTo(checksum2);
}
};

@Override
Expand Down

0 comments on commit 97bc48d

Please sign in to comment.