1
1
package com .comphenix .protocol .injector .packet ;
2
2
3
+ import static com .google .common .base .Preconditions .checkNotNull ;
4
+
3
5
import java .lang .reflect .Field ;
4
6
5
7
import com .comphenix .protocol .reflect .FieldUtils ;
10
12
*/
11
13
public class MapContainer {
12
14
// For detecting changes
13
- private Field modCountField ;
15
+ private final Field modCountField ;
14
16
private int lastModCount ;
15
17
16
18
// The object along with whether or not this is the initial run
17
- private Object source ;
19
+ private final Object source ;
18
20
private boolean changed ;
19
21
20
22
public MapContainer (Object source ) {
21
23
this .source = source ;
22
- this .changed = true ;
23
- this .modCountField = FieldUtils .getField (source .getClass (), "modCount" , true );
24
+ this .changed = false ;
25
+
26
+ Field modCountField = FieldUtils .getField (source .getClass (), "modCount" , true );
27
+ this .modCountField = checkNotNull (modCountField , "Failed to obtain modCount field" );
28
+ this .lastModCount = getModificationCount ();
24
29
}
25
30
26
31
/**
@@ -55,13 +60,13 @@ protected void checkChanged() {
55
60
56
61
/**
57
62
* Retrieve the current modification count.
58
- * @return The current count, or something different than lastModCount if not accessible.
63
+ * @return The current count
59
64
*/
60
65
private int getModificationCount () {
61
66
try {
62
- return modCountField != null ? modCountField .getInt (source ) : lastModCount + 1 ;
63
- } catch (Exception e ) {
64
- throw new RuntimeException ("Unable to retrieve modCount." , e );
67
+ return modCountField .getInt (source );
68
+ } catch (Exception ex ) {
69
+ throw new RuntimeException ("Unable to retrieve modCount." , ex );
65
70
}
66
71
}
67
72
}
0 commit comments