Back to success stories

Sample of Defect

Project Name CID Checker Category Developer Description
CalebFenton/simplify 33660 FB.HE_EQUALS_USE_HASHCODE FindBugs: Bad practice This causes a VERY subtle and annoying correctness bug since these objects are stored in a hashmap.
File: /smalivm/src/main/java/org/cf/smalivm/context/ClassState.java
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
        this.className = parent.className;
    }

    public ClassState(ClassState other, ExecutionContext ectx) {
        super(other, ectx);

        fieldNameAndTypes = new THashSet<String>(other.fieldNameAndTypes);
        className = other.className;
    }

    public void assignField(String fieldNameAndType, Object value) {
        int register = 0;
        String heapKey = getKey(fieldNameAndType);
        String type = fieldNameAndType.split(":")[1];
        assignRegister(register, new HeapItem(value, type), heapKey);
    }

    public void assignField(String fieldNameAndType, HeapItem item) {
        int register = 0;
        String heapKey = getKey(fieldNameAndType);
        assignRegister(register, item, heapKey);
    }

    @Override
 <<< CID 33660: FindBugs: Bad practice FB.HE_EQUALS_USE_HASHCODE
 <<< 1. org.cf.smalivm.context.ClassState defines equals and uses Object.hashCode().
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
    public boolean equals(Object obj) {
        if (obj == null) {
            return false;
        } else if (obj == this) {
            return true;
        } else if (obj.getClass() != getClass()) {
            return false;
        }
        ClassState other = (ClassState) obj;

        return this.toString().equals(other.toString());
    }

    public HeapItem peekField(String fieldNameAndType) {
        int register = 0;
        String heapKey = getKey(fieldNameAndType);

        HeapItem fieldItem = peekRegister(register, heapKey);
        if (fieldItem == null) {
            log.error("Undefined field: " + className + ";->" + fieldNameAndType + ". Returning unknown.");
            fieldItem = HeapItem.newUnknown(fieldNameAndType.split(":")[1]);
        }

        return fieldItem;
    }

    public void pokeField(String fieldNameAndType, Object value) {
Events:
1. defect ClassState.java:50