Recently I participated in an interview for a Russian company in Moskow and could not answer some of the simple questions. One of them I would like to ask here.
List all problems which you can see in the following code:
public abstract class Digest {
private Map<byte[], byte[]> cache = new HashMap<byte[], byte[]>();
public byte[] digest(byte[] input) {
byte[] result = cache.get(input);
if (result == null) {
synchronized (cache) {
result = cache.get(input);
if (result == null) {
result = doDigest(input);
cache.put(input, result);
}
}
}
return result;
}
protected abstract byte[] doDigest(byte[] input);
}