- if (executionMap.containsKey(var)) {
- // Subsequent accesses to the variable
- VarChange current = executionMap.get(var);
- if (current.writer != writer) {
- // Conflict is declared when:
- // 1) Current writer != previous writer, e.g., App1 vs. App2
- // 2) Current value != previous value, e.g., "locked" vs. "unlocked"
- if (!current.value.equals(value)) {
-
- String msg = "Conflict between apps " + current.writer + " and " +
- writer + " for variable " + var;
- Instruction nextIns = ti.createAndThrowException("java.lang.RuntimeException", msg);
- ti.setNextPC(nextIns);
- }
- } else {
- // No conflict is declared if this variable is accessed subsequently by the same writer
- current.writer = writer;
- current.value = value;
- }
- } else {
- // First access to the variable
- VarChange change = new VarChange(writer, value);
- executionMap.put(var, change);
- }
+ // Check and throw error if conflict is detected
+ checkWriteMapAndThrowError(var, value, writer, ti);
+ }
+ }
+ }
+
+ // CASE #2: Detecting global variable location.mode write-after-write conflict
+ if (trackLocationVar) {
+ MethodInfo mi = executedInsn.getMethodInfo();
+ // Find the last load before return and get the value here
+ if (mi.getName().equals(SET_LOCATION_METHOD) &&
+ executedInsn instanceof ALOAD && nextInsn instanceof ARETURN) {
+ byte type = getType(ti, executedInsn);
+ String value = getValue(ti, executedInsn, type);
+
+ // Extract the writer app name
+ ClassInfo ci = mi.getClassInfo();
+ String writer = ci.getName();
+
+ // Check and throw error if conflict is detected
+ checkWriteMapAndThrowError(LOCATION_VAR, value, writer, ti);
+ }
+ }
+ }
+
+ private void checkWriteMapAndThrowError(String var, String value, String writer, ThreadInfo ti) {
+
+ if (writeMap.containsKey(var)) {
+ // Subsequent writes to the variable
+ VarChange current = writeMap.get(var);
+ if (current.writer != writer) {
+ // Conflict is declared when:
+ // 1) Current writer != previous writer, e.g., App1 vs. App2
+ // 2) Current value != previous value, e.g., "locked" vs. "unlocked"
+ if (!current.value.equals(value)) {
+
+ StringBuilder sb = new StringBuilder();
+ sb.append("Conflict between apps " + current.writer + " and " + writer + ": ");
+ sb.append(writer + " has attempted to write the value " + value + " into ");
+ sb.append("variable " + var + " that had already had the value " + current.value);
+ sb.append(" previously written by " + current.writer);
+ Instruction nextIns = ti.createAndThrowException("java.lang.RuntimeException", sb.toString());
+ ti.setNextPC(nextIns);