diff --git a/src/test/java/com/google/simplecfg/NullableDereferenceTest.java b/src/test/java/com/google/simplecfg/NullableDereferenceTest.java index e2ee3b2..4b58a5e 100644 --- a/src/test/java/com/google/simplecfg/NullableDereferenceTest.java +++ b/src/test/java/com/google/simplecfg/NullableDereferenceTest.java @@ -142,4 +142,11 @@ public class NullableDereferenceTest { "testdata/NullableDereferenceIssue13.javax:33:7: " + "Dereferencing obj, which was declared @Nullable."); } + + @Test public void issue22() { + Collection findings = StmtCfgTest.findings("NullableDereferenceIssue22"); + assertThat(findings).containsExactly( + "testdata/NullableDereferenceIssue22.javax:25:12: " + + "Dereferencing obj, which was declared @Nullable."); + } } diff --git a/testdata/NullableDereferenceIssue22.javax b/testdata/NullableDereferenceIssue22.javax new file mode 100644 index 0000000..f46e751 --- /dev/null +++ b/testdata/NullableDereferenceIssue22.javax @@ -0,0 +1,34 @@ +/** + * Copyright 2016 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 #22 (https://github.com/google/simplecfg/issues/22). + */ +public class NullableDereferenceIssue22 { + public int test(@Nullable Object obj) { + ensure(obj != null); + return obj.hashCode(); // False positive finding generated here. + } + + /** Throws an error if the passed condition is false. */ + private void ensure(boolean condition) throws Error { + if (!condition) { + throw new Error("Condition was false"); + } + } +}