diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt
index 7e67ce331c7..d1d9bfc2843 100644
--- a/solr/CHANGES.txt
+++ b/solr/CHANGES.txt
@@ -76,6 +76,14 @@ Upgrading from Solr 4.4.0
XXXXX and delete the ones that you do not wish to use. See SOLR-4953 &
SOLR-5108 for more details.
+* In the past, schema.xml parsing would silently ignore "default" or "required"
+ options specified on declarations. Begining with 4.5, attempting
+ to do configured these on a dynamic field will cause an init error. If you
+ encounter one of these errors when upgrading an existing schema.xml, you can
+ safely remove these attributes, regardless of their value, from your config and
+ Solr will continue to bahave exactly as it did in previous versions. See
+ SOLR-5227 for more details.
+
* The UniqFieldsUpdateProcessorFactory has been improved to support all of the
FieldMutatingUpdateProcessorFactory selector options. The
init param option is now deprecated and should be replaced with the more standard
@@ -201,6 +209,9 @@ Bug Fixes
* SOLR-4909: Use DirectoryReader.openIfChanged in non-NRT mode.
(Michael Garski via Robert Muir)
+* SOLR-5227: Correctly fail schema initalization if a dynamicField is configured to
+ be required, or have a default value. (hossman)
+
Optimizations
----------------------
diff --git a/solr/core/src/java/org/apache/solr/schema/IndexSchema.java b/solr/core/src/java/org/apache/solr/schema/IndexSchema.java
index 51ec4b94a14..2142a8b3539 100644
--- a/solr/core/src/java/org/apache/solr/schema/IndexSchema.java
+++ b/solr/core/src/java/org/apache/solr/schema/IndexSchema.java
@@ -674,6 +674,14 @@ public class IndexSchema {
requiredFields.add(f);
}
} else if (node.getNodeName().equals(DYNAMIC_FIELD)) {
+ if( f.getDefaultValue() != null ) {
+ throw new SolrException(ErrorCode.SERVER_ERROR,
+ DYNAMIC_FIELD + " can not have a default value: " + name);
+ }
+ if ( f.isRequired() ) {
+ throw new SolrException(ErrorCode.SERVER_ERROR,
+ DYNAMIC_FIELD + " can not be required: " + name);
+ }
if (isValidFieldGlob(name)) {
// make sure nothing else has the same path
addDynamicField(dFields, f);
diff --git a/solr/core/src/test-files/solr/collection1/conf/bad-schema-dynamicfield-default-val.xml b/solr/core/src/test-files/solr/collection1/conf/bad-schema-dynamicfield-default-val.xml
new file mode 100644
index 00000000000..0e3595d75cb
--- /dev/null
+++ b/solr/core/src/test-files/solr/collection1/conf/bad-schema-dynamicfield-default-val.xml
@@ -0,0 +1,34 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ id
+ id
+
+
diff --git a/solr/core/src/test-files/solr/collection1/conf/bad-schema-dynamicfield-required.xml b/solr/core/src/test-files/solr/collection1/conf/bad-schema-dynamicfield-required.xml
new file mode 100644
index 00000000000..c372afd44a4
--- /dev/null
+++ b/solr/core/src/test-files/solr/collection1/conf/bad-schema-dynamicfield-required.xml
@@ -0,0 +1,34 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ id
+ id
+
+
diff --git a/solr/core/src/test-files/solr/collection1/conf/schema_codec.xml b/solr/core/src/test-files/solr/collection1/conf/schema_codec.xml
index 73593829cf9..4e49dce953e 100644
--- a/solr/core/src/test-files/solr/collection1/conf/schema_codec.xml
+++ b/solr/core/src/test-files/solr/collection1/conf/schema_codec.xml
@@ -41,8 +41,8 @@
-
-
+
+
string_f
string_f
diff --git a/solr/core/src/test/org/apache/solr/schema/BadIndexSchemaTest.java b/solr/core/src/test/org/apache/solr/schema/BadIndexSchemaTest.java
index a4453ddfbc3..d5d67e69259 100644
--- a/solr/core/src/test/org/apache/solr/schema/BadIndexSchemaTest.java
+++ b/solr/core/src/test/org/apache/solr/schema/BadIndexSchemaTest.java
@@ -40,6 +40,10 @@ public class BadIndexSchemaTest extends AbstractBadConfigTestBase {
public void testSevereErrorsForDuplicateDynamicField() throws Exception {
doTest("bad-schema-dup-dynamicField.xml", "_twice");
}
+ public void testSevereErrorsForUnsupportedAttributesOnDynamicField() throws Exception {
+ doTest("bad-schema-dynamicfield-default-val.xml", "default");
+ doTest("bad-schema-dynamicfield-required.xml", "required");
+ }
public void testSevereErrorsForDuplicateFieldType() throws Exception {
doTest("bad-schema-dup-fieldType.xml", "ftAgain");