[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[
|
<![CDATA[
|
||||||
//PrimaryPrefix
|
//PrimaryPrefix
|
||||||
[Name[ends-with(@Image, '.setAccessible')]]
|
[Name[ends-with(@Image, '.setAccessible')]]
|
||||||
|
[not(following-sibling::PrimarySuffix/Arguments//BooleanLiteral[@True = false()])]
|
||||||
[pmd-java:typeIs('java.lang.reflect.AccessibleObject')]
|
[pmd-java:typeIs('java.lang.reflect.AccessibleObject')]
|
||||||
(: exclude anonymous privileged action classes :)
|
(: exclude anonymous privileged action classes :)
|
||||||
[not(ancestor::AllocationExpression[pmd-java:typeIs('java.security.PrivilegedAction')])]
|
[not(ancestor::AllocationExpression[pmd-java:typeIs('java.security.PrivilegedAction')])]
|
||||||
|
@ -165,4 +165,20 @@ public class NoViolation { {
|
|||||||
} }
|
} }
|
||||||
]]></code>
|
]]></code>
|
||||||
</test-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>
|
</test-data>
|
Reference in New Issue
Block a user