[java] AvoidAccessibilityAlteration: allow setAccessible(false)
This restores the cheks for the Java language access control.
This commit is contained in:
@ -76,6 +76,7 @@ is assumed to be deliberate and is not reported.
|
||||
<![CDATA[
|
||||
//PrimaryPrefix
|
||||
[Name[ends-with(@Image, '.setAccessible')]]
|
||||
[not(following-sibling::PrimarySuffix/Arguments//BooleanLiteral[@True = false()])]
|
||||
[pmd-java:typeIs('java.lang.reflect.AccessibleObject')]
|
||||
(: exclude anonymous privileged action classes :)
|
||||
[not(ancestor::AllocationExpression[pmd-java:typeIs('java.security.PrivilegedAction')])]
|
||||
|
@ -165,4 +165,20 @@ public class NoViolation { {
|
||||
} }
|
||||
]]></code>
|
||||
</test-code>
|
||||
|
||||
<test-code>
|
||||
<description>setAccessible(false) is ok</description>
|
||||
<expected-problems>0</expected-problems>
|
||||
<code><![CDATA[
|
||||
import java.lang.reflect.Constructor;
|
||||
|
||||
public class Violation {
|
||||
private void invalidSetAccessCalls() throws NoSuchMethodException, SecurityException {
|
||||
Constructor<?> constructor = this.getClass().getDeclaredConstructor(String.class);
|
||||
// call to setAccessible with false - that's ok
|
||||
constructor.setAccessible(false);
|
||||
}
|
||||
}
|
||||
]]></code>
|
||||
</test-code>
|
||||
</test-data>
|
Reference in New Issue
Block a user