Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Spotbugs remaining fixes #1303

Closed
wants to merge 13 commits into from

Conversation

tomwhite
Copy link
Contributor

Fix all the remaining issues found by Spotbugs (in addition to those in #1277 and #1278). In some cases it is not clear if there is a fix, or what the best fix would be that maintains existing behaviour, so I've added these cases to an exclude list. With the changes to the Gradle build file new violations will be picked up by causing the build to fail.

/cc @lbergelson

Checklist

  • Code compiles correctly
  • New tests covering changes and new functionality
  • All tests passing
  • Extended the README / documentation, if necessary
  • Is not backward compatible (breaks binary or source compatibility)

@codecov-io
Copy link

codecov-io commented Feb 25, 2019

Codecov Report

Merging #1303 into master will decrease coverage by 0.015%.
The diff coverage is 66.667%.

@@               Coverage Diff               @@
##              master     #1303       +/-   ##
===============================================
- Coverage     67.644%   67.628%   -0.015%     
- Complexity      8188      8229       +41     
===============================================
  Files            560       562        +2     
  Lines          33462     33619      +157     
  Branches        5635      5640        +5     
===============================================
+ Hits           22635     22736      +101     
- Misses          8644      8709       +65     
+ Partials        2183      2174        -9
Impacted Files Coverage Δ Complexity Δ
...java/htsjdk/samtools/MergingSamRecordIterator.java 59.494% <100%> (ø) 19 <0> (ø) ⬇️
...ava/htsjdk/samtools/cram/compression/rans/E14.java 90.566% <100%> (+1.887%) 3 <0> (ø) ⬇️
src/main/java/htsjdk/samtools/util/IOUtil.java 58.213% <100%> (+0.607%) 118 <3> (ø) ⬇️
...n/java/htsjdk/samtools/util/SortingCollection.java 64.444% <100%> (ø) 16 <0> (ø) ⬇️
...tsjdk/tribble/readers/AsciiLineReaderIterator.java 84% <100%> (ø) 6 <0> (ø) ⬇️
...in/java/htsjdk/samtools/TextualBAMIndexWriter.java 66.667% <20%> (-0.866%) 12 <0> (ø)
...c/main/java/htsjdk/samtools/util/ftp/FTPReply.java 0% <0%> (-44.444%) 0% <0%> (-9%)
.../main/java/htsjdk/samtools/util/ftp/FTPClient.java 0% <0%> (-23.171%) 0% <0%> (-6%)
...mtools/seekablestream/SeekableFTPStreamHelper.java 0% <0%> (-19.355%) 0% <0%> (-1%)
...c/main/java/htsjdk/samtools/util/ftp/FTPUtils.java 0% <0%> (-17.544%) 0% <0%> (-2%)
... and 52 more

@yfarjoun yfarjoun self-assigned this Feb 25, 2019
@@ -43,7 +43,7 @@ static int compress(final ByteBuffer in, final RansEncSymbol[][] syms,
// Deal with the remainder
l3 = 0xFF & in.get(in_size - 1);
for (i3 = in_size - 2; i3 > 4 * isz4 - 2 && i3 >= 0; i3--) {
final int c3 = 0xFF & in.get(i3 > -1 ? i3 : 0);
final int c3 = 0xFF & in.get(i3);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought this looked suspicious but I missed that the for loop directly restricts i3, e.g. i3 >= 0

@@ -75,7 +75,7 @@ public String peek() {
private class TupleIterator extends AbstractIterator<Tuple<String, Long>> implements LocationAware {

public TupleIterator() {
hasNext(); // Initialize the iterator, which appears to be a requirement of the parent class. TODO: Really?
super.hasNext(); // Initialize the iterator, which appears to be a requirement of the parent class. TODO: Really?
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why add super.? This class doesn't implement hasNext() and it's private.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's to make it clear that it's TupleIterator's superclass (AbstractIterator) that the hasNext() method resolves to, as opposed to hasNext() on the outer class, AsciiLineReaderIterator.

The default is the superclass, so this doesn't change the behaviour, it just makes it clear (and stops Spotbugs complaining). See https://spotbugs.readthedocs.io/en/stable/bugDescriptions.html#ia-potentially-ambiguous-invocation-of-either-an-inherited-or-outer-method-ia-ambiguous-invocation-of-inherited-or-outer-method

Copy link
Contributor

@pshapiro4broad pshapiro4broad left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good to me.

Note to other reviewers - this is blocked by the other spotbugs PRs, as it will enable spotbugs on the code base. Another approach would be to enable spotbugs with blanket exclusions and commit PRs with more refinements later on.

if (content == null) {
writeNullContent(reference);
writeNullContent();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This changes the behavior; before this would throw a NullPointerException. Is the new behavior the correct/desired behavior of this API?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The NPE was introduced in ee10696#diff-d029b962e0444d3ad90c9c69372591bcL70. This fix removes the NPE, which seems like the right thing to do.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was introduced a month after the initial checkin of the code, which was 8 years ago. So it's worked this way for the lifetime of this code. If content == null is not a valid state, it would be better to remove this code rather than add a new feature.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fair enough. I've fixed this to explicitly throw a NPE in this case.

@lbergelson lbergelson mentioned this pull request Mar 18, 2019
5 tasks
@lbergelson
Copy link
Member

Rebased and merged this as #1331

@lbergelson lbergelson closed this Mar 18, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants