diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt index d00b741ff6a..b46ccfea886 100644 --- a/solr/CHANGES.txt +++ b/solr/CHANGES.txt @@ -153,6 +153,9 @@ Bug Fixes * SOLR-11656: TLOG replication doesn't work properly after rebalancing leaders. (Yuki Yano via Erick Erickson) +* SOLR-14516: Fix NPE in JSON response writer(wt=json) with /get when writing non-stored, non-indexed docvalue field + from an uncommitted document (noble, Ishan Chattopadhyaya, Munendra S N) + Other Changes --------------------- diff --git a/solr/core/src/java/org/apache/solr/schema/BoolField.java b/solr/core/src/java/org/apache/solr/schema/BoolField.java index 83b4395e020..3a4b49a7c0c 100644 --- a/solr/core/src/java/org/apache/solr/schema/BoolField.java +++ b/solr/core/src/java/org/apache/solr/schema/BoolField.java @@ -169,7 +169,7 @@ public class BoolField extends PrimitiveFieldType { @Override public void write(TextResponseWriter writer, String name, IndexableField f) throws IOException { - writer.writeBool(name, f.stringValue().charAt(0) == 'T'); + writer.writeBool(name, toObject(f)); } @Override diff --git a/solr/core/src/java/org/apache/solr/schema/FieldType.java b/solr/core/src/java/org/apache/solr/schema/FieldType.java index ee6dfdb9b16..daac8c04bad 100644 --- a/solr/core/src/java/org/apache/solr/schema/FieldType.java +++ b/solr/core/src/java/org/apache/solr/schema/FieldType.java @@ -677,6 +677,9 @@ public abstract class FieldType extends FieldProperties { /** * calls back to TextResponseWriter to write the field value + *
+ * Sub-classes should prefer using {@link #toExternal(IndexableField)} or {@link #toObject(IndexableField)}
+ * to get the writeable external value of f
instead of directly using f.stringValue()
or f.binaryValue()
*/
public abstract void write(TextResponseWriter writer, String name, IndexableField f) throws IOException;
diff --git a/solr/core/src/java/org/apache/solr/schema/PreAnalyzedField.java b/solr/core/src/java/org/apache/solr/schema/PreAnalyzedField.java
index 84265e2d97a..87a874b5b1d 100644
--- a/solr/core/src/java/org/apache/solr/schema/PreAnalyzedField.java
+++ b/solr/core/src/java/org/apache/solr/schema/PreAnalyzedField.java
@@ -149,7 +149,7 @@ public class PreAnalyzedField extends TextField implements HasImplicitIndexAnaly
@Override
public void write(TextResponseWriter writer, String name, IndexableField f)
throws IOException {
- writer.writeStr(name, f.stringValue(), true);
+ writer.writeStr(name, toExternal(f), true);
}
/** Utility method to convert a field to a string that is parse-able by this
diff --git a/solr/core/src/java/org/apache/solr/schema/StrField.java b/solr/core/src/java/org/apache/solr/schema/StrField.java
index 3413ce18a57..bd7fa06c9cf 100644
--- a/solr/core/src/java/org/apache/solr/schema/StrField.java
+++ b/solr/core/src/java/org/apache/solr/schema/StrField.java
@@ -98,7 +98,7 @@ public class StrField extends PrimitiveFieldType {
@Override
public void write(TextResponseWriter writer, String name, IndexableField f) throws IOException {
- writer.writeStr(name, f.stringValue(), true);
+ writer.writeStr(name, toExternal(f), true);
}
@Override
diff --git a/solr/core/src/java/org/apache/solr/schema/TextField.java b/solr/core/src/java/org/apache/solr/schema/TextField.java
index bddaf00c760..2e44e6741a5 100644
--- a/solr/core/src/java/org/apache/solr/schema/TextField.java
+++ b/solr/core/src/java/org/apache/solr/schema/TextField.java
@@ -139,7 +139,7 @@ public class TextField extends FieldType {
@Override
public void write(TextResponseWriter writer, String name, IndexableField f) throws IOException {
- writer.writeStr(name, f.stringValue(), true);
+ writer.writeStr(name, toExternal(f), true);
}
@Override
diff --git a/solr/core/src/java/org/apache/solr/schema/UUIDField.java b/solr/core/src/java/org/apache/solr/schema/UUIDField.java
index 00495c97755..aa04b0dd21d 100644
--- a/solr/core/src/java/org/apache/solr/schema/UUIDField.java
+++ b/solr/core/src/java/org/apache/solr/schema/UUIDField.java
@@ -65,7 +65,7 @@ public class UUIDField extends StrField {
@Override
public void write(TextResponseWriter writer, String name, IndexableField f)
throws IOException {
- writer.writeStr(name, f.stringValue(), false);
+ writer.writeStr(name, toExternal(f), false);
}
/**
@@ -99,7 +99,7 @@ public class UUIDField extends StrField {
@Override
public UUID toObject(IndexableField f) {
- return UUID.fromString(f.stringValue());
+ return UUID.fromString(toExternal(f));
}
@Override
diff --git a/solr/core/src/test-files/solr/collection1/conf/schema_latest.xml b/solr/core/src/test-files/solr/collection1/conf/schema_latest.xml
index af445bc67ed..18cfedc780a 100644
--- a/solr/core/src/test-files/solr/collection1/conf/schema_latest.xml
+++ b/solr/core/src/test-files/solr/collection1/conf/schema_latest.xml
@@ -260,6 +260,10 @@