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

STORM-3048 : A Potential NPE #2657

Closed
wants to merge 2 commits into from
Closed

Conversation

lujiefsi
Copy link
Contributor

@lujiefsi lujiefsi commented May 2, 2018

We have developed a static analysis tool NPEDetector to find some potential NPE. Our analysis shows that some callees may return null in corner case(e.g. node crash , IO exception), some of their callers have !=null check but some do not have.

Bug:

Cluster#getAssignmentById has 20 callers, 18 callers have null checker like this:

SchedulerAssignment assignment = cluster.getAssignmentById(td.getId());
if (assignment != null) {
    cpuNeeded -= getCpuUsed(assignment);
     memoryNeeded -= getMemoryUsed(assignment);
}

the caller have no null checker :ConstraintSolverStrategy#checkSpreadSchedulingValid ConstraintSolverStrategy#checkConstraintsSatisfied.

I was feel uncertain about whether add null checker here, so i only add assert. If this bug are false positive, please tell me.

@lujiefsi lujiefsi changed the title STORM-3048 STORM-3048 : A Potential NPE May 2, 2018
Copy link
Contributor

@revans2 revans2 left a comment

Choose a reason for hiding this comment

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

+1

The changes are strictly not needed, because the code only runs to verify that a scheduling is correct, so if there is no scheduling at all, which is the case for the NPE, then something really really bad has happened. But because these are in the context of a test the asserts are fine.

@@ -98,6 +98,7 @@ public static boolean validateSolution(Cluster cluster, TopologyDetails td) {
*/
private static boolean checkConstraintsSatisfied(Cluster cluster, TopologyDetails topo) {
LOG.info("Checking constraints...");
assert(cluster.getAssignmentById(topo.getId())!=null);
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: space before and after !=. same for the below code changes.

@revans2
Copy link
Contributor

revans2 commented May 4, 2018

I am getting a failure now of

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-checkstyle-plugin:2.17:check (validate) on project storm-server: You have 792 Checkstyle violations. The maximum number of allowed violations is 783. -> [Help 1]

Specifically

/Users/evans/src/apache-commit/storm-server/src/main/java/org/apache/storm/scheduler/resource/strategies/scheduling/ConstraintSolverStrategy.java
	101: WhitespaceAround: 'assert' is not followed by whitespace. Empty blocks may only be represented as {} when not part of a multi-block statement (4.1.3)
	101: WhitespaceAround: '!=' is not preceded with whitespace.
	101: WhitespaceAround: '!=' is not followed by whitespace. Empty blocks may only be represented as {} when not part of a multi-block statement (4.1.3)
	139: WhitespaceAround: 'assert' is not followed by whitespace. Empty blocks may only be represented as {} when not part of a multi-block statement (4.1.3)
	139: WhitespaceAround: '!=' is not preceded with whitespace.
	139: WhitespaceAround: '!=' is not followed by whitespace. Empty blocks may only be represented as {} when not part of a multi-block statement (4.1.3)
	178: WhitespaceAround: 'assert' is not followed by whitespace. Empty blocks may only be represented as {} when not part of a multi-block statement (4.1.3)
	178: WhitespaceAround: '!=' is not preceded with whitespace.
	178: WhitespaceAround: '!=' is not followed by whitespace. Empty blocks may only be represented as {} when not part of a multi-block statement (4.1.3)

Copy link
Contributor

@HeartSaVioR HeartSaVioR left a comment

Choose a reason for hiding this comment

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

+1

@asfgit asfgit closed this in 3ad1937 Jun 3, 2018
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.

4 participants