{"action":"created","comment":{"url":"https://api.github.com/repos/SonarSource/sonar-java/pulls/comments/29927217","id":29927217,"diff_hunk":"@@ -0,0 +1,248 @@\n+/*\n+ * SonarQube Java\n+ * Copyright (C) 2012 SonarSource\n+ * dev@sonar.codehaus.org\n+ *\n+ * This program is free software; you can redistribute it and/or\n+ * modify it under the terms of the GNU Lesser General Public\n+ * License as published by the Free Software Foundation; either\n+ * version 3 of the License, or (at your option) any later version.\n+ *\n+ * This program is distributed in the hope that it will be useful,\n+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\n+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\n+ * Lesser General Public License for more details.\n+ *\n+ * You should have received a copy of the GNU Lesser General Public\n+ * License along with this program; if not, write to the Free Software\n+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02\n+ */\n+package org.sonar.java.npe;\n+\n+import com.google.common.base.Joiner;\n+import com.google.common.collect.Lists;\n+import org.sonar.java.resolve.JavaSymbol;\n+import org.sonar.java.symexecengine.DataFlowVisitor;\n+import org.sonar.java.symexecengine.State;\n+import org.sonar.plugins.java.api.semantic.Symbol;\n+import org.sonar.plugins.java.api.tree.ArrayAccessExpressionTree;\n+import org.sonar.plugins.java.api.tree.AssignmentExpressionTree;\n+import org.sonar.plugins.java.api.tree.BinaryExpressionTree;\n+import org.sonar.plugins.java.api.tree.ExpressionTree;\n+import org.sonar.plugins.java.api.tree.MemberSelectExpressionTree;\n+import org.sonar.plugins.java.api.tree.MethodInvocationTree;\n+import org.sonar.plugins.java.api.tree.SwitchStatementTree;\n+import org.sonar.plugins.java.api.tree.Tree;\n+import org.sonar.plugins.java.api.tree.VariableTree;\n+\n+import javax.annotation.Nullable;\n+\n+import java.util.List;\n+\n+public class NpeVisitor extends DataFlowVisitor {\n+\n+  public NpeVisitor(List<VariableTree> parameters) {\n+    for (VariableTree parameter : parameters) {\n+      super.visitVariable(parameter);\n+      State state;\n+      if (parameter.symbol().metadata().isAnnotatedWith(\"javax.annotation.CheckForNull\") || parameter.symbol().metadata().isAnnotatedWith(\"javax.annotation.Nullable\")) {\n+        state = new NPEState.Null(parameter);\n+      } else {\n+        state = new NPEState.NotNull(parameter);\n+      }\n+      executionState.markValueAs(parameter.symbol(), state);\n+    }\n+  }\n+\n+  @Override\n+  protected boolean isSymbolRelevant(Symbol symbol) {\n+    return true;\n+  }\n+\n+  @Override\n+  public void visitAssignmentExpression(AssignmentExpressionTree tree) {\n+    super.visitAssignmentExpression(tree);\n+    Symbol symbol = getSymbol(tree.variable());\n+    if (symbol != null && symbol.owner().isMethodSymbol()) {\n+      setStateOfValue(symbol, tree.expression());\n+    }\n+  }\n+\n+  @Override\n+  public void visitVariable(VariableTree tree) {\n+    super.visitVariable(tree);\n+    setStateOfValue(tree.symbol(), tree.initializer());\n+  }\n+\n+  @Override\n+  public void visitArrayAccessExpression(ArrayAccessExpressionTree tree) {\n+    super.visitArrayAccessExpression(tree);\n+    if (!tree.expression().is(Tree.Kind.MEMBER_SELECT) && isNullTree(tree.expression())) {\n+      executionState.reportIssue(tree);\n+    }\n+  }\n+\n+  private void setStateOfValue(Symbol symbol, @Nullable ExpressionTree tree) {\n+    if (tree == null || isNullTree(tree)) {\n+      executionState.markValueAs(symbol, new NPEState.Null(tree));\n+    } else {\n+      executionState.markValueAs(symbol, new NPEState.NotNull(tree));\n+    }\n+  }\n+\n+  private boolean isNullTree(ExpressionTree tree) {\n+    Symbol symbol = getSymbol(tree);\n+    return (symbol != null && executionState.hasState(symbol, NPEState.Null.class)) ||","path":"java-checks/src/main/java/org/sonar/java/npe/NpeVisitor.java","position":95,"original_position":95,"commit_id":"bf0e8e7a27f0d7a8da1974ff2e52be42e536059e","original_commit_id":"bf0e8e7a27f0d7a8da1974ff2e52be42e536059e","user":{"login":"SonarTech","id":1842438,"avatar_url":"https://avatars.githubusercontent.com/u/1842438?v=3","gravatar_id":"","url":"https://api.github.com/users/SonarTech","html_url":"https://github.com/SonarTech","followers_url":"https://api.github.com/users/SonarTech/followers","following_url":"https://api.github.com/users/SonarTech/following{/other_user}","gists_url":"https://api.github.com/users/SonarTech/gists{/gist_id}","starred_url":"https://api.github.com/users/SonarTech/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/SonarTech/subscriptions","organizations_url":"https://api.github.com/users/SonarTech/orgs","repos_url":"https://api.github.com/users/SonarTech/repos","events_url":"https://api.github.com/users/SonarTech/events{/privacy}","received_events_url":"https://api.github.com/users/SonarTech/received_events","type":"User","site_admin":false},"body":":new: ![MAJOR](https://raw.githubusercontent.com/henryju/image-hosting/master/major.png)Reduce the number of conditional operators (4) used in the expression (maximum allowed 3).[![...](https://raw.githubusercontent.com/henryju/image-hosting/master/more.png)](http://nemo.sonarqube.org/coding_rules#rule_key=squid%3AS1067)\n","created_at":"2015-05-08T09:27:16Z","updated_at":"2015-05-08T09:27:16Z","html_url":"https://github.com/SonarSource/sonar-java/pull/196#discussion_r29927217","pull_request_url":"https://api.github.com/repos/SonarSource/sonar-java/pulls/196","_links":{"self":{"href":"https://api.github.com/repos/SonarSource/sonar-java/pulls/comments/29927217"},"html":{"href":"https://github.com/SonarSource/sonar-java/pull/196#discussion_r29927217"},"pull_request":{"href":"https://api.github.com/repos/SonarSource/sonar-java/pulls/196"}}},"pull_request":{"url":"https://api.github.com/repos/SonarSource/sonar-java/pulls/196","id":34742146,"html_url":"https://github.com/SonarSource/sonar-java/pull/196","diff_url":"https://github.com/SonarSource/sonar-java/pull/196.diff","patch_url":"https://github.com/SonarSource/sonar-java/pull/196.patch","issue_url":"https://api.github.com/repos/SonarSource/sonar-java/issues/196","number":196,"state":"open","locked":false,"title":"Sonarjava 1030 npe","user":{"login":"benzonico","id":1199708,"avatar_url":"https://avatars.githubusercontent.com/u/1199708?v=3","gravatar_id":"","url":"https://api.github.com/users/benzonico","html_url":"https://github.com/benzonico","followers_url":"https://api.github.com/users/benzonico/followers","following_url":"https://api.github.com/users/benzonico/following{/other_user}","gists_url":"https://api.github.com/users/benzonico/gists{/gist_id}","starred_url":"https://api.github.com/users/benzonico/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/benzonico/subscriptions","organizations_url":"https://api.github.com/users/benzonico/orgs","repos_url":"https://api.github.com/users/benzonico/repos","events_url":"https://api.github.com/users/benzonico/events{/privacy}","received_events_url":"https://api.github.com/users/benzonico/received_events","type":"User","site_admin":false},"body":"","created_at":"2015-05-05T16:28:59Z","updated_at":"2015-05-08T09:27:16Z","closed_at":null,"merged_at":null,"merge_commit_sha":"f165d2ebbdfe7a303057a84c8dc59e75dedea208","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/SonarSource/sonar-java/pulls/196/commits","review_comments_url":"https://api.github.com/repos/SonarSource/sonar-java/pulls/196/comments","review_comment_url":"https://api.github.com/repos/SonarSource/sonar-java/pulls/comments{/number}","comments_url":"https://api.github.com/repos/SonarSource/sonar-java/issues/196/comments","statuses_url":"https://api.github.com/repos/SonarSource/sonar-java/statuses/bf0e8e7a27f0d7a8da1974ff2e52be42e536059e","head":{"label":"benzonico:SONARJAVA-1030_NPE","ref":"SONARJAVA-1030_NPE","sha":"bf0e8e7a27f0d7a8da1974ff2e52be42e536059e","user":{"login":"benzonico","id":1199708,"avatar_url":"https://avatars.githubusercontent.com/u/1199708?v=3","gravatar_id":"","url":"https://api.github.com/users/benzonico","html_url":"https://github.com/benzonico","followers_url":"https://api.github.com/users/benzonico/followers","following_url":"https://api.github.com/users/benzonico/following{/other_user}","gists_url":"https://api.github.com/users/benzonico/gists{/gist_id}","starred_url":"https://api.github.com/users/benzonico/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/benzonico/subscriptions","organizations_url":"https://api.github.com/users/benzonico/orgs","repos_url":"https://api.github.com/users/benzonico/repos","events_url":"https://api.github.com/users/benzonico/events{/privacy}","received_events_url":"https://api.github.com/users/benzonico/received_events","type":"User","site_admin":false},"repo":{"id":16585446,"name":"sonar-java","full_name":"benzonico/sonar-java","owner":{"login":"benzonico","id":1199708,"avatar_url":"https://avatars.githubusercontent.com/u/1199708?v=3","gravatar_id":"","url":"https://api.github.com/users/benzonico","html_url":"https://github.com/benzonico","followers_url":"https://api.github.com/users/benzonico/followers","following_url":"https://api.github.com/users/benzonico/following{/other_user}","gists_url":"https://api.github.com/users/benzonico/gists{/gist_id}","starred_url":"https://api.github.com/users/benzonico/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/benzonico/subscriptions","organizations_url":"https://api.github.com/users/benzonico/orgs","repos_url":"https://api.github.com/users/benzonico/repos","events_url":"https://api.github.com/users/benzonico/events{/privacy}","received_events_url":"https://api.github.com/users/benzonico/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/benzonico/sonar-java","description":"","fork":true,"url":"https://api.github.com/repos/benzonico/sonar-java","forks_url":"https://api.github.com/repos/benzonico/sonar-java/forks","keys_url":"https://api.github.com/repos/benzonico/sonar-java/keys{/key_id}","collaborators_url":"https://api.github.com/repos/benzonico/sonar-java/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/benzonico/sonar-java/teams","hooks_url":"https://api.github.com/repos/benzonico/sonar-java/hooks","issue_events_url":"https://api.github.com/repos/benzonico/sonar-java/issues/events{/number}","events_url":"https://api.github.com/repos/benzonico/sonar-java/events","assignees_url":"https://api.github.com/repos/benzonico/sonar-java/assignees{/user}","branches_url":"https://api.github.com/repos/benzonico/sonar-java/branches{/branch}","tags_url":"https://api.github.com/repos/benzonico/sonar-java/tags","blobs_url":"https://api.github.com/repos/benzonico/sonar-java/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/benzonico/sonar-java/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/benzonico/sonar-java/git/refs{/sha}","trees_url":"https://api.github.com/repos/benzonico/sonar-java/git/trees{/sha}","statuses_url":"https://api.github.com/repos/benzonico/sonar-java/statuses/{sha}","languages_url":"https://api.github.com/repos/benzonico/sonar-java/languages","stargazers_url":"https://api.github.com/repos/benzonico/sonar-java/stargazers","contributors_url":"https://api.github.com/repos/benzonico/sonar-java/contributors","subscribers_url":"https://api.github.com/repos/benzonico/sonar-java/subscribers","subscription_url":"https://api.github.com/repos/benzonico/sonar-java/subscription","commits_url":"https://api.github.com/repos/benzonico/sonar-java/commits{/sha}","git_commits_url":"https://api.github.com/repos/benzonico/sonar-java/git/commits{/sha}","comments_url":"https://api.github.com/repos/benzonico/sonar-java/comments{/number}","issue_comment_url":"https://api.github.com/repos/benzonico/sonar-java/issues/comments{/number}","contents_url":"https://api.github.com/repos/benzonico/sonar-java/contents/{+path}","compare_url":"https://api.github.com/repos/benzonico/sonar-java/compare/{base}...{head}","merges_url":"https://api.github.com/repos/benzonico/sonar-java/merges","archive_url":"https://api.github.com/repos/benzonico/sonar-java/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/benzonico/sonar-java/downloads","issues_url":"https://api.github.com/repos/benzonico/sonar-java/issues{/number}","pulls_url":"https://api.github.com/repos/benzonico/sonar-java/pulls{/number}","milestones_url":"https://api.github.com/repos/benzonico/sonar-java/milestones{/number}","notifications_url":"https://api.github.com/repos/benzonico/sonar-java/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/benzonico/sonar-java/labels{/name}","releases_url":"https://api.github.com/repos/benzonico/sonar-java/releases{/id}","created_at":"2014-02-06T16:29:39Z","updated_at":"2014-08-11T16:38:33Z","pushed_at":"2015-05-08T09:23:42Z","git_url":"git://github.com/benzonico/sonar-java.git","ssh_url":"git@github.com:benzonico/sonar-java.git","clone_url":"https://github.com/benzonico/sonar-java.git","svn_url":"https://github.com/benzonico/sonar-java","homepage":"","size":12542,"stargazers_count":0,"watchers_count":0,"language":"Java","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"SonarSource:master","ref":"master","sha":"f4ba9039d36ec943972baa33559c558826331f7b","user":{"login":"SonarSource","id":545988,"avatar_url":"https://avatars.githubusercontent.com/u/545988?v=3","gravatar_id":"","url":"https://api.github.com/users/SonarSource","html_url":"https://github.com/SonarSource","followers_url":"https://api.github.com/users/SonarSource/followers","following_url":"https://api.github.com/users/SonarSource/following{/other_user}","gists_url":"https://api.github.com/users/SonarSource/gists{/gist_id}","starred_url":"https://api.github.com/users/SonarSource/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/SonarSource/subscriptions","organizations_url":"https://api.github.com/users/SonarSource/orgs","repos_url":"https://api.github.com/users/SonarSource/repos","events_url":"https://api.github.com/users/SonarSource/events{/privacy}","received_events_url":"https://api.github.com/users/SonarSource/received_events","type":"Organization","site_admin":false},"repo":{"id":5674787,"name":"sonar-java","full_name":"SonarSource/sonar-java","owner":{"login":"SonarSource","id":545988,"avatar_url":"https://avatars.githubusercontent.com/u/545988?v=3","gravatar_id":"","url":"https://api.github.com/users/SonarSource","html_url":"https://github.com/SonarSource","followers_url":"https://api.github.com/users/SonarSource/followers","following_url":"https://api.github.com/users/SonarSource/following{/other_user}","gists_url":"https://api.github.com/users/SonarSource/gists{/gist_id}","starred_url":"https://api.github.com/users/SonarSource/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/SonarSource/subscriptions","organizations_url":"https://api.github.com/users/SonarSource/orgs","repos_url":"https://api.github.com/users/SonarSource/repos","events_url":"https://api.github.com/users/SonarSource/events{/privacy}","received_events_url":"https://api.github.com/users/SonarSource/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/SonarSource/sonar-java","description":"","fork":false,"url":"https://api.github.com/repos/SonarSource/sonar-java","forks_url":"https://api.github.com/repos/SonarSource/sonar-java/forks","keys_url":"https://api.github.com/repos/SonarSource/sonar-java/keys{/key_id}","collaborators_url":"https://api.github.com/repos/SonarSource/sonar-java/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/SonarSource/sonar-java/teams","hooks_url":"https://api.github.com/repos/SonarSource/sonar-java/hooks","issue_events_url":"https://api.github.com/repos/SonarSource/sonar-java/issues/events{/number}","events_url":"https://api.github.com/repos/SonarSource/sonar-java/events","assignees_url":"https://api.github.com/repos/SonarSource/sonar-java/assignees{/user}","branches_url":"https://api.github.com/repos/SonarSource/sonar-java/branches{/branch}","tags_url":"https://api.github.com/repos/SonarSource/sonar-java/tags","blobs_url":"https://api.github.com/repos/SonarSource/sonar-java/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/SonarSource/sonar-java/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/SonarSource/sonar-java/git/refs{/sha}","trees_url":"https://api.github.com/repos/SonarSource/sonar-java/git/trees{/sha}","statuses_url":"https://api.github.com/repos/SonarSource/sonar-java/statuses/{sha}","languages_url":"https://api.github.com/repos/SonarSource/sonar-java/languages","stargazers_url":"https://api.github.com/repos/SonarSource/sonar-java/stargazers","contributors_url":"https://api.github.com/repos/SonarSource/sonar-java/contributors","subscribers_url":"https://api.github.com/repos/SonarSource/sonar-java/subscribers","subscription_url":"https://api.github.com/repos/SonarSource/sonar-java/subscription","commits_url":"https://api.github.com/repos/SonarSource/sonar-java/commits{/sha}","git_commits_url":"https://api.github.com/repos/SonarSource/sonar-java/git/commits{/sha}","comments_url":"https://api.github.com/repos/SonarSource/sonar-java/comments{/number}","issue_comment_url":"https://api.github.com/repos/SonarSource/sonar-java/issues/comments{/number}","contents_url":"https://api.github.com/repos/SonarSource/sonar-java/contents/{+path}","compare_url":"https://api.github.com/repos/SonarSource/sonar-java/compare/{base}...{head}","merges_url":"https://api.github.com/repos/SonarSource/sonar-java/merges","archive_url":"https://api.github.com/repos/SonarSource/sonar-java/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/SonarSource/sonar-java/downloads","issues_url":"https://api.github.com/repos/SonarSource/sonar-java/issues{/number}","pulls_url":"https://api.github.com/repos/SonarSource/sonar-java/pulls{/number}","milestones_url":"https://api.github.com/repos/SonarSource/sonar-java/milestones{/number}","notifications_url":"https://api.github.com/repos/SonarSource/sonar-java/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/SonarSource/sonar-java/labels{/name}","releases_url":"https://api.github.com/repos/SonarSource/sonar-java/releases{/id}","created_at":"2012-09-04T15:53:13Z","updated_at":"2015-05-07T16:47:33Z","pushed_at":"2015-05-08T09:23:43Z","git_url":"git://github.com/SonarSource/sonar-java.git","ssh_url":"git@github.com:SonarSource/sonar-java.git","clone_url":"https://github.com/SonarSource/sonar-java.git","svn_url":"https://github.com/SonarSource/sonar-java","homepage":"","size":32047,"stargazers_count":41,"watchers_count":41,"language":"Java","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":75,"mirror_url":null,"open_issues_count":6,"forks":75,"open_issues":6,"watchers":41,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/SonarSource/sonar-java/pulls/196"},"html":{"href":"https://github.com/SonarSource/sonar-java/pull/196"},"issue":{"href":"https://api.github.com/repos/SonarSource/sonar-java/issues/196"},"comments":{"href":"https://api.github.com/repos/SonarSource/sonar-java/issues/196/comments"},"review_comments":{"href":"https://api.github.com/repos/SonarSource/sonar-java/pulls/196/comments"},"review_comment":{"href":"https://api.github.com/repos/SonarSource/sonar-java/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/SonarSource/sonar-java/pulls/196/commits"},"statuses":{"href":"https://api.github.com/repos/SonarSource/sonar-java/statuses/bf0e8e7a27f0d7a8da1974ff2e52be42e536059e"}}}}