64 lines
1.9 KiB
Plaintext
64 lines
1.9 KiB
Plaintext
== Why is this an issue?
|
|
|
|
``++private++`` methods that are never executed are dead code: unnecessary, inoperative code that should be removed. Cleaning out dead code decreases the size of the maintained codebase, making it easier to understand the program and preventing bugs from being introduced.
|
|
|
|
|
|
Note that this rule does not take reflection into account, which means that issues will be raised on ``++private++`` methods that are only accessed using the reflection API.
|
|
|
|
=== Noncompliant code example
|
|
|
|
[source,java]
|
|
----
|
|
public class Foo implements Serializable
|
|
{
|
|
private Foo(){} //Compliant, private empty constructor intentionally used to prevent any direct instantiation of a class.
|
|
public static void doSomething(){
|
|
Foo foo = new Foo();
|
|
...
|
|
}
|
|
private void unusedPrivateMethod(){...}
|
|
private void writeObject(ObjectOutputStream s){...} //Compliant, relates to the java serialization mechanism
|
|
private void readObject(ObjectInputStream in){...} //Compliant, relates to the java serialization mechanism
|
|
}
|
|
----
|
|
|
|
=== Compliant solution
|
|
|
|
[source,java]
|
|
----
|
|
public class Foo implements Serializable
|
|
{
|
|
private Foo(){} //Compliant, private empty constructor intentionally used to prevent any direct instantiation of a class.
|
|
public static void doSomething(){
|
|
Foo foo = new Foo();
|
|
...
|
|
}
|
|
|
|
private void writeObject(ObjectOutputStream s){...} //Compliant, relates to the java serialization mechanism
|
|
|
|
private void readObject(ObjectInputStream in){...} //Compliant, relates to the java serialization mechanism
|
|
}
|
|
----
|
|
|
|
=== Exceptions
|
|
|
|
This rule doesn't raise issues for:
|
|
|
|
* annotated methods
|
|
* methods with parameters that are annotated with `@javax.enterprise.event.Observes`
|
|
|
|
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[]
|