View Javadoc
1   import edu.umd.cs.findbugs.annotations.ExpectWarning;
2   import edu.umd.cs.findbugs.annotations.NoWarning;
3
4   abstract class AbstractMissingHashCode {
5       int x;
6
7       @Override
8       @ExpectWarning("HE_EQUALS_USE_HASHCODE")
9       public boolean equals(Object o) {
10          if (!(o instanceof AbstractMissingHashCode))
11              return false;
12          return x == ((AbstractMissingHashCode) o).x;
13      }
14
15      @ExpectWarning("HE_INHERITS_EQUALS_USE_HASHCODE")
16      static class StillMissingHashCode extends AbstractMissingHashCode {
17          int y;
18      }
19
20      static class Concrete extends StillMissingHashCode {
21          public int z;
22
23          @Override
24          @NoWarning("HE")
25          public int hashCode(){
26              return 0;
27          }
28
29          @ExpectWarning("EQ_UNUSUAL")
30          @Override
31          public boolean equals(Object o) {
32              // #303 Request for check <int var> += <double val>
33              int sum = 5;
34              sum += 4.2; // same as sum = (int)(sum + 4.2);
35              System.out.println(sum);
36              return o == this;
37          }
38      }
39
40      @ExpectWarning("EQ_DOESNT_OVERRIDE_EQUALS")
41      static class ConcreteMissingEquals extends Concrete {
42          int z;
43      }
44  }