dsmiley commented on code in PR #5417:
URL: https://github.com/apache/solr/pull/5417#discussion_r4763781226


##########
solr/solrj/src/java/org/apache/solr/common/util/SimpleOrderedMap.java:
##########
@@ -89,6 +99,34 @@ public EntryWriter put(CharSequence k, Object v) throws 
IOException {
     }
   }
 
+  /**
+   * {@inheritDoc}
+   *
+   * <p>Keys are expected to be unique; see {@link #ASSERT_UNIQUE_KEYS_PROP}. 
To replace a value use
+   * {@link #put}; if repeated keys are intended, use a {@link NamedList}.
+   */
+  @Override
+  public void add(String name, T val) {
+    if (assertUniqueKeys && name != null && indexOf(name, 0) >= 0) {

Review Comment:
   Use an actual `assert` keyword so that the JVM strips this code (for 
performance) when assertions aren't enabled.



##########
gradle/testing/randomization.gradle:
##########
@@ -132,6 +132,10 @@ configure(allprojects.findAll {project -> 
project.path.startsWith(":solr")}) {
           [propName: 'solr.tests.use.numeric.points', value: null, 
description: "Point implementation to use (true=numerics, false=trie)."],
           [propName: 'tests.ssl', value: null, description: "Control SSL: 
true=force on, false=force off, unset=randomize (all respect @SuppressSSL)."],
           [propName: 'tests.selenium', value: false, description: "Enables or 
disables @SeleniumTest tests (browser-based, need a local Chrome)."],
+          [propName: 'solr.simpleOrderedMap.assertUniqueKeys',

Review Comment:
   the listing here is only for "popular" settings, thus we want convenience of 
setting them.  Most things here can be set in a more direct way if you know the 
magic sys prop.  
   The setting you are adding here definitely doesn't deserve it.



##########
solr/solrj/src/java/org/apache/solr/common/util/SimpleOrderedMap.java:
##########
@@ -47,6 +47,16 @@ public final class SimpleOrderedMap<T> extends NamedList<T> 
implements Map<Strin
 
   private static final long serialVersionUID = -8705511030983987520L;
 
+  /**
+   * System property (or env var {@code 
SOLR_SIMPLEORDEREDMAP_ASSERTUNIQUEKEYS}) that makes {@link
+   * #add} and {@link #addAll(NamedList)} fail on a key that is already 
present. Off by default; the
+   * Solr build turns it on for nightly test runs so that code relying on 
repeated keys shows up.
+   */
+  public static final String ASSERT_UNIQUE_KEYS_PROP = 
"solr.simpleOrderedMap.assertUniqueKeys";
+
+  // not final so that tests can toggle it

Review Comment:
   IMO either the entire test run will include it or it won't; let the JVM 
inline.  Ditch the tests you added (testing the test is a bit much in this case)



##########
solr/solrj/src/test/org/apache/solr/common/util/SimpleOrderedMapTest.java:
##########


Review Comment:
   IMO no tests needed -- we know there are bugs and you've found them :-)



##########
solr/solrj/src/java/org/apache/solr/common/util/SimpleOrderedMap.java:
##########
@@ -89,6 +99,34 @@ public EntryWriter put(CharSequence k, Object v) throws 
IOException {
     }
   }
 
+  /**
+   * {@inheritDoc}
+   *
+   * <p>Keys are expected to be unique; see {@link #ASSERT_UNIQUE_KEYS_PROP}. 
To replace a value use
+   * {@link #put}; if repeated keys are intended, use a {@link NamedList}.
+   */
+  @Override
+  public void add(String name, T val) {
+    if (assertUniqueKeys && name != null && indexOf(name, 0) >= 0) {
+      throw new IllegalArgumentException(
+          "SimpleOrderedMap already contains key '"
+              + name
+              + "'; keys must not repeat (use put to replace, or a NamedList 
for repeated keys)");
+    }
+    super.add(name, val);
+  }
+
+  @Override
+  public boolean addAll(NamedList<? extends T> nl) {
+    if (!assertUniqueKeys) {

Review Comment:
   al; thorough of you



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to