You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by tf...@apache.org on 2021/03/06 05:39:02 UTC

[lucene-solr] branch master updated: SOLR-15154: Close Reader used for credentials file

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

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


The following commit(s) were added to refs/heads/master by this push:
     new 03aec55  SOLR-15154: Close Reader used for credentials file
03aec55 is described below

commit 03aec55f1e28fcd9a95b29e5beaf769ca0d023c7
Author: Tomas Fernandez Lobbe <tf...@apache.org>
AuthorDate: Fri Mar 5 21:38:33 2021 -0800

    SOLR-15154: Close Reader used for credentials file
---
 .../solrj/impl/PreemptiveBasicAuthClientBuilderFactory.java   |  9 +++++----
 .../impl/PreemptiveBasicAuthClientBuilderFactoryTest.java     | 11 ++++++-----
 2 files changed, 11 insertions(+), 9 deletions(-)

diff --git a/solr/solrj/src/java/org/apache/solr/client/solrj/impl/PreemptiveBasicAuthClientBuilderFactory.java b/solr/solrj/src/java/org/apache/solr/client/solrj/impl/PreemptiveBasicAuthClientBuilderFactory.java
index 2b4f6c2..38274b8 100644
--- a/solr/solrj/src/java/org/apache/solr/client/solrj/impl/PreemptiveBasicAuthClientBuilderFactory.java
+++ b/solr/solrj/src/java/org/apache/solr/client/solrj/impl/PreemptiveBasicAuthClientBuilderFactory.java
@@ -17,10 +17,11 @@
 
 package org.apache.solr.client.solrj.impl;
 
-import java.io.FileInputStream;
+import java.io.BufferedReader;
 import java.io.IOException;
-import java.io.InputStreamReader;
 import java.nio.charset.StandardCharsets;
+import java.nio.file.Files;
+import java.nio.file.Path;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
@@ -139,8 +140,8 @@ public class PreemptiveBasicAuthClientBuilderFactory implements HttpClientBuilde
         defaultParams = new MapSolrParams(Map.of(HttpClientUtil.PROP_BASIC_AUTH_USER, ss.get(0), HttpClientUtil.PROP_BASIC_AUTH_PASS, ss.get(1)));
       } else if (configFile != null) {
         Properties defaultProps = new Properties();
-        try {
-          defaultProps.load(new InputStreamReader(new FileInputStream(configFile), StandardCharsets.UTF_8));
+        try (BufferedReader reader = Files.newBufferedReader(Path.of(configFile), StandardCharsets.UTF_8)) {
+          defaultProps.load(reader);
         } catch (IOException e) {
           throw new IllegalArgumentException("Unable to read credentials file at " + configFile, e);
         }
diff --git a/solr/solrj/src/test/org/apache/solr/client/solrj/impl/PreemptiveBasicAuthClientBuilderFactoryTest.java b/solr/solrj/src/test/org/apache/solr/client/solrj/impl/PreemptiveBasicAuthClientBuilderFactoryTest.java
index 2da0def..6a385d7 100644
--- a/solr/solrj/src/test/org/apache/solr/client/solrj/impl/PreemptiveBasicAuthClientBuilderFactoryTest.java
+++ b/solr/solrj/src/test/org/apache/solr/client/solrj/impl/PreemptiveBasicAuthClientBuilderFactoryTest.java
@@ -19,10 +19,11 @@ package org.apache.solr.client.solrj.impl;
 
 import org.apache.solr.SolrTestCase;
 
-import java.io.File;
-import java.io.FileWriter;
+import java.io.BufferedWriter;
 import java.io.IOException;
 import java.nio.charset.StandardCharsets;
+import java.nio.file.Files;
+import java.nio.file.Path;
 import java.util.Properties;
 
 public class PreemptiveBasicAuthClientBuilderFactoryTest extends SolrTestCase {
@@ -66,11 +67,11 @@ public class PreemptiveBasicAuthClientBuilderFactoryTest extends SolrTestCase {
         Properties p = new Properties();
         p.setProperty("httpBasicAuthUser", "foo");
         p.setProperty("httpBasicAuthPassword", "bar");
-        File f = createTempFile().toFile();
-        try (FileWriter fw = new FileWriter(f, StandardCharsets.UTF_8)) {
+        Path f = createTempFile();
+        try (BufferedWriter fw = Files.newBufferedWriter(f, StandardCharsets.UTF_8)) {
             p.store(fw, "tmp properties file for PreemptiveBasicAuthClientBuilderFactoryTest.testCredentialsFromConfigFile");
         }
-        System.setProperty(PreemptiveBasicAuthClientBuilderFactory.SYS_PROP_HTTP_CLIENT_CONFIG, f.getAbsolutePath());
+        System.setProperty(PreemptiveBasicAuthClientBuilderFactory.SYS_PROP_HTTP_CLIENT_CONFIG, f.toFile().getAbsolutePath());
         PreemptiveBasicAuthClientBuilderFactory.CredentialsResolver credentialsResolver = new PreemptiveBasicAuthClientBuilderFactory.CredentialsResolver();
         assertEquals("foo", credentialsResolver.defaultParams.get(HttpClientUtil.PROP_BASIC_AUTH_USER));
         assertEquals("bar", credentialsResolver.defaultParams.get(HttpClientUtil.PROP_BASIC_AUTH_PASS));