class Name1 listing, partial rewriting of Singleton pattern introduction
This commit is contained in:
parent
00efe7d4b0
commit
d07e2d2889
2 changed files with 40 additions and 2 deletions
BIN
report.pdf
BIN
report.pdf
Binary file not shown.
42
report.tex
42
report.tex
|
@ -168,12 +168,50 @@ submission as the file \textit{analysis.xml}.
|
||||||
\section{Structural Patterns}
|
\section{Structural Patterns}
|
||||||
|
|
||||||
\subsection{TO REWRITE Singleton Pattern}
|
\subsection{TO REWRITE Singleton Pattern}
|
||||||
Lots of false positives for the Singleton pattern. Example,
|
Ensure a class only has one instance and provide a global point of access to it.
|
||||||
com.fasterxml.jackson.core.sym.Name1 has a package private constructor and a
|
The tool found thirteen instances with the Singleton pattern,
|
||||||
|
doing a deeper analysis of the found instances we discovered that some of the results are false positives.
|
||||||
|
Example, com.fasterxml.jackson.core.sym.Name1 has a package private constructor and a
|
||||||
public static final instance of it, but reading the documentation the class
|
public static final instance of it, but reading the documentation the class
|
||||||
represents (short) JSON string literals and therefore is clearly
|
represents (short) JSON string literals and therefore is clearly
|
||||||
initialized by client code.
|
initialized by client code.
|
||||||
|
|
||||||
|
\begin{lstlisting}[caption=Name1 class,language=java]
|
||||||
|
public final class Name1 extends Name {
|
||||||
|
private final static Name1 EMPTY = new Name1("", 0, 0);
|
||||||
|
private final int q;
|
||||||
|
|
||||||
|
Name1(String name, int hash, int quad) {
|
||||||
|
super(name, hash);
|
||||||
|
q = quad;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Name1 getEmptyName() {
|
||||||
|
return EMPTY;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(int quad) {
|
||||||
|
return (quad == q);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(int quad1, int quad2) {
|
||||||
|
return (quad1 == q) && (quad2 == 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(int q1, int q2, int q3) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(int[] quads, int qlen) {
|
||||||
|
return (qlen == 1 && quads[0] == q);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
\end{lstlisting}
|
||||||
|
|
||||||
(com.fasterxml.jackson.core omitted for brevity)
|
(com.fasterxml.jackson.core omitted for brevity)
|
||||||
|
|
||||||
\begin{description}
|
\begin{description}
|
||||||
|
|
Reference in a new issue