Skip to content

Commit

Permalink
Add test for issue google#22
Browse files Browse the repository at this point in the history
  • Loading branch information
llbit committed Aug 4, 2016
1 parent 4e498b2 commit 5ebd2b8
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -142,4 +142,11 @@ public class NullableDereferenceTest {
"testdata/NullableDereferenceIssue13.javax:33:7: "
+ "Dereferencing obj, which was declared @Nullable.");
}

@Test public void issue22() {
Collection<String> findings = StmtCfgTest.findings("NullableDereferenceIssue22");
assertThat(findings).containsExactly(
"testdata/NullableDereferenceIssue22.javax:25:12: "
+ "Dereferencing obj, which was declared @Nullable.");
}
}
33 changes: 33 additions & 0 deletions testdata/NullableDereferenceIssue22.javax
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/**
* Copyright 2015 Google Inc. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import javax.annotation.Nullable;

/**
* This is test data, not real source code!
* Test for GitHub issue #13 (https://github.com/google/simplecfg/issues/13).
*/
public class NullableDereferenceIssue22 {
public int test(@Nullable Object obj) {
ensure(obj != null);
return obj.hashCode(); // False positive finding generated here.
}

private void ensure(boolean condition) throws Error {
if (!condition) {
throw new Error("Condition was false");
}
}
}

0 comments on commit 5ebd2b8

Please sign in to comment.