From f7de5a6e43e7304ee8d9a07f838236995d60bedd Mon Sep 17 00:00:00 2001 From: Volodymyr Karpenko Date: Sun, 23 Oct 2022 21:25:33 +0200 Subject: [PATCH] corrections --- report.tex | 70 +++++++++++++++--------------------------------------- 1 file changed, 19 insertions(+), 51 deletions(-) diff --git a/report.tex b/report.tex index 8cbdd67..2db4256 100644 --- a/report.tex +++ b/report.tex @@ -129,26 +129,19 @@ lines of Java code and this satisfies all the requirements. We use \href{https://users.encs.concordia.ca/~nikolaos/pattern\_detection.html}{\textit{Pattern4J}} -as a pattern detection tool. This tool needs compiled \textit{.class} files in -order to perform analysis. Therefore, as \textit{jackson-core} is a standard -Maven project, we compile the sources using the command \textit{mvn clean -compile}. The \textit{pom.xml} of the library specifies Java 1.6 as a -build target, which is not supported by JDK 17 or above. We used JDK 11 -instead, as it is the previous LTS version. +as a pattern detection tool. This tool needs to be compiled \textit{.class} files to perform analysis. +Therefore, as \textit{jackson-core} is a standard Maven project, we compile the sources using the command mvn clean compile. +The \textit{pom.xml} of the library specifies Java 1.6 as a build target, which is not supported by JDK 17 or above. We used JDK 11 instead, as it is the previous LTS version. -An XML dump of the \textit{Pattern4j} analysis results are included in the -submission as the file \textit{analysis.xml}. +An XML dump of the \textit{Pattern4j} analysis results is included in the submission as the file \textit{analysis.xml}. \section{Structural Patterns} \subsection{TO REWRITE Singleton Pattern} -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. +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 results are false positives. +Example, \textit{com.fasterxml.jackson.core.sym.Name1} has a private package constructor and a public static final instance of it, but reading the documentation, the class represents (short) JSON string literals and is initialized by client code. \begin{lstlisting}[caption=Name1 class,language=java] public final class Name1 extends Name { @@ -190,13 +183,11 @@ public final class Name1 extends Name { \begin{description} \item[sym.Name1, JsonLocation, DefaultIndenter, - util.DefaultPrettyPrinter\$FixedSpaceIndenter] not a singleton (detected - cause of "convenient" default instance given as static final field), the - constructor is not used but the class is extensible - \item[JsonPointer, filter.TokenFilter] like above, but constructors are protected + util.DefaultPrettyPrinter\$FixedSpaceIndenter] is not a singleton (detected cause of "convenient" default instance given as static final field), the constructor is not used, but the class is extensible + \item[JsonPointer, filter.TokenFilter] is like the above, but constructors are protected \item[JsonpCharacterEscapes, util.DefaultPrettyPrinter\$NopIndenter, - Version] a singleton but with a public constructor that is never called - in the module code, may be called in tests + Version] a singleton but with a public constructor that is never called in the module code, + may be called in tests \item[io.JsonStringEncoder] like above, but the class is final \item[util.InternCache, io.CharTypes\$AltEscapes] actual singleton, thread-unsafe initialization @@ -208,44 +199,21 @@ public final class Name1 extends Name { \begin{description} \item[TokenStreamFactory] which indeed is a factory for \textbf{JsonParser} and - \textbf{JsonGenerator} objects, although two overloaded factory methods - exist on this class (one for each class) catering for different combination of - arguments. A concrete implementation of this factory is included in the form - of the \textbf{JsonFactory} class, although other modules may add additional - implementations to cater for different encodings (like the - \textit{jackson-dataformat-xml} module for XML); -\item[TSFBuilder] which is also a factory for concrete implementations of - \textbf{TokenStreamFactory} to allow slight changes in the serialization and - deserialization rules (e.g. changing the quote character used in JSON keys - from \textit{"} to \textit{'}). Like \textbf{TokenStreamFactory}, this class - is only implemented by one class, namely \textbf{JsonFactoryBuilder}, whitin - the scope of this module. And as mentioned previously, this abstract factory - is also likely to be extended by concrete implementations in other - \textit{Jackson} modules. + \textbf{JsonGenerator} is a factory for JsonParser and JsonGenerator objects, although two overloaded factory methods exist on this class (one for each class) catering to a different combination of arguments. + A concrete implementation of this factory is included in the form of the \textbf{JsonFactory} class, although other modules may add additional implementations to cater to different encodings (like the \textit{jackson-dataformat-xml} module for XML); +\item[TSFBuilder] which is also a factory for concrete implementations of \textbf{TokenStreamFactory} allows slight changes in the serialization and deserialization rules (e.g., changing the quote character used in JSON keys from " to '). Like TokenStreamFactory, this class is only implemented by one class, JsonFactoryBuilder, within this module's scope. Moreover, as mentioned previously, this abstract factory will likely be extended by concrete implementations in other Jackson modules. \end{description} \subsection{Builder Pattern} The builder pattern does not seem to be analyzed by -\textit{Pattern4J}, as the analysis output does not mention the pattern, even -just to report that no instances of it have been found (as it is the case with -other patterns, e.g. the observer pattern). A manual search in the source code -produced the following results: +\textit{Pattern4J}, as the analysis output does not mention the pattern, even to report that no instances of it have been found (as is the case with other patterns, e.g., the observer pattern). +A manual search in the source code produced the following results: \begin{description} -\item[TSFBuilder] is also a builder other than an abstract factory. As mentioned - previously, this class allows to alter slightly the serialization and - deserialization rules used to build outputtting \textbf{JsonFactory} - objects. Each rule is represented by an object or enum instance implementing - the \textbf{util.JacksonFeature} interface. \textit{TSFBuilder} then - provides several overloaded methods to enable and disable features - represented by the interface. Enabled features are stored in several - bitmask \textit{protected int} fields, which are then directly accessed by - the constructor of the \textbf{TokenStreamFactory} concrete implementation - to build; +\item[TSFBuilder] is also a builder other than an abstract factory. As mentioned previously, this class allows slightly altering the serialization and deserialization rules used to build outputting JsonFactory objects. Each rule is represented by an object or enum instance implementing the util.JacksonFeature interface. TSFBuilder then provides several overloaded methods to enable and disable features represented by the interface. Enabled features are stored in several bitmask-protected int fields, which are then directly accessed by the constructor of the TokenStreamFactory concrete implementation to build; \marginpar[right text]{\color{white}\url{https://youtu.be/72b2nH-kdbU}} -\item[JsonFactoryBuilder] an concrete factory implementation of - \textbf{TSFBuilder} that builds \textbf{JsonFactory} instances; +\item[JsonFactoryBuilder] is a concrete factory implementation of \textbf{TSFBuilder} that builds \textbf{JsonFactory} instances; \item[util.ByteArrayBuilder] provides facilities to build \textit{byte[]} objects of varying length, akin to \textbf{StringBuilder} building \textbf{String} objects. This is not a strict implementation of the builder pattern per se