90 lines
2.0 KiB
Plaintext
90 lines
2.0 KiB
Plaintext
== Why is this an issue?
|
|
|
|
include::../description.adoc[]
|
|
|
|
=== Exceptions
|
|
|
|
The rule will not raise issues for unused parameters:
|
|
|
|
* that are annotated with `@javax.enterprise.event.Observes`
|
|
* in overrides and implementation methods
|
|
* in interface `default` methods
|
|
* in non-private methods that only `throw` or that have empty bodies
|
|
* in annotated methods, unless the annotation is `@SuppressWarning("unchecked")` or `@SuppressWarning("rawtypes")`, in which case the annotation will be ignored
|
|
* in overridable methods (non-final, or not member of a final class, non-static, non-private), if the parameter is documented with a proper javadoc.
|
|
|
|
== How to fix it
|
|
|
|
include::../how-to-fix-it.adoc[]
|
|
|
|
=== Code examples
|
|
|
|
==== Noncompliant code example
|
|
|
|
[source,java,diff-id=1,diff-type=noncompliant]
|
|
----
|
|
void doSomething(int a, int b) { // Noncompliant, "b" is unused
|
|
compute(a);
|
|
}
|
|
----
|
|
|
|
==== Compliant solution
|
|
|
|
[source,java,diff-id=1,diff-type=compliant]
|
|
----
|
|
void doSomething(int a) {
|
|
compute(a);
|
|
}
|
|
----
|
|
|
|
Examples of exceptions:
|
|
|
|
[source,java]
|
|
----
|
|
@Override
|
|
void doSomething(int a, int b) { // no issue reported on b
|
|
compute(a);
|
|
}
|
|
|
|
public void foo(String s) {
|
|
// designed to be extended but noop in standard case
|
|
}
|
|
|
|
protected void bar(String s) {
|
|
//open-closed principle
|
|
}
|
|
|
|
public void qix(String s) {
|
|
throw new UnsupportedOperationException("This method should be implemented in subclasses");
|
|
}
|
|
|
|
/**
|
|
* @param s This string may be used for further computation in overriding classes
|
|
*/
|
|
protected void foobar(int a, String s) { // no issue, method is overridable and unused parameter has proper javadoc
|
|
compute(a);
|
|
}
|
|
----
|
|
|
|
== Resources
|
|
|
|
* https://wiki.sei.cmu.edu/confluence/x/5dUxBQ[CERT, MSC12-C.] - Detect and remove code that has no effect or is never executed
|
|
|
|
ifdef::env-github,rspecator-view[]
|
|
|
|
'''
|
|
== Implementation Specification
|
|
(visible only on this page)
|
|
|
|
=== Message
|
|
|
|
include::../message.adoc[]
|
|
|
|
'''
|
|
== Comments And Links
|
|
(visible only on this page)
|
|
|
|
include::../comments-and-links.adoc[]
|
|
|
|
endif::env-github,rspecator-view[]
|