Skip to content

Commit

Permalink
Merge pull request #6872 from NotedSalmon/FISH-9196-spot-bugs-default…
Browse files Browse the repository at this point in the history
…-encoding

FISH-9196 spot bugs default encoding
  • Loading branch information
NotedSalmon authored Aug 9, 2024
2 parents 54138a4 + a4c1330 commit 70741d4
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
*
* Copyright (c) 2017 Payara Foundation and/or its affiliates. All rights reserved.
* Copyright (c) [2017-2024] Payara Foundation and/or its affiliates. All rights reserved.
*
* The contents of this file are subject to the terms of either the GNU
* General Public License Version 2 only ("GPL") or the Common Development
Expand Down Expand Up @@ -44,6 +44,7 @@
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.PrintStream;
import java.nio.charset.StandardCharsets;

import com.sun.enterprise.util.io.FileUtils;
import org.glassfish.api.admin.CommandException;
Expand Down Expand Up @@ -84,7 +85,7 @@ protected DBControl(final String dbCommand, final String dbHost, final String db
}

// Redirect stdout and stderr to a file
try (PrintStream printStream = new PrintStream(new FileOutputStream(dbLog, true), true)) {
try (PrintStream printStream = new PrintStream(new FileOutputStream(dbLog, true), false, StandardCharsets.UTF_8)) {
System.setOut(printStream);
System.setErr(printStream);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
import com.sun.enterprise.util.io.FileUtils;
import fish.payara.admin.launcher.PayaraDefaultJvmOptions;
import java.io.*;
import java.nio.charset.StandardCharsets;
import java.util.*;
import java.util.logging.Level;
import java.util.regex.Matcher;
Expand Down Expand Up @@ -608,7 +609,7 @@ private void writeSecurityTokens(Process sp) throws GFLauncherException, IOExcep
OutputStreamWriter osw = null;
BufferedWriter bw = null;
try {
osw = new OutputStreamWriter(os);
osw = new OutputStreamWriter(os, StandardCharsets.UTF_8);
bw = new BufferedWriter(osw);
for (String token : info.securityTokens) {
bw.write(token);
Expand Down Expand Up @@ -910,7 +911,7 @@ private Optional<JDK.Version> getConfiguredJdkVersion(String javaExePath) throws
Runtime r = Runtime.getRuntime();
Process p = r.exec(javaExePath + " -version");
p.waitFor();
try (BufferedReader b = new BufferedReader(new InputStreamReader(p.getErrorStream()))) {
try (BufferedReader b = new BufferedReader(new InputStreamReader(p.getErrorStream(), StandardCharsets.UTF_8))) {
String line;
while ((line = b.readLine()) != null) {
Matcher m = JAVA_VERSION_PATTERN.matcher(line);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
* only if the new code is made subject to such option by the copyright
* holder.
*/
// Portions Copyright [2017-2018] [Payara Foundation and/or its affiliates]
// Portions Copyright [2017-2024] [Payara Foundation and/or its affiliates]

package com.sun.enterprise.admin.remote;

Expand Down Expand Up @@ -931,8 +931,8 @@ private void doHttpCommand(String uriString, String httpMethod,
} catch (Exception e) {
logger.log(Level.FINER, "doHttpCommand: exception", e);
ByteArrayOutputStream buf = new ByteArrayOutputStream();
e.printStackTrace(new PrintStream(buf));
logger.finer(buf.toString());
e.printStackTrace(new PrintStream(buf, false, UTF_8));
logger.finer(buf.toString(UTF_8));
throw new CommandException(e);
}
} while (shouldTryCommandAgain);
Expand Down Expand Up @@ -1123,7 +1123,7 @@ private StringBuilder addPasswordOption(StringBuilder uriString, String name, St
passwordOptions
.append(name)
.append('=')
.append(URLEncoder.encode(new String(Base64.getMimeEncoder().encode(option.getBytes()), UTF_8), "UTF-8"));
.append(URLEncoder.encode(new String(Base64.getMimeEncoder().encode(option.getBytes(UTF_8)), UTF_8), "UTF-8"));

return uriString;
}
Expand Down Expand Up @@ -1341,7 +1341,7 @@ private CommandModel parseMetadata(InputStream in, StringBuilder errors) {
FileUtils.copy(in, baos, 0);
} catch (IOException ex) { }
in = new ByteArrayInputStream(baos.toByteArray());
String response = baos.toString();
String response = baos.toString(UTF_8);
logger.finer("------- RAW METADATA RESPONSE ---------");
logger.finer(response);
logger.finer("------- RAW METADATA RESPONSE ---------");
Expand Down

0 comments on commit 70741d4

Please sign in to comment.