Skip to content

Resolve numerous Coverity findings.#536

Merged
sjudeng merged 1 commit into
JanusGraph:masterfrom
sjudeng:scan-fixes
Sep 23, 2017
Merged

Resolve numerous Coverity findings.#536
sjudeng merged 1 commit into
JanusGraph:masterfrom
sjudeng:scan-fixes

Conversation

@sjudeng

@sjudeng sjudeng commented Sep 21, 2017

Copy link
Copy Markdown
Contributor

Relates to #535

@janusgraph-bot janusgraph-bot added the cla: yes This PR is compliant with the CLA label Sep 21, 2017

@davidclement90 davidclement90 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Nice cleanup

log.trace("Vertex {} has unknown lifecycle state", vertexId);
return null;
} else if (!tv.edges(Direction.BOTH).hasNext() && !tv.properties().hasNext()) {
if (!tv.edges(Direction.BOTH).hasNext() && !tv.properties().hasNext()) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Why did you remove the log ?
And can you delete the dead code just above ?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@davidclement90 This section is unreachable because it's conditioned on !foundVertexState and foundVertexState is set to !verifyVertexExistence (L93), which is always true since verifyVertexExistence is false (L48). I never would have found this if it wasn't for Coverity (and it took me awhile to see it even after it was flagged).

I just pushed updates to further remove the useless foundVertexState, which hopefully makes this clearer. Also removed the commented out code.

@sjudeng sjudeng force-pushed the scan-fixes branch 2 times, most recently from 65cdbe3 to ba2b9c2 Compare September 22, 2017 22:36
} else if (other instanceof JanusGraphElement) {
return ((JanusGraphElement) other).hasId() && getCompareId()==((JanusGraphElement)other).longId();
} else if (other instanceof Element) {
} else if (other != null) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why this change from if (other instanceof Element) to if (other != null)?

The new check is always true, because the first line checks for other == null; however, the next line casts other to Element, so we really should have checked whether other instanceof Element is true.

Should this line be reverted to the original?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@mbrukman At this point other is an instance of Element since otherwise it wouldn't pass the check here. But I did just push an update to remove the null check since you're right null was checked above.

File directory = new File(dir);
if (!directory.exists()) directory.mkdirs();
if (!directory.exists() || !directory.isDirectory() || !directory.canWrite())
if ((!directory.exists() && !directory.mkdirs()) || !directory.isDirectory() || !directory.canWrite())

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Since you're here, would you mind enclosing the if statement's single-line body in { ... } so that it's clear that it refers to a single statement, please? We've had other situations in this code base where indentation was counter to the actual syntax; would be nice to avoid that going forward.

Incidentally, I like how Go enforces braces for if statements, even for a single line, to avoid this ambiguity.

File path = new File(dir);
if (!path.exists()) path.mkdirs();
if (!path.exists() || !path.isDirectory() || !path.canWrite())
if ((!path.exists() && !path.mkdirs()) || !path.isDirectory() || !path.canWrite())

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Please add {...} around if's statement body.

@Override
public boolean hasNext() {
if (count != 0 && count % batchSize == 0 && batchSize * numBatches < limit) {
if (count != 0 && count % batchSize == 0 && count < limit) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This change seems reasonable, but was this a Coverity-specified error or a separate change? I had to convince myself that this is correct, but this is a behavior change, so I'm curious how none of the unit tests failed before with this, and none required to be changed given this change (i.e., it should be possible to reproduce this error in a unittest such that it fails before, and succeeds after this change; or, that it succeeds before with an erroneous assertion, and this change requires changing said assertion to be correct).

Should this be a separate change?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@mbrukman The Coverity finding was that batchSize*numBatches is performed at int32 but limit is int64. Upon review though I realized when count % batchSize == 0 (e.g. at the start of a new batch), count is equal to batchSize * numBatches. I was familiar with this line from reviewing when it was added (see #481 (comment)). @davidclement90 Does this seem okay?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Agreed, LGTM.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Yes it's ok LGTM

Signed-off-by: sjudeng <sjudeng@users.noreply.github.com>

@mbrukman mbrukman left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM

@Override
public boolean hasNext() {
if (count != 0 && count % batchSize == 0 && batchSize * numBatches < limit) {
if (count != 0 && count % batchSize == 0 && count < limit) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Yes it's ok LGTM

@sjudeng sjudeng merged commit f2f1eda into JanusGraph:master Sep 23, 2017
bwatson-rti-org pushed a commit to bwatson-rti-org/janusgraph that referenced this pull request Mar 9, 2019
Resolve numerous Coverity findings.
micpod pushed a commit to micpod/janusgraph that referenced this pull request Nov 5, 2019
Resolve numerous Coverity findings.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cla: yes This PR is compliant with the CLA

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants