You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by ma...@apache.org on 2020/08/22 18:42:39 UTC

[lucene-solr] 20/22: @600 Some cleanup.

This is an automated email from the ASF dual-hosted git repository.

markrmiller pushed a commit to branch reference_impl
in repository https://gitbox.apache.org/repos/asf/lucene-solr.git

commit 93a0b27770f2f904b8c96728ca478f92623862b7
Author: markrmiller@gmail.com <ma...@gmail.com>
AuthorDate: Fri Aug 21 14:12:03 2020 -0500

    @600 Some cleanup.
---
 .../java/org/apache/solr/core/XmlConfigFile.java   | 25 +++++++++++++---------
 .../org/apache/solr/handler/loader/XMLLoader.java  |  9 ++++----
 .../solr/search/GraphTermsQParserPlugin.java       | 12 ++++++-----
 .../org/apache/solr/search/ValueSourceParser.java  |  6 +++---
 .../src/java/org/apache/solr/util/CryptoKeys.java  |  2 +-
 .../test/org/apache/solr/cloud/TestRSAKeyPair.java |  7 ++++++
 6 files changed, 37 insertions(+), 24 deletions(-)

diff --git a/solr/core/src/java/org/apache/solr/core/XmlConfigFile.java b/solr/core/src/java/org/apache/solr/core/XmlConfigFile.java
index b266b41e..a0d946b 100644
--- a/solr/core/src/java/org/apache/solr/core/XmlConfigFile.java
+++ b/solr/core/src/java/org/apache/solr/core/XmlConfigFile.java
@@ -71,19 +71,23 @@ public class XmlConfigFile { // formerly simply "Config"
 
   public static final XPathFactoryImpl xpathFactory = new XPathFactoryImpl();
 
-  public static final Configuration conf;
+  public static Configuration conf = null;
 
-  private static final NamePool pool ;
+  private static NamePool pool = null;
 
   static  {
-    conf = Configuration.newConfiguration();
-    conf.setValidation(false);
-    conf.setXIncludeAware(true);
-    conf.setExpandAttributeDefaults(true);
-    pool = new NamePool();
-    conf.setNamePool(pool);
-
-    xpathFactory.setConfiguration(conf);
+    try {
+      conf = Configuration.newConfiguration();
+      conf.setValidation(false);
+      conf.setXIncludeAware(true);
+      conf.setExpandAttributeDefaults(true);
+      pool = new NamePool();
+      conf.setNamePool(pool);
+
+      xpathFactory.setConfiguration(conf);
+    } catch (Exception e) {
+      log.error("", e);
+    }
   }
 
   protected final String prefix;
@@ -167,6 +171,7 @@ public class XmlConfigFile { // formerly simply "Config"
       conf2.setExpandAttributeDefaults(true);
       conf2.setNamePool(pool);
       conf2.setDocumentNumberAllocator(conf.getDocumentNumberAllocator());
+
       SolrTinyBuilder builder = new SolrTinyBuilder(conf2.makePipelineConfiguration(), substituteProps);
       builder.setStatistics(conf2.getTreeStatistics().SOURCE_DOCUMENT_STATISTICS);
 
diff --git a/solr/core/src/java/org/apache/solr/handler/loader/XMLLoader.java b/solr/core/src/java/org/apache/solr/handler/loader/XMLLoader.java
index 0719645..436a090 100644
--- a/solr/core/src/java/org/apache/solr/handler/loader/XMLLoader.java
+++ b/solr/core/src/java/org/apache/solr/handler/loader/XMLLoader.java
@@ -130,11 +130,9 @@ public class XMLLoader extends ContentStreamLoader {
 
     String tr = req.getParams().get(CommonParams.TR,null);
     if(tr!=null) {
-      if (req.getCore().getCoreDescriptor().isConfigSetTrusted() == false) {
-          throw new SolrException(ErrorCode.UNAUTHORIZED, "The configset for this collection was uploaded without any authentication in place,"
-                  + " and this operation is not available for collections with untrusted configsets. To use this feature, re-upload the configset"
-                  + " after enabling authentication and authorization.");
-      }
+      if (req.getCore().getCoreDescriptor().isConfigSetTrusted() == false) throw new SolrException(ErrorCode.UNAUTHORIZED,
+          "The configset for this collection was uploaded without any authentication in place,"
+              + " and this operation is not available for collections with untrusted configsets. To use this feature, re-upload the configset" + " after enabling authentication and authorization.");
 
       final Transformer t = getTransformer(tr,req);
 
@@ -188,6 +186,7 @@ public class XMLLoader extends ContentStreamLoader {
         parser = (XMLStreamReader2) ((charset == null) ?
                   inputFactory.createXMLStreamReader(is) : inputFactory.createXMLStreamReader(is, charset));
         parser.setProperty(XMLInputFactory.IS_SUPPORTING_EXTERNAL_ENTITIES, Boolean.TRUE);
+
         this.processUpdate(req, processor, parser);
       } catch (XMLStreamException e) {
         throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, e.getMessage(), e);
diff --git a/solr/core/src/java/org/apache/solr/search/GraphTermsQParserPlugin.java b/solr/core/src/java/org/apache/solr/search/GraphTermsQParserPlugin.java
index c66e079..24af875 100644
--- a/solr/core/src/java/org/apache/solr/search/GraphTermsQParserPlugin.java
+++ b/solr/core/src/java/org/apache/solr/search/GraphTermsQParserPlugin.java
@@ -155,7 +155,7 @@ public class GraphTermsQParserPlugin extends QParserPlugin {
     };
   }
 
-  private class GraphTermsQuery extends Query implements ExtendedQuery {
+  private static class GraphTermsQuery extends Query implements ExtendedQuery {
 
     private Term[] queryTerms;
     private String field;
@@ -216,10 +216,12 @@ public class GraphTermsQParserPlugin extends QParserPlugin {
     }
 
     public GraphTermsQuery clone() {
-      GraphTermsQuery clone = new GraphTermsQuery(this.field,
-                                                  this.queryTerms,
-                                                  this.maxDocFreq,
-                                                  this.id);
+      GraphTermsQuery clone = null;
+      try {
+        clone = (GraphTermsQuery) super.clone();
+      } catch (CloneNotSupportedException e) {
+        throw new IllegalStateException(e);
+      }
       return clone;
     }
 
diff --git a/solr/core/src/java/org/apache/solr/search/ValueSourceParser.java b/solr/core/src/java/org/apache/solr/search/ValueSourceParser.java
index 24da3a7..886fca7 100644
--- a/solr/core/src/java/org/apache/solr/search/ValueSourceParser.java
+++ b/solr/core/src/java/org/apache/solr/search/ValueSourceParser.java
@@ -569,14 +569,14 @@ public abstract class ValueSourceParser implements NamedListInitializedPlugin {
       @Override
       public ValueSource parse(FunctionQParser fp) throws SyntaxError {
         List<ValueSource> sources = fp.parseValueSourceList();
-        return new MaxFloatFunction(sources.toArray(new ValueSource[sources.size()]));
+        return new MaxFloatFunction(sources.toArray(new ValueSource[0]));
       }
     });
     addParser("min", new ValueSourceParser() {
       @Override
       public ValueSource parse(FunctionQParser fp) throws SyntaxError {
         List<ValueSource> sources = fp.parseValueSourceList();
-        return new MinFloatFunction(sources.toArray(new ValueSource[sources.size()]));
+        return new MinFloatFunction(sources.toArray(new ValueSource[0]));
       }
     });
 
@@ -862,7 +862,7 @@ public abstract class ValueSourceParser implements NamedListInitializedPlugin {
       @Override
       public ValueSource parse(FunctionQParser fp) throws SyntaxError {
         List<ValueSource> sources = fp.parseValueSourceList();
-        return new ConcatStringFunction(sources.toArray(new ValueSource[sources.size()]));
+        return new ConcatStringFunction(sources.toArray(new ValueSource[0]));
       }
     });
 
diff --git a/solr/core/src/java/org/apache/solr/util/CryptoKeys.java b/solr/core/src/java/org/apache/solr/util/CryptoKeys.java
index 9b70c6c..d452b71 100644
--- a/solr/core/src/java/org/apache/solr/util/CryptoKeys.java
+++ b/solr/core/src/java/org/apache/solr/util/CryptoKeys.java
@@ -351,7 +351,7 @@ public final class CryptoKeys {
       } catch (NoSuchAlgorithmException e) {
         throw new AssertionError("JVM spec is required to support RSA", e);
       }
-      keyGen.initialize(DEFAULT_KEYPAIR_LENGTH);
+      keyGen.initialize(Integer.getInteger("solr.keypair.keypair_length", DEFAULT_KEYPAIR_LENGTH));
       java.security.KeyPair keyPair = keyGen.genKeyPair();
       privateKey = keyPair.getPrivate();
       publicKey = keyPair.getPublic();
diff --git a/solr/core/src/test/org/apache/solr/cloud/TestRSAKeyPair.java b/solr/core/src/test/org/apache/solr/cloud/TestRSAKeyPair.java
index 3c5f793..22f56e9 100644
--- a/solr/core/src/test/org/apache/solr/cloud/TestRSAKeyPair.java
+++ b/solr/core/src/test/org/apache/solr/cloud/TestRSAKeyPair.java
@@ -18,6 +18,7 @@ package org.apache.solr.cloud;
 
 import org.apache.solr.SolrTestCase;
 import org.apache.solr.util.CryptoKeys;
+import org.junit.BeforeClass;
 import org.junit.Test;
 
 import java.net.URL;
@@ -27,6 +28,12 @@ import static org.hamcrest.CoreMatchers.equalTo;
 import static org.hamcrest.CoreMatchers.not;
 
 public class TestRSAKeyPair extends SolrTestCase {
+
+    @BeforeClass
+    public static void beforeTestRSAKeyPair() {
+        System.setProperty("solr.keypair.keypair_length", "512");
+    }
+
     @Test
     public void testGenKeyPair() throws Exception {
         testRoundTrip(new CryptoKeys.RSAKeyPair());