private int silentAdd(R record) { if (record == null) { throw new NullPointerException("Record is null passed into add() to store"); } Long id = record.getRecordId(); if (id == null) { id = ID_GENERATOR.next(); try { record.setRecordId(id); } catch (Exception e) { // this can't happen if we have exclusive access to the object (2 threads?) } } R existing = data.get(id); if (existing != null) { throw new RuntimeException("The store already contains this"); } // add it to our internal memory int index = data.add(id, record); // listen for change events. (null safe version) record.onChange().addObserver(this.onValueChanged); return index; }