-
Notifications
You must be signed in to change notification settings - Fork 0
/
sosie016-gson-tojson.tex
35 lines (32 loc) · 1.9 KB
/
sosie016-gson-tojson.tex
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
Listing \ref{lst:tojson} shows a sosie of the \texttt{toJson()} method from the Google Gson library.
The last statement of the original method is replaced by another one: instead of setting the serialization format of the \texttt{writer} it set the indent format.
Each variant creates a JSon with slightly different formats, and none of these formatting decisions are part of the specified domain (and actually, specifying the exact formatting of the JSon String could be considered as over-specification).
Here, sosiefication exploits a specific kind of plasticity that we call ``code rigidities''. We have found many regions in programs where statements assign specific values to variables, while any value in a given range would be as good. Fixing one value is what we call a rigidity, and changing this value is an interesting way to create sosies that modify the program state but still deliver a correct service.
%GSon.java:601
\begin{minipage}{\columnwidth}
\begin{lstlisting}[caption={\texttt{toJson} in GSON and a sosie},label={lst:tojson},language=java,numbers=left]
// Original program
void toJson(Object src, Type typeOfSrc, JsonWriter writer){
*{\color{grey}...}*)
finally {
writer.setLenient(oldLenient);
writer.setHtmlSafe(oldHtmlSafe);
writer.setSerializeNulls(oldSerializeNulls); }}
//sosie
void toJson(Object src, Type typeOfSrc, JsonWriter writer){
finally {
writer.setLenient(oldLenient);
writer.setHtmlSafe(oldHtmlSafe);
%*{\textbf{\color{orange}statement replaced by following}}*)
writer.setIndent(" ");}}
\end{lstlisting}
\tabcolsep=0.11cm
\begin{tabular}{>{\small}c>{\small}c>{\small}c>{\small}c>{\small}c>{\small}c>{\small}c>{\small}c}
\hline
\rowcolor{lightgray} \#tc & \#assert & transfo & node & min & max & median & mean \\
\rowcolor{lightgray} & & type & type & depth & depth & depth & depth \\
\hline
& & rep & & & & & \\
\hline
\end{tabular}
\end{minipage}