Could fields.get(k) be null ? If so, defensive coding would use fields.isNull() first to check.