-
Notifications
You must be signed in to change notification settings - Fork 600
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow private methods to inherit default annotations from package or …
…class scope (#1222) * refs #374: reproduce reported problem * allow private methods to inherit default annotations Remove the restriction that a method must not be private in order to inherit default annotations from package or class scope. Resolves #374. * bump year in license header * add a comment in changelog as per the PR template * ./gradlew spotlessApply * address pr comments - fix copyright attribution - move entry in changelog Co-authored-by: Ritee <chenh0510@qq.com>
- Loading branch information
Showing
7 changed files
with
107 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
spotbugs-tests/src/test/java/edu/umd/cs/findbugs/detect/Issue374Test.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/* | ||
* Contributions to SpotBugs | ||
* Copyright (C) 2020, ritchan | ||
* | ||
* This library is free software; you can redistribute it and/or | ||
* modify it under the terms of the GNU Lesser General Public | ||
* License as published by the Free Software Foundation; either | ||
* version 2.1 of the License, or (at your option) any later version. | ||
* | ||
* This library is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
* Lesser General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public | ||
* License along with this library; if not, write to the Free Software | ||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
*/ | ||
package edu.umd.cs.findbugs.detect; | ||
|
||
import edu.umd.cs.findbugs.AbstractIntegrationTest; | ||
import edu.umd.cs.findbugs.test.matcher.BugInstanceMatcher; | ||
import edu.umd.cs.findbugs.test.matcher.BugInstanceMatcherBuilder; | ||
import org.junit.Test; | ||
|
||
import static edu.umd.cs.findbugs.test.CountMatcher.containsExactly; | ||
import static org.junit.Assert.assertThat; | ||
|
||
|
||
/** | ||
* @see <a href="https://github.com/spotbugs/spotbugs/issues/374">GitHub issue</a> | ||
*/ | ||
public class Issue374Test extends AbstractIntegrationTest { | ||
@Test | ||
public void test() { | ||
performAnalysis( | ||
"ghIssues/issue374/package-info.class", | ||
"ghIssues/issue374/ClassLevel.class", | ||
"ghIssues/issue374/MethodLevel.class", | ||
"ghIssues/issue374/PackageLevel.class"); | ||
BugInstanceMatcher matcher = new BugInstanceMatcherBuilder() | ||
.bugType("NP_PARAMETER_MUST_BE_NONNULL_BUT_MARKED_AS_NULLABLE") | ||
.build(); | ||
assertThat(getBugCollection(), containsExactly(3, matcher)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
spotbugsTestCases/src/java/ghIssues/issue374/ClassLevel.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package ghIssues.issue374; | ||
|
||
import javax.annotation.Nullable; | ||
import javax.annotation.ParametersAreNonnullByDefault; | ||
|
||
@ParametersAreNonnullByDefault | ||
public class ClassLevel { | ||
public String method() { | ||
return methodNullable(null); | ||
} | ||
|
||
private String methodNullable(@Nullable final String test) { | ||
return methodNonNull(test); | ||
} | ||
|
||
private String methodNonNull(final String test) { | ||
return test; | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
spotbugsTestCases/src/java/ghIssues/issue374/MethodLevel.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package ghIssues.issue374; | ||
|
||
import javax.annotation.Nullable; | ||
import javax.annotation.ParametersAreNonnullByDefault; | ||
|
||
public class MethodLevel { | ||
public String method() { | ||
return methodNullable(null); | ||
} | ||
|
||
private String methodNullable(@Nullable final String test) { | ||
return methodNonNull(test); | ||
} | ||
|
||
@ParametersAreNonnullByDefault | ||
private String methodNonNull(final String test) { | ||
return test; | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
spotbugsTestCases/src/java/ghIssues/issue374/PackageLevel.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package ghIssues.issue374; | ||
|
||
import javax.annotation.Nullable; | ||
|
||
public class PackageLevel { | ||
public String method() { | ||
return methodNullable(null); | ||
} | ||
|
||
private String methodNullable(@Nullable final String test) { | ||
return methodNonNull(test); | ||
} | ||
|
||
private String methodNonNull(final String test) { | ||
return test; | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
spotbugsTestCases/src/java/ghIssues/issue374/package-info.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
/* | ||
* An example to reproduce problem at https://github.com/spotbugs/spotbugs/issues/374 | ||
*/ | ||
@javax.annotation.ParametersAreNonnullByDefault | ||
package ghIssues.issue374; |