diff --git a/report.pdf b/report.pdf index 6642b0b..4f9203a 100644 Binary files a/report.pdf and b/report.pdf differ diff --git a/report.tex b/report.tex index c2648b8..bb9b972 100644 --- a/report.tex +++ b/report.tex @@ -168,12 +168,50 @@ submission as the file \textit{analysis.xml}. \section{Structural Patterns} \subsection{TO REWRITE Singleton Pattern} -Lots of false positives for the Singleton pattern. Example, -com.fasterxml.jackson.core.sym.Name1 has a package private constructor and a +Ensure a class only has one instance and provide a global point of access to it. +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 represents (short) JSON string literals and therefore is clearly 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) \begin{description}