diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt index 613908c58fd..87490d92921 100644 --- a/solr/CHANGES.txt +++ b/solr/CHANGES.txt @@ -105,6 +105,9 @@ Bug Fixes * SOLR-5216: Document updates to SolrCloud can cause a distributed deadlock. (Mark Miller) + +* SOLR-5367: Unmarshalling delete by id commands with JavaBin can lead to class cast + exception. (Mark Miller) Optimizations ---------------------- diff --git a/solr/solrj/src/java/org/apache/solr/client/solrj/request/JavaBinUpdateRequestCodec.java b/solr/solrj/src/java/org/apache/solr/client/solrj/request/JavaBinUpdateRequestCodec.java index 1de906f3547..5998eeccb80 100644 --- a/solr/solrj/src/java/org/apache/solr/client/solrj/request/JavaBinUpdateRequestCodec.java +++ b/solr/solrj/src/java/org/apache/solr/client/solrj/request/JavaBinUpdateRequestCodec.java @@ -94,7 +94,7 @@ public class JavaBinUpdateRequestCodec { List> doclist; Map> docMap; List delById; - Map delByIdMap; + Map> delByIdMap; List delByQ; final NamedList[] namedList = new NamedList[1]; JavaBinCodec codec = new JavaBinCodec() { @@ -166,7 +166,7 @@ public class JavaBinUpdateRequestCodec { } } delById = (List) namedList[0].get("delById"); - delByIdMap = (Map) namedList[0].get("delByIdMap"); + delByIdMap = (Map>) namedList[0].get("delByIdMap"); delByQ = (List) namedList[0].get("delByQ"); doclist = (List) namedList[0].get("docs"); docMap = (Map>) namedList[0].get("docsMap"); @@ -201,8 +201,15 @@ public class JavaBinUpdateRequestCodec { } } if (delByIdMap != null) { - for (Map.Entry entry : delByIdMap.entrySet()) { - updateRequest.deleteById(entry.getKey(), entry.getValue()); + for (Map.Entry> entry : delByIdMap.entrySet()) { + Map params = entry.getValue(); + if (params != null) { + Long version = (Long) params.get("ver"); + updateRequest.deleteById(entry.getKey(), version); + } else { + updateRequest.deleteById(entry.getKey()); + } + } } if (delByQ != null) { diff --git a/solr/solrj/src/java/org/apache/solr/client/solrj/request/UpdateRequest.java b/solr/solrj/src/java/org/apache/solr/client/solrj/request/UpdateRequest.java index 7898079127e..32d0fb1e2e4 100644 --- a/solr/solrj/src/java/org/apache/solr/client/solrj/request/UpdateRequest.java +++ b/solr/solrj/src/java/org/apache/solr/client/solrj/request/UpdateRequest.java @@ -47,6 +47,7 @@ import org.apache.solr.common.util.XML; */ public class UpdateRequest extends AbstractUpdateRequest { + private static final String VER = "ver"; public static final String OVERWRITE = "ow"; public static final String COMMIT_WITHIN = "cw"; private Map> documents = null; @@ -148,7 +149,7 @@ public class UpdateRequest extends AbstractUpdateRequest { deleteById = new LinkedHashMap>(); } Map params = new HashMap(1); - params.put("ver", version); + params.put(VER, version); deleteById.put(id, params); return this; } @@ -224,7 +225,7 @@ public class UpdateRequest extends AbstractUpdateRequest { Map map = entry.getValue(); Long version = null; if (map != null) { - version = (Long) map.get("ver"); + version = (Long) map.get(VER); } Slice slice = router.getTargetSlice(deleteId, null, null, col); if (slice == null) { @@ -371,7 +372,7 @@ public class UpdateRequest extends AbstractUpdateRequest { writer.append(" map = entry.getValue(); if (map != null) { - Long version = (Long) map.get("ver"); + Long version = (Long) map.get(VER); if (version != null) { writer.append(" version=\"" + version + "\""); }