You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by dw...@apache.org on 2021/03/10 09:53:55 UTC

[lucene] 41/45: SOLR-15154: Close Reader used for credentials file

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

dweiss pushed a commit to branch branch_8x
in repository https://gitbox.apache.org/repos/asf/lucene.git

commit d4241a9ceea8c44b61aa035c296c0b9c5075e376
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 26d3298..17c54a8 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.Optional;
@@ -146,8 +147,8 @@ public class PreemptiveBasicAuthClientBuilderFactory implements HttpClientBuilde
         defaultParams = new MapSolrParams(map);
       } 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 ba3df09..bdce5c0 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
@@ -17,14 +17,15 @@
 
 package org.apache.solr.client.solrj.impl;
 
+import org.apache.solr.SolrTestCase;
+
 import java.io.BufferedWriter;
-import java.io.File;
 import java.io.IOException;
 import java.nio.charset.StandardCharsets;
 import java.nio.file.Files;
+import java.nio.file.Path;
 import java.util.Properties;
 
-import org.apache.solr.SolrTestCase;
 
 public class PreemptiveBasicAuthClientBuilderFactoryTest extends SolrTestCase {
 
@@ -67,11 +68,11 @@ public class PreemptiveBasicAuthClientBuilderFactoryTest extends SolrTestCase {
         Properties p = new Properties();
         p.setProperty("httpBasicAuthUser", "foo");
         p.setProperty("httpBasicAuthPassword", "bar");
-        File f = createTempFile().toFile();
-        try (BufferedWriter fw = Files.newBufferedWriter(f.toPath(), 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));