There is an inner class SynchronizedCollection - inside java.util.Collections with two constructors. the first takes a collection, and the other takes a collection and a mutex. the former constructor checks the argument for being non-zero. but later do not !. here is the implementation.
SynchronizedCollection(Collection<E> c) { if (c==null) throw new NullPointerException(); this.c = c; mutex = this; } SynchronizedCollection(Collection<E> c, Object mutex) { this.c = c; this.mutex = mutex; }
with this implementation, I can break the class invariant by sending a zero per second constructor.
I believe this should be something like this:
SynchronizedCollection(Collection<E> c) { this(c,this) } SynchronizedCollection(Collection<E> c, Object mutex) { if (c==null) throw new NullPointerException(); this.c = c; this.mutex = mutex; }
however, I cannot convince myself that Josh Bloch and Neil Gufter could not see it. so can you really tell me what i missed here?
edited: possible attack
Map<String, String> m = new Map<String, String>(){ @Override public int size() {
java collections
Morteza adi
source share