You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@solr.apache.org by "epugh (via GitHub)" <gi...@apache.org> on 2026/07/26 11:48:03 UTC

[PR] Tidy up java code in o.a.s.common package [solr]

epugh opened a new pull request, #4669:
URL: https://github.com/apache/solr/pull/4669

   # Description
   
   Reviewing code in the org.apache.solr.common package for potential improvements.
   
   
   
   # Solution
   
   Mostly driven by what IntelliJ is suggesting are weaknesses. Specifically, lots of unused methods.   I found some gnarly extra params that don't get used in the JSON parsing stuff I'd love extra eyes on.
   
   # Tests
   
   Existing tests, plus talking to Claude for reivew.
   


-- 
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: issues-unsubscribe@solr.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@solr.apache.org
For additional commands, e-mail: issues-help@solr.apache.org


Re: [PR] Tidy up java code in o.a.s.common package [solr]

Posted by "epugh (via GitHub)" <gi...@apache.org>.
epugh commented on code in PR #4669:
URL: https://github.com/apache/solr/pull/4669#discussion_r3667686049


##########
solr/solrj/src/java/org/apache/solr/common/MapWriter.java:
##########
@@ -145,7 +144,4 @@ default BiConsumer<CharSequence, Object> getBiConsumer() {
       return this::putNoEx;
     }
   }
-
-  @Deprecated // use SimpleOrderedMap.of()
-  MapWriter EMPTY = new MapWriterMap(Map.of());
 }

Review Comment:
   I don't think anyone downstream would use it.



-- 
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: issues-unsubscribe@solr.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@solr.apache.org
For additional commands, e-mail: issues-help@solr.apache.org


Re: [PR] Tidy up java code in o.a.s.common package [solr]

Posted by "epugh (via GitHub)" <gi...@apache.org>.
epugh commented on code in PR #4669:
URL: https://github.com/apache/solr/pull/4669#discussion_r3667680521


##########
solr/solrj/src/java/org/apache/solr/common/LinkedHashMapWriter.java:
##########
@@ -20,24 +20,13 @@
 import java.io.IOException;
 import java.util.LinkedHashMap;
 import java.util.List;
-import java.util.Map;
-import org.apache.solr.common.util.SuppressForbidden;
 
 public class LinkedHashMapWriter<V> extends LinkedHashMap<String, V> implements MapWriter {
 
-  @SuppressForbidden(reason = "extends LinkedHashMap")
-  public LinkedHashMapWriter(int initialCapacity) {
-    super(initialCapacity);
-  }
-
   public LinkedHashMapWriter() {
     super();
   }

Review Comment:
   Hummm...    Maybe?   It feels like this is kind of internal, but maybe not...  Would love opinoni from someone else.



-- 
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: issues-unsubscribe@solr.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@solr.apache.org
For additional commands, e-mail: issues-help@solr.apache.org


Re: [PR] Tidy up java code in o.a.s.common package [solr]

Posted by "epugh (via GitHub)" <gi...@apache.org>.
epugh commented on code in PR #4669:
URL: https://github.com/apache/solr/pull/4669#discussion_r3667768746


##########
solr/solrj/src/java/org/apache/solr/common/SolrException.java:
##########
@@ -23,14 +23,10 @@
 import java.util.Map;
 import org.apache.solr.common.util.NamedList;
 import org.apache.solr.common.util.SimpleOrderedMap;
-import org.slf4j.Logger;
-import org.slf4j.MDC;
 
 /** */
 public class SolrException extends RuntimeException {
 
-  private final Map<String, String> mdcContext;

Review Comment:
   @psalagnac would you weigh in on this?   Is there any side effect that I don't understand why we need to set this if we never read it?   On my first pass, I left it b/c I didn't understand it.  On my second pass I decided maybe it was just dead code...  Would love your eyes.



-- 
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: issues-unsubscribe@solr.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@solr.apache.org
For additional commands, e-mail: issues-help@solr.apache.org


Re: [PR] Tidy up java code in o.a.s.common package [solr]

Posted by "epugh (via GitHub)" <gi...@apache.org>.
epugh commented on code in PR #4669:
URL: https://github.com/apache/solr/pull/4669#discussion_r3667689879


##########
solr/solrj/src/java/org/apache/solr/common/params/CommonParams.java:
##########
@@ -163,7 +159,7 @@ public interface CommonParams {
   String CPU_ALLOWED = "cpuAllowed";
 
   /**
-   * Max query memory allocation value in mebibytes (float). If not set, or the value is &lt;= 0.0,
+   * Max query memory allocation value in megabytes (float). If not set, or the value is &lt;= 0.0,
    * there is no limit.

Review Comment:
   wait, so "mebibyte" is a thing?   https://simple.wikipedia.org/wiki/Mebibyte



-- 
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: issues-unsubscribe@solr.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@solr.apache.org
For additional commands, e-mail: issues-help@solr.apache.org


Re: [PR] Tidy up java code in o.a.s.common package [solr]

Posted by "Copilot (via GitHub)" <gi...@apache.org>.
Copilot commented on code in PR #4669:
URL: https://github.com/apache/solr/pull/4669#discussion_r3652514573


##########
solr/solrj/src/java/org/apache/solr/common/SolrException.java:
##########
@@ -23,12 +23,12 @@
 import java.util.Map;
 import org.apache.solr.common.util.NamedList;
 import org.apache.solr.common.util.SimpleOrderedMap;
-import org.slf4j.Logger;
 import org.slf4j.MDC;
 
 /** */
 public class SolrException extends RuntimeException {
 
+  // Can I be removed???  TODO
   private final Map<String, String> mdcContext;

Review Comment:
   The new inline TODO comment ("Can I be removed???") is unclear/unhelpful in production code. Also, with the MDC logging helpers removed below, `mdcContext` is now only captured and stored but never read; consider either restoring a supported use (e.g., accessor) or removing the field + MDC capture to avoid overhead.



##########
solr/solrj/src/java/org/apache/solr/common/LinkedHashMapWriter.java:
##########
@@ -20,24 +20,13 @@
 import java.io.IOException;
 import java.util.LinkedHashMap;
 import java.util.List;
-import java.util.Map;
-import org.apache.solr.common.util.SuppressForbidden;
 
 public class LinkedHashMapWriter<V> extends LinkedHashMap<String, V> implements MapWriter {
 
-  @SuppressForbidden(reason = "extends LinkedHashMap")
-  public LinkedHashMapWriter(int initialCapacity) {
-    super(initialCapacity);
-  }
-
   public LinkedHashMapWriter() {
     super();
   }

Review Comment:
   The removed public constructors (`LinkedHashMapWriter(int)` and `LinkedHashMapWriter(Map)`) are part of the SolrJ surface area and their removal is a breaking change for clients. Consider restoring them as deprecated constructors to keep source/binary compatibility while still steering users to the preferred usage.



##########
solr/solrj/src/java/org/apache/solr/common/util/JsonRecordReader.java:
##########
@@ -218,13 +211,13 @@ private void buildOptimize() {
     private void build(
         List<String> paths, // a List of segments from the split paths
         String fieldName, // the fieldName assoc with this path
-        boolean multiValued, // flag if this fieldName is multiValued or not
+        // flag if this fieldName is multiValued or not
         boolean record, // is this path a record or a field
         String path) {

Review Comment:
   This method signature still contains a comment about a removed `multiValued` parameter, which is now misleading noise in the API/implementation. It should be removed or updated to reflect current behavior.



##########
solr/solrj/src/java/org/apache/solr/common/ConditionalKeyMapWriter.java:
##########
@@ -80,8 +79,4 @@ public EntryWriter put(CharSequence k, boolean v) throws IOException {
   public void writeMap(EntryWriter ew) throws IOException {
     if (delegate != null) delegate.writeMap(new EntryWriterWrapper(ew, predicate));
   }
-
-  public static Predicate<CharSequence> dedupeKeyPredicate(Set<CharSequence> keys) {
-    return (k) -> keys.add(k);
-  }
 }

Review Comment:
   The static `dedupeKeyPredicate(Set)` helper was removed. Even if unused in-tree, this is a breaking API change for SolrJ consumers. Consider restoring it as a deprecated method; callers can still migrate to `keys::add` over time.



##########
solr/solrj/src/java/org/apache/solr/common/params/CommonParams.java:
##########
@@ -163,7 +159,7 @@ public interface CommonParams {
   String CPU_ALLOWED = "cpuAllowed";
 
   /**
-   * Max query memory allocation value in mebibytes (float). If not set, or the value is &lt;= 0.0,
+   * Max query memory allocation value in megabytes (float). If not set, or the value is &lt;= 0.0,
    * there is no limit.

Review Comment:
   The MEM_ALLOWED javadoc now says the value is in "megabytes", but the enforcement code multiplies by a mebibyte constant (MiB). This mismatch can mislead users configuring limits; the doc should reflect the actual unit.



##########
solr/solrj/src/java/org/apache/solr/common/MapWriter.java:
##########
@@ -145,7 +144,4 @@ default BiConsumer<CharSequence, Object> getBiConsumer() {
       return this::putNoEx;
     }
   }
-
-  @Deprecated // use SimpleOrderedMap.of()
-  MapWriter EMPTY = new MapWriterMap(Map.of());
 }

Review Comment:
   Removing the deprecated `MapWriter.EMPTY` constant is a breaking change for any downstream code that still references it. If this is not part of a deliberate major-version cleanup, consider restoring it (still deprecated) to preserve binary compatibility.



-- 
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: issues-unsubscribe@solr.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@solr.apache.org
For additional commands, e-mail: issues-help@solr.apache.org


Re: [PR] Tidy up java code in o.a.s.common package [solr]

Posted by "epugh (via GitHub)" <gi...@apache.org>.
epugh commented on code in PR #4669:
URL: https://github.com/apache/solr/pull/4669#discussion_r3667699992


##########
solr/core/src/test/org/apache/solr/response/JSONWriterTest.java:
##########
@@ -187,10 +187,9 @@ public void testJSONSolrDocument() throws Exception {
   @Test
   public void testArrntvWriterOverridesAllWrites() {
     // List rather than Set because two not-overridden methods could share name but not signature
-    final List<String> methodsExpectedNotOverridden = new ArrayList<>(14);
+    final List<String> methodsExpectedNotOverridden = new ArrayList<>(13);

Review Comment:
   works fo rme..



-- 
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: issues-unsubscribe@solr.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@solr.apache.org
For additional commands, e-mail: issues-help@solr.apache.org


Re: [PR] Tidy up java code in o.a.s.common package [solr]

Posted by "psalagnac (via GitHub)" <gi...@apache.org>.
psalagnac commented on code in PR #4669:
URL: https://github.com/apache/solr/pull/4669#discussion_r3667997894


##########
solr/solrj/src/java/org/apache/solr/common/SolrException.java:
##########
@@ -23,14 +23,10 @@
 import java.util.Map;
 import org.apache.solr.common.util.NamedList;
 import org.apache.solr.common.util.SimpleOrderedMap;
-import org.slf4j.Logger;
-import org.slf4j.MDC;
 
 /** */
 public class SolrException extends RuntimeException {
 
-  private final Map<String, String> mdcContext;

Review Comment:
   This exception is available in SolrJ, so the only usage I image is a caller that catches it can know some details on the context.
   
   ```
   try {
      doStuff();
   } catch (SolrException e) {
     e.logInfoWithMdc(myLogger, "oh no!");
   }
   ```
   But I don't know if we set MDC context on clients, and honestly I would not rely on this.
   I don't have any concerns with removing this.



-- 
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: issues-unsubscribe@solr.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@solr.apache.org
For additional commands, e-mail: issues-help@solr.apache.org


Re: [PR] Tidy up java code in o.a.s.common package [solr]

Posted by "epugh (via GitHub)" <gi...@apache.org>.
epugh merged PR #4669:
URL: https://github.com/apache/solr/pull/4669


-- 
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: issues-unsubscribe@solr.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@solr.apache.org
For additional commands, e-mail: issues-help@solr.apache.org


Re: [PR] Tidy up java code in o.a.s.common package [solr]

Posted by "psalagnac (via GitHub)" <gi...@apache.org>.
psalagnac commented on code in PR #4669:
URL: https://github.com/apache/solr/pull/4669#discussion_r3655735050


##########
solr/solrj/src/java/org/apache/solr/common/util/JsonRecordReader.java:
##########
@@ -218,13 +211,13 @@ private void buildOptimize() {
     private void build(
         List<String> paths, // a List of segments from the split paths
         String fieldName, // the fieldName assoc with this path
-        boolean multiValued, // flag if this fieldName is multiValued or not
+        // flag if this fieldName is multiValued or not

Review Comment:
   Comment to be removed



##########
solr/core/src/test/org/apache/solr/response/JSONWriterTest.java:
##########
@@ -187,10 +187,9 @@ public void testJSONSolrDocument() throws Exception {
   @Test
   public void testArrntvWriterOverridesAllWrites() {
     // List rather than Set because two not-overridden methods could share name but not signature
-    final List<String> methodsExpectedNotOverridden = new ArrayList<>(14);
+    final List<String> methodsExpectedNotOverridden = new ArrayList<>(13);

Review Comment:
   Minor: Why not just using the default constructor here? Mostly in test code, such a micro optimization does not make sense to me.
   Plus the following lines add more than 13 items, so the array will have to grow anyway.



##########
solr/solrj/src/java/org/apache/solr/common/Callable.java:
##########
@@ -17,5 +17,5 @@
 package org.apache.solr.common;
 
 public interface Callable<T> {

Review Comment:
   I see a single internal class using this interface.
   We could remove it and replace it by Java standard `Consumer`.



-- 
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: issues-unsubscribe@solr.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@solr.apache.org
For additional commands, e-mail: issues-help@solr.apache.org


Re: [PR] Tidy up java code in o.a.s.common package [solr]

Posted by "epugh (via GitHub)" <gi...@apache.org>.
epugh commented on code in PR #4669:
URL: https://github.com/apache/solr/pull/4669#discussion_r3667682396


##########
solr/solrj/src/java/org/apache/solr/common/ConditionalKeyMapWriter.java:
##########
@@ -80,8 +79,4 @@ public EntryWriter put(CharSequence k, boolean v) throws IOException {
   public void writeMap(EntryWriter ew) throws IOException {
     if (delegate != null) delegate.writeMap(new EntryWriterWrapper(ew, predicate));
   }
-
-  public static Predicate<CharSequence> dedupeKeyPredicate(Set<CharSequence> keys) {
-    return (k) -> keys.add(k);
-  }
 }

Review Comment:
   likewise, is this really called by anyone?



-- 
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: issues-unsubscribe@solr.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@solr.apache.org
For additional commands, e-mail: issues-help@solr.apache.org


Re: [PR] Tidy up java code in o.a.s.common package [solr]

Posted by "epugh (via GitHub)" <gi...@apache.org>.
epugh commented on code in PR #4669:
URL: https://github.com/apache/solr/pull/4669#discussion_r3667759140


##########
solr/solrj/src/java/org/apache/solr/common/Callable.java:
##########
@@ -17,5 +17,5 @@
 package org.apache.solr.common;
 
 public interface Callable<T> {

Review Comment:
   I poked aroudn about your comment, and yeah, we odn' tneed to recreate Java ;-)



-- 
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: issues-unsubscribe@solr.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@solr.apache.org
For additional commands, e-mail: issues-help@solr.apache.org


Re: [PR] Tidy up java code in o.a.s.common package [solr]

Posted by "epugh (via GitHub)" <gi...@apache.org>.
epugh commented on code in PR #4669:
URL: https://github.com/apache/solr/pull/4669#discussion_r3667675059


##########
solr/solrj/src/java/org/apache/solr/common/SolrException.java:
##########
@@ -23,12 +23,12 @@
 import java.util.Map;
 import org.apache.solr.common.util.NamedList;
 import org.apache.solr.common.util.SimpleOrderedMap;
-import org.slf4j.Logger;
 import org.slf4j.MDC;
 
 /** */
 public class SolrException extends RuntimeException {
 
+  // Can I be removed???  TODO
   private final Map<String, String> mdcContext;

Review Comment:
   okay, going to remove it..



-- 
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: issues-unsubscribe@solr.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@solr.apache.org
For additional commands, e-mail: issues-help@solr.apache.org


Re: [PR] Tidy up java code in o.a.s.common package [solr]

Posted by "epugh (via GitHub)" <gi...@apache.org>.
epugh commented on code in PR #4669:
URL: https://github.com/apache/solr/pull/4669#discussion_r3667760942


##########
solr/solrj/src/java/org/apache/solr/common/util/JsonRecordReader.java:
##########
@@ -218,13 +211,13 @@ private void buildOptimize() {
     private void build(
         List<String> paths, // a List of segments from the split paths
         String fieldName, // the fieldName assoc with this path
-        boolean multiValued, // flag if this fieldName is multiValued or not
+        // flag if this fieldName is multiValued or not

Review Comment:
   great



-- 
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: issues-unsubscribe@solr.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@solr.apache.org
For additional commands, e-mail: issues-help@solr.apache.org


Re: [PR] Tidy up java code in o.a.s.common package [solr]

Posted by "epugh (via GitHub)" <gi...@apache.org>.
epugh commented on code in PR #4669:
URL: https://github.com/apache/solr/pull/4669#discussion_r3669505852


##########
solr/solrj/src/java/org/apache/solr/common/SolrException.java:
##########
@@ -23,14 +23,10 @@
 import java.util.Map;
 import org.apache.solr.common.util.NamedList;
 import org.apache.solr.common.util.SimpleOrderedMap;
-import org.slf4j.Logger;
-import org.slf4j.MDC;
 
 /** */
 public class SolrException extends RuntimeException {
 
-  private final Map<String, String> mdcContext;

Review Comment:
   thanks for explaining this, that DOES make sense.    It's one of those things, there are no tests around it, we don't use that behavior in our own SolrJ use, so it feels like it's a "YAGNI" type feature!  and that if someone DID dpeend on it, it would probably break at some point.   
   
   I will leave this PR Open for a few more days, see if there are any other opionons.
   
   Thanks.
   
   



-- 
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: issues-unsubscribe@solr.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@solr.apache.org
For additional commands, e-mail: issues-help@solr.apache.org