Introduction

Developers may have a hard time to learn from past failures or bugs in the application due to team autonomy, constant pressure to deliver and a heavily distributed code base. How can they achieve that past errors are avoided in future development activities?

Neal Ford, Rebecca Parsons and Patrick Kua are proposing fitness functions that check for certain qualities in software applications in their book "Building Evolutionary Architectures: Support Constant Change". Also, Neal is speaking particular

In this notebook, I take this idea to show you a possible implementation of fitness functions using Jupyter notebooks!

(Made up) Context

In the recent stress test of our application GlugiZP2000, we had severe issues with data quality and program failures. After an initial inspection of our code review team, we found several spot in the application that can lead to race conditions.

Race conditions are bad because they lead to weird behavior in multi-user applications. Wikipedia defines Race Conditions as follows:

A race condition or race hazard is the behavior of an electronics, software, or other system where the output is dependent on the sequence or timing of other uncontrollable events. It becomes a bug when events do not happen in the order the programmer intended.

Idea

Some of the occurred race conditions could be statically identified by our software expert John Doe. In the following analysis, we use jQAssistant and the Neo4j graph database to spot even more possible problems with the help of structural code analysis. For this, we read in the complete Java code of GlugiZP2000 into the Neo4j database.

Analysis

With the following Cypher queries, we can spot some kind of race conditions that are declared public and not static fields and are written by some methods.


In [1]:
%load_ext cypher

In [2]:
%%cypher
MATCH (c:Class)-[:DECLARES]->(f:Field)<-[w:WRITES]-(m:Method)
WHERE 
    EXISTS(f.static) AND NOT EXISTS(f.final)
RETURN 
    c.name as InClass, 
    m.name as theMethod, 
    w.lineNumber as writesInLine, 
    f.name as toStaticField


3 rows affected.
Out[2]:
InClass theMethod writesInLine toStaticField
OwnerController processFindForm 112 ownersIndexes
OwnerController processFindForm 112 ownersIndexes
BrokenSingleton getInstance 11 INSTANCE

Conclusion

There are some possible race conditions regarding static, written Java field references. Our suggestion is to fix these immediately.