protect ImmutableOpenMap builder from using the built map after build has been called

This commit is contained in:
Shay Banon 2013-11-01 20:53:24 +01:00
parent 633e781204
commit f720531328
1 changed files with 3 additions and 1 deletions

View File

@ -137,7 +137,7 @@ public final class ImmutableOpenMap<KType, VType> implements Iterable<ObjectObje
public static class Builder<KType, VType> implements ObjectObjectMap<KType, VType> {
private final ObjectObjectOpenHashMap<KType, VType> map;
private ObjectObjectOpenHashMap<KType, VType> map;
public Builder() {
//noinspection unchecked
@ -152,6 +152,8 @@ public final class ImmutableOpenMap<KType, VType> implements Iterable<ObjectObje
* Builds a new instance of the
*/
public ImmutableOpenMap<KType, VType> build() {
ObjectObjectOpenHashMap<KType, VType> map = this.map;
this.map = null; // nullify the map, so any operation post build will fail! (hackish, but safest)
return new ImmutableOpenMap<KType, VType>(map);
}