Skip to content

Commit

Permalink
fixed files form Lang #32
Browse files Browse the repository at this point in the history
  • Loading branch information
tdurieux committed Mar 7, 2017
1 parent 709978e commit cb436fe
Showing 1 changed file with 17 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -101,12 +101,7 @@ public class HashCodeBuilder {
*
* @since 2.3
*/
private static final ThreadLocal<Set<IDKey>> REGISTRY = new ThreadLocal<Set<IDKey>>() {
@Override
protected Set<IDKey> initialValue() {
return new HashSet<IDKey>();
}
};
private static final ThreadLocal<Set<IDKey>> REGISTRY = new ThreadLocal<Set<IDKey>>();

/*
* N.B. we cannot store the actual objects in a HashSet, as that would use the very hashCode()
Expand Down Expand Up @@ -149,7 +144,8 @@ static Set<IDKey> getRegistry() {
* @since 2.3
*/
static boolean isRegistered(Object value) {
return getRegistry().contains(new IDKey(value));
Set<IDKey> registry = getRegistry();
return registry != null && registry.contains(new IDKey(value));
}

/**
Expand Down Expand Up @@ -519,6 +515,11 @@ public static int reflectionHashCode(Object object, String[] excludeFields) {
* The object to register.
*/
static void register(Object value) {
synchronized (HashCodeBuilder.class) {
if (getRegistry() == null) {
REGISTRY.set(new HashSet<IDKey>());
}
}
getRegistry().add(new IDKey(value));
}

Expand All @@ -535,7 +536,15 @@ static void register(Object value) {
* @since 2.3
*/
static void unregister(Object value) {
getRegistry().remove(new IDKey(value));
Set<IDKey> s = getRegistry();
if (s != null) {
s.remove(new IDKey(value));
synchronized (HashCodeBuilder.class) {
if (s.isEmpty()) {
REGISTRY.remove();
}
}
}
}

/**
Expand Down

0 comments on commit cb436fe

Please sign in to comment.