[java] ImmutableField: Ignore @Value (Spring) and @Captor (Mockito)

This commit is contained in:
James Harrison 2022-06-07 09:58:45 +01:00
parent 021c5a25e8
commit e29a589970
No known key found for this signature in database
GPG Key ID: FF66133B6520B71D
5 changed files with 28 additions and 3 deletions

View File

@ -3384,7 +3384,8 @@
"avatar_url": "https://avatars.githubusercontent.com/u/242337?v=4",
"profile": "https://github.com/jjlharrison",
"contributions": [
"bug"
"bug",
"code"
]
},
{

View File

@ -307,7 +307,7 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d
<td align="center"><a href="https://www.linkedin.com/in/publicstaticvoidmain"><img src="https://avatars.githubusercontent.com/u/457542?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Ivo Šmíd</b></sub></a><br /><a href="https://github.com/pmd/pmd/issues?q=author%3Abedla" title="Bug reports">🐛</a></td>
<td align="center"><a href="https://github.com/JJengility"><img src="https://avatars.githubusercontent.com/u/29776644?v=4?s=100" width="100px;" alt=""/><br /><sub><b>JJengility</b></sub></a><br /><a href="https://github.com/pmd/pmd/issues?q=author%3AJJengility" title="Bug reports">🐛</a></td>
<td align="center"><a href="https://github.com/jakehemmerle"><img src="https://avatars.githubusercontent.com/u/8061957?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Jake Hemmerle</b></sub></a><br /><a href="https://github.com/pmd/pmd/issues?q=author%3Ajakehemmerle" title="Bug reports">🐛</a></td>
<td align="center"><a href="https://github.com/jjlharrison"><img src="https://avatars.githubusercontent.com/u/242337?v=4?s=100" width="100px;" alt=""/><br /><sub><b>James Harrison</b></sub></a><br /><a href="https://github.com/pmd/pmd/issues?q=author%3Ajjlharrison" title="Bug reports">🐛</a></td>
<td align="center"><a href="https://github.com/jjlharrison"><img src="https://avatars.githubusercontent.com/u/242337?v=4?s=100" width="100px;" alt=""/><br /><sub><b>James Harrison</b></sub></a><br /><a href="https://github.com/pmd/pmd/commits?author=jjlharrison" title="Code">💻</a> <a href="https://github.com/pmd/pmd/issues?q=author%3Ajjlharrison" title="Bug reports">🐛</a></td>
<td align="center"><a href="https://github.com/jgerken"><img src="https://avatars.githubusercontent.com/u/1132816?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Jan</b></sub></a><br /><a href="https://github.com/pmd/pmd/issues?q=author%3Ajgerken" title="Bug reports">🐛</a></td>
</tr>
<tr>

View File

@ -15,6 +15,9 @@ This is a {{ site.pmd.release_type }} release.
### New and noteworthy
### Fixed Issues
* java-design
* [#3981](https://github.com/pmd/pmd/issues/3981): \[java] ImmutableField reports fields annotated with @Value (Spring)
* [#3998](https://github.com/pmd/pmd/issues/3998): \[java] ImmutableField reports fields annotated with @Captor (Mockito)
* java-errorprone
* [#3936](https://github.com/pmd/pmd/issues/3936): \[java] AvoidFieldNameMatchingMethodName should consider enum class
* [#3937](https://github.com/pmd/pmd/issues/3937): \[java] AvoidDuplicateLiterals - uncompilable test cases
@ -24,6 +27,7 @@ This is a {{ site.pmd.release_type }} release.
### External Contributions
* [#3985](https://github.com/pmd/pmd/pull/3985): \[java] Fix false negative problem about Enum in AvoidFieldNameMatchingMethodName #3936 - [@Scrsloota](https://github.com/Scrsloota)
* [#3993](https://github.com/pmd/pmd/pull/3993): \[java] AvoidDuplicateLiterals - Add the method "buz" definition to test cases - [@dalizi007](https://github.com/dalizi007)
* [#4002](https://github.com/pmd/pmd/pull/4002): \[java] ImmutableField - Ignore fields annotated with @Value (Spring) or @Captor (Mockito) - [@jjlharrison](https://github.com/jjlharrison)
{% endtocmaker %}

View File

@ -46,9 +46,11 @@ public class ImmutableFieldRule extends AbstractLombokAwareRule {
@Override
protected Collection<String> defaultSuppressionAnnotations() {
Collection<String> defaultValues = new ArrayList<>(super.defaultSuppressionAnnotations());
defaultValues.add("org.mockito.Mock");
defaultValues.add("org.mockito.Captor");
defaultValues.add("org.mockito.InjectMocks");
defaultValues.add("org.mockito.Mock");
defaultValues.add("org.springframework.beans.factory.annotation.Autowired");
defaultValues.add("org.springframework.beans.factory.annotation.Value");
defaultValues.add("org.springframework.boot.test.mock.mockito.MockBean");
return defaultValues;

View File

@ -603,4 +603,22 @@ class Baz {}
class Foo2 {}
]]></code>
</test-code>
<test-code>
<description>#3981 #3998 [java] ImmutableField reports fields annotated with @Value (Spring) and @Captor (Mockito)</description>
<expected-problems>0</expected-problems>
<code><![CDATA[
import org.mockito.Captor;
import org.mockito.ArgumentCaptor;
import org.springframework.beans.factory.annotation.Value;
public class ExampleImmutableField {
@Value("${property.value}")
private String bar2;
@Captor
private ArgumentCaptor<Object> baz2;
}
]]></code>
</test-code>
</test-data>