Skip to content

Commit

Permalink
Fixes spotbugs errors
Browse files Browse the repository at this point in the history
Signed-off-by: Darshit Chanpura <[email protected]>
  • Loading branch information
DarshitChanpura committed Nov 10, 2023
1 parent 11f0218 commit 2f75836
Showing 1 changed file with 11 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
Expand Down Expand Up @@ -156,7 +157,7 @@ private static void showHelp() {
*/
private static void gatherUserInputs() {
if (!assumeyes) {
try (Scanner scanner = new Scanner(System.in)) {
try (Scanner scanner = new Scanner(System.in, StandardCharsets.UTF_8)) {

if (!confirmAction(scanner, "Install demo certificates?")) {
System.exit(0);
Expand Down Expand Up @@ -319,7 +320,7 @@ private static void printVariables() {
private static void checkIfSecurityPluginIsAlreadyConfigured() {
// Check if the configuration file contains the 'plugins.security' string
if (OPENSEARCH_CONF_FILE != null && new File(OPENSEARCH_CONF_FILE).exists()) {
try (BufferedReader br = new BufferedReader(new FileReader(OPENSEARCH_CONF_FILE))) {
try (BufferedReader br = new BufferedReader(new FileReader(OPENSEARCH_CONF_FILE, StandardCharsets.UTF_8))) {
String line;
while ((line = br.readLine()) != null) {
if (line.toLowerCase().contains("plugins.security")) {
Expand Down Expand Up @@ -360,7 +361,7 @@ private static void setAdminPassword() {
} else {
File adminPasswordFile = new File(ADMIN_PASSWORD_FILE_PATH);
if (adminPasswordFile.exists() && adminPasswordFile.length() > 0) {
try (BufferedReader br = new BufferedReader(new FileReader(ADMIN_PASSWORD_FILE_PATH))) {
try (BufferedReader br = new BufferedReader(new FileReader(ADMIN_PASSWORD_FILE_PATH, StandardCharsets.UTF_8))) {
ADMIN_PASSWORD = br.readLine();
}
}
Expand Down Expand Up @@ -415,8 +416,8 @@ private static void writePasswordToInternalUsersFile(String adminPassword, Strin
Path internalUsersPath = Paths.get(internalUsersFile);

try (
BufferedReader reader = new BufferedReader(new FileReader(internalUsersFile));
BufferedWriter writer = new BufferedWriter(new FileWriter(tempFilePath.toFile()))
BufferedReader reader = new BufferedReader(new FileReader(internalUsersFile, StandardCharsets.UTF_8));
BufferedWriter writer = new BufferedWriter(new FileWriter(tempFilePath.toFile(), StandardCharsets.UTF_8))
) {
String line;
while ((line = reader.readLine()) != null) {
Expand All @@ -441,7 +442,7 @@ public static void createDemoCertificates() {
for (DemoCertificate cert : DemoCertificate.values()) {
String filePath = OPENSEARCH_CONF_DIR + File.separator + cert.getFileName();
try {
FileWriter fileWriter = new FileWriter(filePath);
FileWriter fileWriter = new FileWriter(filePath, StandardCharsets.UTF_8);
fileWriter.write(cert.getContent());
fileWriter.close();
} catch (IOException e) {
Expand All @@ -457,7 +458,7 @@ public static void createDemoCertificates() {
private static void writeSecurityConfigToOpenSearchYML() {
String securityConfig = buildSecurityConfigString();

try (FileWriter writer = new FileWriter(OPENSEARCH_CONF_FILE, true)) {
try (FileWriter writer = new FileWriter(OPENSEARCH_CONF_FILE, StandardCharsets.UTF_8, true)) {
writer.write(securityConfig);
} catch (IOException e) {
System.err.println("Exception writing security configuration to opensearch.yml.");
Expand Down Expand Up @@ -548,7 +549,7 @@ private static boolean isNodeMaxLocalStorageNodesAlreadyPresent(String filePath)
* @throws IOException if there was exception reading the file
*/
private static boolean isStringAlreadyPresentInFile(String filePath, String searchString) throws IOException {
try (BufferedReader reader = new BufferedReader(new FileReader(filePath))) {
try (BufferedReader reader = new BufferedReader(new FileReader(filePath, StandardCharsets.UTF_8))) {
String line;
while ((line = reader.readLine()) != null) {
if (line.matches(searchString)) {
Expand Down Expand Up @@ -593,7 +594,7 @@ private static void finishScriptExecution() {

// Read the last line of the security-admin script
String lastLine = "";
try (BufferedReader reader = new BufferedReader(new FileReader(securityAdminDemoScriptPath))) {
try (BufferedReader reader = new BufferedReader(new FileReader(securityAdminDemoScriptPath, StandardCharsets.UTF_8))) {
String currentLine;
while ((currentLine = reader.readLine()) != null) {
lastLine = currentLine;
Expand Down Expand Up @@ -663,7 +664,7 @@ private static void createSecurityAdminDemoScript(String securityAdminScriptPath
}

// Write securityadmin_demo script
FileWriter writer = new FileWriter(securityAdminDemoScriptPath);
FileWriter writer = new FileWriter(securityAdminDemoScriptPath, StandardCharsets.UTF_8);
for (String command : securityAdminCommands) {
writer.write(command + "\n");
}
Expand Down

0 comments on commit 2f75836

Please sign in to comment.