rspec/rules/S3011/java/rule.adoc
Fred Tingaud a08c3bbd23
Modify Rule S3011: LaYC reflection
Co-authored-by: Nils Werner <nils.werner@sonarsource.com>
2023-06-13 19:24:21 +02:00

35 lines
842 B
Plaintext

== Why is this an issue?
include::../description.adoc[]
[source,java]
----
public void makeItPublic(String methodName) throws NoSuchMethodException {
this.getClass().getMethod(methodName).setAccessible(true); // Noncompliant
}
public void setItAnyway(String fieldName, int value) {
this.getClass().getDeclaredField(fieldName).setInt(this, value); // Noncompliant; bypasses controls in setter
}
----
include::../resources.adoc[]
* https://wiki.sei.cmu.edu/confluence/x/_jZGBQ[CERT, SEC05-J.] - Do not use reflection to increase accessibility of classes, methods, or fields
ifdef::env-github,rspecator-view[]
'''
== Implementation Specification
(visible only on this page)
include::../message.adoc[]
'''
== Comments And Links
(visible only on this page)
include::../comments-and-links.adoc[]
endif::env-github,rspecator-view[]