You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by ds...@apache.org on 2016/03/17 18:22:32 UTC

lucene-solr:master: SOLR-8866: UpdateLog now throws an error if it can't serialize a field value

Repository: lucene-solr
Updated Branches:
  refs/heads/master c1e95d7b4 -> a22099a39


SOLR-8866: UpdateLog now throws an error if it can't serialize a field value


Project: http://git-wip-us.apache.org/repos/asf/lucene-solr/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucene-solr/commit/a22099a3
Tree: http://git-wip-us.apache.org/repos/asf/lucene-solr/tree/a22099a3
Diff: http://git-wip-us.apache.org/repos/asf/lucene-solr/diff/a22099a3

Branch: refs/heads/master
Commit: a22099a3986de1f36f926b4e106827c5308708b0
Parents: c1e95d7
Author: David Smiley <ds...@apache.org>
Authored: Thu Mar 17 13:22:16 2016 -0400
Committer: David Smiley <ds...@apache.org>
Committed: Thu Mar 17 13:22:16 2016 -0400

----------------------------------------------------------------------
 solr/CHANGES.txt                                |  3 +++
 .../org/apache/solr/update/TransactionLog.java  |  4 +++-
 .../test/org/apache/solr/update/TestUpdate.java | 21 ++++++++++++++++++++
 .../apache/solr/common/util/JavaBinCodec.java   |  4 +++-
 4 files changed, 30 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/a22099a3/solr/CHANGES.txt
----------------------------------------------------------------------
diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt
index 1be92c9..3863ceb 100644
--- a/solr/CHANGES.txt
+++ b/solr/CHANGES.txt
@@ -66,6 +66,9 @@ Other Changes
 
 * SOLR-8860: Remove back-compat handling of router format made in SOLR-4221 in 4.5.0. (shalin)
 
+* SOLR-8866: UpdateLog will now throw an exception if it doesn't know how to serialize a value.
+  (David Smiley)
+
 ==================  6.0.0 ==================
 
 Consult the LUCENE_CHANGES.txt file for additional, low level, changes in this release

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/a22099a3/solr/core/src/java/org/apache/solr/update/TransactionLog.java
----------------------------------------------------------------------
diff --git a/solr/core/src/java/org/apache/solr/update/TransactionLog.java b/solr/core/src/java/org/apache/solr/update/TransactionLog.java
index 474bcaf..673d683 100644
--- a/solr/core/src/java/org/apache/solr/update/TransactionLog.java
+++ b/solr/core/src/java/org/apache/solr/update/TransactionLog.java
@@ -95,7 +95,9 @@ public class TransactionLog implements Closeable {
         codec.writeByteArray(br.bytes, br.offset, br.length);
         return null;
       }
-      return o;
+      // Fallback: we have no idea how to serialize this.  Be noisy to prevent insidious bugs
+      throw new SolrException(SolrException.ErrorCode.SERVER_ERROR,
+          "TransactionLog doesn't know how to serialize " + o.getClass() + "; try implementing ObjectResolver?");
     }
   };
 

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/a22099a3/solr/core/src/test/org/apache/solr/update/TestUpdate.java
----------------------------------------------------------------------
diff --git a/solr/core/src/test/org/apache/solr/update/TestUpdate.java b/solr/core/src/test/org/apache/solr/update/TestUpdate.java
index 381231f..13a2479 100644
--- a/solr/core/src/test/org/apache/solr/update/TestUpdate.java
+++ b/solr/core/src/test/org/apache/solr/update/TestUpdate.java
@@ -18,9 +18,11 @@ package org.apache.solr.update;
 
 import org.apache.solr.SolrTestCaseJ4;
 import org.apache.solr.common.SolrException;
+import org.apache.solr.common.SolrInputDocument;
 import org.junit.BeforeClass;
 import org.junit.Test;
 
+import java.io.IOException;
 import java.util.concurrent.Callable;
 
 public class TestUpdate extends SolrTestCaseJ4 {
@@ -243,4 +245,23 @@ public class TestUpdate extends SolrTestCaseJ4 {
 
   }
 
+  @Test // SOLR-8866
+  public void testUpdateLogThrowsForUnknownTypes() throws IOException {
+    SolrInputDocument doc = new SolrInputDocument();
+    doc.addField("id", "444");
+    doc.addField("text", new Object());//Object shouldn't be serialized later...
+
+    AddUpdateCommand cmd = new AddUpdateCommand(req());
+    cmd.solrDoc = doc;
+    try {
+      h.getCore().getUpdateHandler().addDoc(cmd); // should throw
+    } catch (SolrException e) {
+      if (e.getMessage().contains("serialize")) {
+        return;//passed test
+      }
+      throw e;
+    }
+    fail();
+  }
+
 }

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/a22099a3/solr/solrj/src/java/org/apache/solr/common/util/JavaBinCodec.java
----------------------------------------------------------------------
diff --git a/solr/solrj/src/java/org/apache/solr/common/util/JavaBinCodec.java b/solr/solrj/src/java/org/apache/solr/common/util/JavaBinCodec.java
index 63c1b28..fe9ad08 100644
--- a/solr/solrj/src/java/org/apache/solr/common/util/JavaBinCodec.java
+++ b/solr/solrj/src/java/org/apache/solr/common/util/JavaBinCodec.java
@@ -207,7 +207,9 @@ public class JavaBinCodec {
         if (writeKnownType(tmpVal)) return;
       }
     }
-
+    // Fallback to do *something*.
+    // note: if the user of this codec doesn't want this (e.g. UpdateLog) it can supply an ObjectResolver that does
+    //  something else like throw an exception.
     writeVal(val.getClass().getName() + ':' + val.toString());
   }