diff --git a/nucleus/admin/server-mgmt/src/main/java/com/sun/enterprise/admin/servermgmt/cli/LocalServerCommand.java b/nucleus/admin/server-mgmt/src/main/java/com/sun/enterprise/admin/servermgmt/cli/LocalServerCommand.java index 6899b78ae68..5ae5273f0d2 100644 --- a/nucleus/admin/server-mgmt/src/main/java/com/sun/enterprise/admin/servermgmt/cli/LocalServerCommand.java +++ b/nucleus/admin/server-mgmt/src/main/java/com/sun/enterprise/admin/servermgmt/cli/LocalServerCommand.java @@ -37,7 +37,7 @@ * only if the new code is made subject to such option by the copyright * holder. */ -// Portions Copyright [2016-2023] [Payara Foundation and/or affiliates] +// Portions Copyright [2016-2024] [Payara Foundation and/or affiliates] package com.sun.enterprise.admin.servermgmt.cli; @@ -50,6 +50,7 @@ import com.sun.enterprise.universal.i18n.LocalStringsImpl; import com.sun.enterprise.universal.io.SmartFile; import com.sun.enterprise.universal.process.Jps; +import com.sun.enterprise.universal.process.ProcessState; import com.sun.enterprise.universal.process.ProcessUtils; import com.sun.enterprise.universal.xml.MiniXmlParser; import com.sun.enterprise.universal.xml.MiniXmlParserException; @@ -386,12 +387,12 @@ protected boolean isRunning() { return isRunningByCheckingForPidFile(); } - Boolean b = ProcessUtils.isProcessRunning(pp); + ProcessState b = ProcessUtils.getProcessRunningState(pp); - if (b == null) { // this means it couldn't find out! + if (b == ProcessState.ERROR) { // this means it couldn't find out! return isRunningUsingJps(); } else { - return b; + return b == ProcessState.RUNNING; } } diff --git a/nucleus/admin/server-mgmt/src/main/java/com/sun/enterprise/admin/servermgmt/cli/StartServerHelper.java b/nucleus/admin/server-mgmt/src/main/java/com/sun/enterprise/admin/servermgmt/cli/StartServerHelper.java index 3d779fa1a24..efa69bbfc3a 100644 --- a/nucleus/admin/server-mgmt/src/main/java/com/sun/enterprise/admin/servermgmt/cli/StartServerHelper.java +++ b/nucleus/admin/server-mgmt/src/main/java/com/sun/enterprise/admin/servermgmt/cli/StartServerHelper.java @@ -37,7 +37,7 @@ * only if the new code is made subject to such option by the copyright * holder. */ -// Portions Copyright [2017-2023] Payara Foundation and/or Affiliates +// Portions Copyright [2017-2024] Payara Foundation and/or Affiliates package com.sun.enterprise.admin.servermgmt.cli; @@ -59,6 +59,8 @@ import java.util.logging.Logger; import java.util.stream.Collectors; + +import com.sun.enterprise.universal.process.ProcessState; import org.glassfish.api.admin.CommandException; import com.sun.enterprise.admin.cli.CLIConstants; @@ -387,18 +389,18 @@ private void waitForParentDeath(int pid) throws CommandException { long start = System.currentTimeMillis(); try { do { - Boolean b = ProcessUtils.isProcessRunning(pid); - if (b == null) { + ProcessState b = ProcessUtils.getProcessRunningState(pid); + if (b == ProcessState.ERROR) { // this means we were unable to find out from the OS if the process // is running or not - debugMessage("ProcessUtils.isProcessRunning(" + pid + ") " + debugMessage("ProcessUtils.getProcessRunningState(" + pid + ") " + "returned null which means we can't get process " + "info on this platform."); new ParentDeathWaiterPureJava(); return; } - if (!b) { + if (b == ProcessState.STOPPED) { debugMessage("Parent process (" + pid + ") is dead."); return; } diff --git a/nucleus/common/common-util/src/main/java/com/sun/appserv/management/client/prefs/MemoryHashLoginInfoStore.java b/nucleus/common/common-util/src/main/java/com/sun/appserv/management/client/prefs/MemoryHashLoginInfoStore.java index 7ed9c237c43..89dbc058d92 100644 --- a/nucleus/common/common-util/src/main/java/com/sun/appserv/management/client/prefs/MemoryHashLoginInfoStore.java +++ b/nucleus/common/common-util/src/main/java/com/sun/appserv/management/client/prefs/MemoryHashLoginInfoStore.java @@ -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.appserv.management.client.prefs; @@ -48,6 +48,7 @@ import java.io.*; import java.net.URI; import java.net.URISyntaxException; +import java.nio.charset.StandardCharsets; import java.util.*; /** A {@link LoginInfoStore} that reads the information from the default file ".gfclient/pass" @@ -76,13 +77,13 @@ public MemoryHashLoginInfoStore() throws StoreException { store = new File(dir, DEFAULT_STORE_NAME); if (store.createNewFile()) { - try (BufferedWriter bw = new BufferedWriter(new FileWriter(store))) { + try (BufferedWriter bw = new BufferedWriter(new FileWriter(store, StandardCharsets.UTF_8))) { FileMapTransform.writePreamble(bw); } state = new HashMap<> (); } else { - try (BufferedReader br = new BufferedReader(new FileReader(store))) { + try (BufferedReader br = new BufferedReader(new FileReader(store, StandardCharsets.UTF_8))) { state = FileMapTransform.readAll(br); } } @@ -149,12 +150,12 @@ public String getName() { ///// PRIVATE METHODS ///// private void commit(final HostPortKey key, LoginInfo old) { - try (BufferedWriter writer = new BufferedWriter(new FileWriter(store))) { + try (BufferedWriter writer = new BufferedWriter(new FileWriter(store, StandardCharsets.UTF_8))) { FileMapTransform.writeAll(state.values(), writer); } catch(final Exception e) { state.put(key, old); //try to roll back, first memory if (old != null) { - try (BufferedWriter writer = new BufferedWriter(new FileWriter(store))) { // then disk, if the old value is not null + try (BufferedWriter writer = new BufferedWriter(new FileWriter(store, StandardCharsets.UTF_8))) { // then disk, if the old value is not null FileMapTransform.writeAll(state.values(), writer); } catch (final Exception ae) { throw new RuntimeException("catastrophe, can't write it to file"); diff --git a/nucleus/common/common-util/src/main/java/com/sun/appserv/server/util/Version.java b/nucleus/common/common-util/src/main/java/com/sun/appserv/server/util/Version.java index f28ae461aa1..8b3e4648ad9 100644 --- a/nucleus/common/common-util/src/main/java/com/sun/appserv/server/util/Version.java +++ b/nucleus/common/common-util/src/main/java/com/sun/appserv/server/util/Version.java @@ -46,6 +46,7 @@ import java.io.FileFilter; import java.io.FileReader; import java.io.IOException; +import java.nio.charset.StandardCharsets; import java.util.*; import java.util.stream.Collectors; @@ -89,7 +90,7 @@ public boolean accept(File f) { })) { FileReader fr = null; try { - fr = new FileReader(f); + fr = new FileReader(f, StandardCharsets.UTF_8); Properties p = new Properties(); p.load(fr); VERSION_PROPS.add(p); diff --git a/nucleus/common/common-util/src/main/java/com/sun/common/util/logging/GFLogRecord.java b/nucleus/common/common-util/src/main/java/com/sun/common/util/logging/GFLogRecord.java index 0e985015f23..a08bd84dda0 100644 --- a/nucleus/common/common-util/src/main/java/com/sun/common/util/logging/GFLogRecord.java +++ b/nucleus/common/common-util/src/main/java/com/sun/common/util/logging/GFLogRecord.java @@ -38,10 +38,11 @@ * holder. */ -// Portions Copyright [2016-2021] [Payara Foundation and/or its affiliates] +// Portions Copyright [2016-2024] [Payara Foundation and/or its affiliates] package com.sun.common.util.logging; +import java.util.concurrent.atomic.AtomicBoolean; import java.util.logging.Level; import java.util.logging.LogManager; import java.util.logging.LogRecord; @@ -53,8 +54,16 @@ public class GFLogRecord extends LogRecord { private static final String FAST_LOGGER_PROPERTY = "com.sun.enterprise.server.logging.GFFileHandler.fastLogging"; + /** + * The deprecated fastLogging attribute + * + * DO NOT USE! Retained for semantic versioning. Replaced by {@link GFLogRecord#fastLoggingAtomic}. + */ + @Deprecated(forRemoval = true, since = "6.21.0") public static Boolean fastLogging = Boolean.parseBoolean(LogManager.getLogManager().getProperty(FAST_LOGGER_PROPERTY)); + public static final AtomicBoolean fastLoggingAtomic = new AtomicBoolean(Boolean.parseBoolean(LogManager.getLogManager().getProperty(FAST_LOGGER_PROPERTY))); + /** * SVUID for serialization compatibility */ @@ -131,7 +140,7 @@ private static Object[] transformParameters(Object[] params) { if (params == null) { return null; } - if (fastLogging) { + if (fastLoggingAtomic.get()) { return params; } Object[] result = new Object[params.length * 2]; diff --git a/nucleus/common/common-util/src/main/java/com/sun/common/util/logging/LoggingOutputStream.java b/nucleus/common/common-util/src/main/java/com/sun/common/util/logging/LoggingOutputStream.java index ab03ac60475..e683907634a 100644 --- a/nucleus/common/common-util/src/main/java/com/sun/common/util/logging/LoggingOutputStream.java +++ b/nucleus/common/common-util/src/main/java/com/sun/common/util/logging/LoggingOutputStream.java @@ -37,13 +37,14 @@ * only if the new code is made subject to such option by the copyright * holder. */ -// Portions Copyright [2016-2019] [Payara Foundation and/or affiliates] +// Portions Copyright [2016-2024] [Payara Foundation and/or affiliates] package com.sun.common.util.logging; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.InterruptedIOException; import java.io.PrintStream; +import java.nio.charset.StandardCharsets; import java.util.*; import java.util.concurrent.ArrayBlockingQueue; import java.util.concurrent.BlockingQueue; @@ -101,7 +102,7 @@ public void flush() throws IOException { String logMessage = null; synchronized (this) { super.flush(); - logMessage = this.toString(); + logMessage = this.toString(StandardCharsets.UTF_8); super.reset(); } if (logMessage.trim().length() == 0 || logMessage.trim().equals(lineSeparator)) { @@ -220,7 +221,7 @@ public class LoggingPrintStream extends PrintStream { private ThreadLocal perThreadStObjects = new ThreadLocal<>(); public LoggingPrintStream(ByteArrayOutputStream os) { - super(os, true); + super(os, true, StandardCharsets.UTF_8); } public void setLogger(Logger l) { @@ -490,11 +491,11 @@ private static class StackTraceObjects { private StackTraceObjects(Throwable x) { // alloc buffer for getting stack trace. stackTraceBuf = new ByteArrayOutputStream(); - stStream = new PrintStream(stackTraceBuf, true); + stStream = new PrintStream(stackTraceBuf, true, StandardCharsets.UTF_8); comparisonBuf = new ByteArrayOutputStream(); - cbStream = new PrintStream(comparisonBuf, true); + cbStream = new PrintStream(comparisonBuf, true, StandardCharsets.UTF_8); ((Throwable) x).printStackTrace(stStream); - stString = stackTraceBuf.toString(); + stString = stackTraceBuf.toString(StandardCharsets.UTF_8); stackTraceBufBytes = stackTraceBuf.size(); // helps keep our stack trace skipping logic simpler. cbStream.println(x); @@ -509,7 +510,7 @@ boolean ignorePrintln(String str) { String cbString; int cbLen; cbStream.println(str); - cbString = comparisonBuf.toString(); + cbString = comparisonBuf.toString(StandardCharsets.UTF_8); cbLen = cbString.length(); if (stString.regionMatches(charsIgnored, cbString, 0, cbLen)) { charsIgnored += cbLen; diff --git a/nucleus/common/common-util/src/main/java/com/sun/enterprise/security/store/PasswordAdapter.java b/nucleus/common/common-util/src/main/java/com/sun/enterprise/security/store/PasswordAdapter.java index 20a3017596e..ebd48a2512e 100644 --- a/nucleus/common/common-util/src/main/java/com/sun/enterprise/security/store/PasswordAdapter.java +++ b/nucleus/common/common-util/src/main/java/com/sun/enterprise/security/store/PasswordAdapter.java @@ -37,7 +37,7 @@ * only if the new code is made subject to such option by the copyright * holder. */ -// Portions Copyright [2019] Payara Foundation and/or affiliates +// Portions Copyright [2019-2024] Payara Foundation and/or affiliates package com.sun.enterprise.security.store; @@ -47,6 +47,7 @@ import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; +import java.nio.charset.StandardCharsets; import java.security.Key; import java.security.KeyStore; import java.security.KeyStoreException; @@ -160,7 +161,7 @@ public synchronized String getPasswordForAlias(final String alias) final Key key = pwdStore.getKey( alias, getMasterPassword() ); if ( key != null ) { - passwordString = new String( key.getEncoded() ); + passwordString = new String(key.getEncoded(), StandardCharsets.UTF_8); } return passwordString; diff --git a/nucleus/common/common-util/src/main/java/com/sun/enterprise/universal/glassfish/ASenvPropertyReader.java b/nucleus/common/common-util/src/main/java/com/sun/enterprise/universal/glassfish/ASenvPropertyReader.java index 6f4d2700492..1dfbff1c130 100644 --- a/nucleus/common/common-util/src/main/java/com/sun/enterprise/universal/glassfish/ASenvPropertyReader.java +++ b/nucleus/common/common-util/src/main/java/com/sun/enterprise/universal/glassfish/ASenvPropertyReader.java @@ -37,13 +37,14 @@ * only if the new code is made subject to such option by the copyright * holder. */ -// Portions Copyright [2017-2020] [Payara Foundation and/or its affiliates.] +// Portions Copyright [2017-2024] [Payara Foundation and/or its affiliates.] package com.sun.enterprise.universal.glassfish; import com.sun.enterprise.universal.io.SmartFile; import com.sun.enterprise.util.net.NetUtils; import java.io.*; +import java.nio.charset.StandardCharsets; import java.util.*; import static com.sun.enterprise.util.SystemPropertyConstants.*; @@ -241,7 +242,7 @@ private void setProperties(File configDir) { File asenv = new File(configDir, GFLauncherUtils.isWindows() ? WINDOWS_ASENV_FILENAME : UNIX_ASENV_FILENAME); - try (BufferedReader reader = new BufferedReader(new FileReader(asenv))) { + try (BufferedReader reader = new BufferedReader(new FileReader(asenv, StandardCharsets.UTF_8))) { String line; while ((line = reader.readLine()) != null) { setProperty(line); diff --git a/nucleus/common/common-util/src/main/java/com/sun/enterprise/universal/process/ProcessManager.java b/nucleus/common/common-util/src/main/java/com/sun/enterprise/universal/process/ProcessManager.java index da6093d000e..7186ede568e 100644 --- a/nucleus/common/common-util/src/main/java/com/sun/enterprise/universal/process/ProcessManager.java +++ b/nucleus/common/common-util/src/main/java/com/sun/enterprise/universal/process/ProcessManager.java @@ -37,11 +37,12 @@ * only if the new code is made subject to such option by the copyright * holder. */ -// Portions Copyright [2018-2019] [Payara Foundation and/or its affiliates] +// Portions Copyright [2018-2024] [Payara Foundation and/or its affiliates] package com.sun.enterprise.universal.process; import java.io.*; +import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.Arrays; import java.util.List; @@ -171,7 +172,7 @@ private void writeStdin() throws ProcessManagerException { throw new ProcessManagerException(Strings.get("null.process")); } - try (PrintWriter pipe = new PrintWriter(new BufferedWriter(new OutputStreamWriter(process.getOutputStream())))) { + try (PrintWriter pipe = new PrintWriter(new BufferedWriter(new OutputStreamWriter(process.getOutputStream(), StandardCharsets.UTF_8)))) { for (String stdinLine : stdinLines) { debug("InputLine ->" + stdinLine + "<-"); pipe.println(stdinLine); @@ -185,7 +186,7 @@ private void writeStdin() throws ProcessManagerException { //////////////////////////////////////////////////////////////////////////// private void readStream(String name, InputStream stream, StringBuffer sb) { - BufferedReader reader = new BufferedReader(new InputStreamReader(stream)); + BufferedReader reader = new BufferedReader(new InputStreamReader(stream, StandardCharsets.UTF_8)); Thread thread = new Thread(new ReaderThread(reader, sb, echo), name); threads.add(thread); thread.start(); diff --git a/nucleus/common/common-util/src/main/java/com/sun/enterprise/universal/process/ProcessState.java b/nucleus/common/common-util/src/main/java/com/sun/enterprise/universal/process/ProcessState.java new file mode 100644 index 00000000000..c7c5af6afb3 --- /dev/null +++ b/nucleus/common/common-util/src/main/java/com/sun/enterprise/universal/process/ProcessState.java @@ -0,0 +1,46 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright (c) [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 + * and Distribution License("CDDL") (collectively, the "License"). You + * may not use this file except in compliance with the License. You can + * obtain a copy of the License at + * https://github.com/payara/Payara/blob/main/LICENSE.txt + * See the License for the specific + * language governing permissions and limitations under the License. + * + * When distributing the software, include this License Header Notice in each + * file and include the License file at glassfish/legal/LICENSE.txt. + * + * GPL Classpath Exception: + * The Payara Foundation designates this particular file as subject to the + * "Classpath" exception as provided by the Payara Foundation in the GPL + * Version 2 section of the License file that accompanied this code. + * + * Modifications: + * If applicable, add the following below the License Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyright [year] [name of copyright owner]" + * + * Contributor(s): + * If you wish your version of this file to be governed by only the CDDL or + * only the GPL Version 2, indicate your decision by adding "[Contributor] + * elects to include this software in this distribution under the [CDDL or GPL + * Version 2] license." If you don't indicate a single choice of license, a + * recipient has the option to distribute your version of this file under + * either the CDDL, the GPL Version 2 or to extend the choice of license to + * its licensees as provided above. However, if you add GPL Version 2 code + * and therefore, elected the GPL Version 2 license, then the option applies + * only if the new code is made subject to such option by the copyright + * holder. + */ + +package com.sun.enterprise.universal.process; + +public enum ProcessState { + RUNNING,STOPPED,ERROR; +} diff --git a/nucleus/common/common-util/src/main/java/com/sun/enterprise/universal/process/ProcessStreamDrainerWorker.java b/nucleus/common/common-util/src/main/java/com/sun/enterprise/universal/process/ProcessStreamDrainerWorker.java index b706e1e5f5a..5ea8b2c5156 100644 --- a/nucleus/common/common-util/src/main/java/com/sun/enterprise/universal/process/ProcessStreamDrainerWorker.java +++ b/nucleus/common/common-util/src/main/java/com/sun/enterprise/universal/process/ProcessStreamDrainerWorker.java @@ -37,11 +37,12 @@ * only if the new code is made subject to such option by the copyright * holder. */ -// Portions Copyright [2019] Payara Foundation and/or affiliates +// Portions Copyright [2019-2024] Payara Foundation and/or affiliates package com.sun.enterprise.universal.process; import java.io.*; +import java.nio.charset.StandardCharsets; /////////////////////////////////////////////////////////////////////////// @@ -78,7 +79,7 @@ public void run() { } if (sb != null) { - sb.append(new String(buffer, 0, count)); + sb.append(new String(buffer, 0, count, StandardCharsets.UTF_8)); } } } catch (IOException e) { diff --git a/nucleus/common/common-util/src/main/java/com/sun/enterprise/universal/process/ProcessUtils.java b/nucleus/common/common-util/src/main/java/com/sun/enterprise/universal/process/ProcessUtils.java index d06ef3644ce..71fbdd3a640 100644 --- a/nucleus/common/common-util/src/main/java/com/sun/enterprise/universal/process/ProcessUtils.java +++ b/nucleus/common/common-util/src/main/java/com/sun/enterprise/universal/process/ProcessUtils.java @@ -37,6 +37,7 @@ * only if the new code is made subject to such option by the copyright * holder. */ +// Portions Copyright 2024 Payara Foundation and/or affiliates package com.sun.enterprise.universal.process; import java.io.*; @@ -171,6 +172,16 @@ public static String killJvm(String classname) { return null; } + /** + * The deprecated isProcessingRunning method + * + * DO NOT USE! Retained for semantic versioning. Replaced by {@link ProcessUtils#getProcessRunningState(int)}. + */ + @Deprecated(forRemoval = true, since = "6.21.0") + public static Boolean isProcessRunning(int aPid) { + return false; + } + /** * If we can determine it -- find out if the process that owns the given * process id is running. @@ -179,7 +190,7 @@ public static String killJvm(String classname) { * @return true if it's running, false if not and null if we don't know. I.e * the return value is a true tri-state Boolean. */ - public static Boolean isProcessRunning(int aPid) { + public static ProcessState getProcessRunningState(int aPid) { try { if (OS.isWindowsForSure()) return isProcessRunningWindows(aPid); @@ -187,7 +198,7 @@ public static Boolean isProcessRunning(int aPid) { return isProcessRunningUnix(aPid); } catch (Exception e) { - return null; + return ProcessState.ERROR; } } ////////////////////////////////////////////////////////////////////////// @@ -197,7 +208,7 @@ public static Boolean isProcessRunning(int aPid) { private static final String[] paths; private static boolean debug; - private static boolean isProcessRunningWindows(int aPid) throws ProcessManagerException { + private static ProcessState isProcessRunningWindows(int aPid) throws ProcessManagerException { String pidString = Integer.toString(aPid); ProcessManager pm = new ProcessManager("tasklist", "/NH", "/FI", "\"pid eq " + pidString + "\""); pm.setEcho(false); @@ -222,20 +233,20 @@ private static boolean isProcessRunningWindows(int aPid) throws ProcessManagerEx // be reusing the pid. This isn't a guarantee because some other // java process might be reusing the pid. if (out.indexOf("java.exe") >= 0 && out.indexOf(pidString) >= 0) - return true; + return ProcessState.RUNNING; else - return false; + return ProcessState.STOPPED; } throw new ProcessManagerException("unknown"); } - private static Boolean isProcessRunningUnix(int aPid) throws ProcessManagerException { + private static ProcessState isProcessRunningUnix(int aPid) throws ProcessManagerException { ProcessManager pm = new ProcessManager("kill", "-0", "" + aPid); pm.setEcho(false); pm.execute(); int retval = pm.getExitValue(); - return retval == 0 ? Boolean.TRUE : Boolean.FALSE; + return retval == 0 ? ProcessState.RUNNING : ProcessState.STOPPED; } static { diff --git a/nucleus/common/common-util/src/main/java/com/sun/enterprise/universal/xml/MiniXmlParser.java b/nucleus/common/common-util/src/main/java/com/sun/enterprise/universal/xml/MiniXmlParser.java index 1c63f9d9411..9a4d65bba6d 100644 --- a/nucleus/common/common-util/src/main/java/com/sun/enterprise/universal/xml/MiniXmlParser.java +++ b/nucleus/common/common-util/src/main/java/com/sun/enterprise/universal/xml/MiniXmlParser.java @@ -37,7 +37,7 @@ * only if the new code is made subject to such option by the copyright * holder. */ -// Portions Copyright [2016-2020] [Payara Foundation and/or its affiliates] +// Portions Copyright [2016-2024] [Payara Foundation and/or its affiliates] package com.sun.enterprise.universal.xml; @@ -49,6 +49,7 @@ import com.sun.enterprise.util.JDK; import com.sun.enterprise.util.StringUtils; import java.io.*; +import java.nio.charset.StandardCharsets; import java.util.*; import java.util.logging.Level; import java.util.logging.Logger; @@ -68,6 +69,8 @@ * @author bnevins */ public class MiniXmlParser { + + private static final Logger LOGGER = Logger.getLogger(MiniXmlParser.class.getName()); public MiniXmlParser(File domainXml) throws MiniXmlParserException { this(domainXml, DEFAULT_VS_ID); // default for a domain } @@ -96,7 +99,7 @@ public MiniXmlParser(File domainXml, String serverName) throws MiniXmlParserExce } } catch (Exception e) { - // ignore + LOGGER.log(Level.FINE, "Problem closing parser", e); } try { if (reader != null) { @@ -104,7 +107,7 @@ public MiniXmlParser(File domainXml, String serverName) throws MiniXmlParserExce } } catch (Exception e) { - // ignore + LOGGER.log(Level.FINE, "Problem closing parser", e); } } } @@ -400,7 +403,7 @@ private void read() throws XMLStreamException, EndDocumentException, FileNotFoun } private void createParser() throws FileNotFoundException, XMLStreamException { - reader = new InputStreamReader(new FileInputStream(domainXml)); + reader = new InputStreamReader(new FileInputStream(domainXml), StandardCharsets.UTF_8); XMLInputFactory xif = getXmlInputFactory(); // Set the resolver so that any external entity references, such // as a reference to a DTD, return an empty file. The domain.xml @@ -531,8 +534,9 @@ private void parseConfig() throws XMLStreamException, EndDocumentException { } else if (event == START_ELEMENT) { String name = parser.getLocalName(); if (null == name) { - skipTree(name); - } else switch (name) { + continue; + } + switch (name) { case SYSTEM_PROPERTY: parseSystemProperty(SysPropsHandler.Type.CONFIG); break; @@ -589,8 +593,10 @@ private void parseNetworkConfig() } } else if (event == START_ELEMENT) { String name = parser.getLocalName(); - if (null == name) {skipTree(name); - } else switch (name) { + if (null == name) { + continue; + } + switch (name) { case "protocols": parseProtocols(); break; @@ -622,29 +628,26 @@ private void parseIiopService() throws XMLStreamException, EndDocumentException } else if (event == START_ELEMENT) { String name = parser.getLocalName(); if (null == name) { - skipTree(name); - } else switch (name) { - // Cursor --> START_ELEMENT of - case "iiop-listener": - // Get attributes - Map iiopAttributes = parseAttributes(); - - // Skip to ssl config if present - while (true) { - skipToButNotPast("iiop-listener", "ssl"); - name = parser.getLocalName(); - if ("ssl".equals(name)) { - iiopAttributes.putAll(parseAttributes()); - // Only store attributes of SSL enabled IIOP listeners - iiopSslAttributes.add(iiopAttributes); - } else if ("iiop-listener".equals(name)) { - break; - } + continue; + } + // Cursor --> START_ELEMENT of + if (name.equals("iiop-listener")) {// Get attributes + Map iiopAttributes = parseAttributes(); + + // Skip to ssl config if present + while (true) { + skipToButNotPast("iiop-listener", "ssl"); + name = parser.getLocalName(); + if ("ssl".equals(name)) { + iiopAttributes.putAll(parseAttributes()); + // Only store attributes of SSL enabled IIOP listeners + iiopSslAttributes.add(iiopAttributes); + } else if ("iiop-listener".equals(name)) { + break; } - break; - default: - skipTree(name); - break; + } + } else { + skipTree(name); } } } diff --git a/nucleus/common/common-util/src/main/java/com/sun/enterprise/universal/xml/XmlParserHelper.java b/nucleus/common/common-util/src/main/java/com/sun/enterprise/universal/xml/XmlParserHelper.java index aa73c2ca070..f38dd8737e6 100644 --- a/nucleus/common/common-util/src/main/java/com/sun/enterprise/universal/xml/XmlParserHelper.java +++ b/nucleus/common/common-util/src/main/java/com/sun/enterprise/universal/xml/XmlParserHelper.java @@ -37,9 +37,11 @@ * only if the new code is made subject to such option by the copyright * holder. */ +// Portions Copyright 2024 Payara Foundation and/or affiliates package com.sun.enterprise.universal.xml; import java.io.*; +import java.nio.charset.StandardCharsets; import javax.xml.stream.*; /** @@ -49,7 +51,7 @@ public final class XmlParserHelper { public XmlParserHelper(final File f) throws FileNotFoundException, XMLStreamException { - reader = new InputStreamReader(new FileInputStream(f)); + reader = new InputStreamReader(new FileInputStream(f), StandardCharsets.UTF_8); parser = XMLInputFactory.newInstance().createXMLStreamReader( f.toURI().toString(), reader); } diff --git a/nucleus/common/common-util/src/main/java/com/sun/enterprise/util/ProcessExecutor.java b/nucleus/common/common-util/src/main/java/com/sun/enterprise/util/ProcessExecutor.java index 0efac7083f3..b447a1051e2 100644 --- a/nucleus/common/common-util/src/main/java/com/sun/enterprise/util/ProcessExecutor.java +++ b/nucleus/common/common-util/src/main/java/com/sun/enterprise/util/ProcessExecutor.java @@ -37,7 +37,7 @@ * only if the new code is made subject to such option by the copyright * holder. */ -// Portions Copyright [2018] [Payara Foundation and/or its affiliates] +// Portions Copyright [2018-2024] [Payara Foundation and/or its affiliates] package com.sun.enterprise.util; @@ -46,6 +46,7 @@ import com.sun.enterprise.util.io.FileUtils; import java.io.*; +import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.List; @@ -356,7 +357,7 @@ private void addInputLinesToProcessInput(Process subProcess) throws ExecExceptio if (mInputLines == null) return; - try (PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(subProcess.getOutputStream())))) { + try (PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(subProcess.getOutputStream(), StandardCharsets.UTF_8)))) { for (String mInputLine : mInputLines) { if (bDebug) { System.out.println("InputLine ->" + mInputLine + "<-"); @@ -374,7 +375,7 @@ private String[] getInputStrings(InputStream inputStream) throws ExecException { if (inputStream == null) return null; List list = new ArrayList<>(); - try (BufferedReader in = new BufferedReader(new InputStreamReader(inputStream))) { + try (BufferedReader in = new BufferedReader(new InputStreamReader(inputStream, StandardCharsets.UTF_8))) { String str; while ((str = in.readLine()) != null) list.add(str); return list.isEmpty() @@ -438,7 +439,7 @@ private void sleep(long millis) { */ protected String getFileBuffer(File file) { final StringBuilder sb = new StringBuilder(); - try (BufferedReader reader = new BufferedReader(new FileReader(file))) { + try (BufferedReader reader = new BufferedReader(new FileReader(file, StandardCharsets.UTF_8))) { String line; while ((line = reader.readLine()) != null) { sb.append(line); diff --git a/nucleus/common/common-util/src/main/java/com/sun/enterprise/util/io/FileUtils.java b/nucleus/common/common-util/src/main/java/com/sun/enterprise/util/io/FileUtils.java index bec15e50535..5ec00701f76 100644 --- a/nucleus/common/common-util/src/main/java/com/sun/enterprise/util/io/FileUtils.java +++ b/nucleus/common/common-util/src/main/java/com/sun/enterprise/util/io/FileUtils.java @@ -37,7 +37,7 @@ * only if the new code is made subject to such option by the copyright * holder. */ -// Portions Copyright [2016-2021] [Payara Foundation and/or affiliates] +// Portions Copyright [2016-2024] [Payara Foundation and/or affiliates] package com.sun.enterprise.util.io; @@ -69,6 +69,7 @@ import java.nio.channels.FileChannel; import java.nio.channels.ReadableByteChannel; import java.nio.channels.WritableByteChannel; +import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.Collection; import java.util.List; @@ -780,7 +781,6 @@ private static int doWithRetry(RetriableWork work) { } catch (InterruptedException ex) { _utillogger.log(Level.SEVERE, "Thread Interrupted Exception", ex); } - System.gc(); work.run(); } } @@ -1207,7 +1207,7 @@ public static String readSmallFile(final String fileName) public static String readSmallFile(final File file) throws IOException { final StringBuilder sb = new StringBuilder(); - try (final BufferedReader bf = new BufferedReader(new FileReader(file))) { + try (final BufferedReader bf = new BufferedReader(new FileReader(file, StandardCharsets.UTF_8))) { String line; while ( (line = bf.readLine()) != null ) { sb.append(line); @@ -1288,7 +1288,7 @@ public static void writeStringToFile(String s, File f) throws IOException { Writer writer = null; try { - writer = new PrintWriter(f); + writer = new PrintWriter(f, StandardCharsets.UTF_8); writer.write(s); } finally { @@ -1336,7 +1336,7 @@ public boolean accept(File dir, String name) { public static String resourceToString(String resourceName) { byte[] bytes = resourceToBytes(resourceName); - return bytes == null ? null : new String(bytes); + return bytes == null ? null : new String(bytes, StandardCharsets.UTF_8); } /** diff --git a/nucleus/common/common-util/src/main/java/com/sun/enterprise/util/io/ServerDirs.java b/nucleus/common/common-util/src/main/java/com/sun/enterprise/util/io/ServerDirs.java index 350079ac118..2eeff19e1d8 100644 --- a/nucleus/common/common-util/src/main/java/com/sun/enterprise/util/io/ServerDirs.java +++ b/nucleus/common/common-util/src/main/java/com/sun/enterprise/util/io/ServerDirs.java @@ -37,10 +37,13 @@ * only if the new code is made subject to such option by the copyright * holder. */ +// Portions Copyright 2024 Payara Foundation and/or affiliates package com.sun.enterprise.util.io; import java.io.*; import java.io.File; +import java.nio.charset.StandardCharsets; +import java.util.logging.Logger; import com.sun.enterprise.universal.i18n.LocalStringsImpl; import com.sun.enterprise.universal.io.SmartFile; @@ -127,24 +130,13 @@ public ServerDirs(File leaf) throws IOException { localPasswordFile = new File(configDir, "local-password"); String localPasswordBuffer = null; // need an atomic assign tor localPassword - BufferedReader r = null; - try { - r = new BufferedReader(new FileReader(localPasswordFile)); + try (BufferedReader r = new BufferedReader(new FileReader(localPasswordFile, StandardCharsets.UTF_8))) { localPasswordBuffer = r.readLine(); - } - catch (Exception e) { - // needs no handling - } - finally { + } catch (Exception e) { + LOGGER.fine("Error reading local password file: " + localPasswordFile); + } finally { localPassword = localPasswordBuffer; - if (r != null) { - try { - r.close(); - } - catch (IOException ex) { - // ignore - } - } + // ignore } // bnevins May 17 -- perhaps we should have a NodeAgentDirs ??? @@ -262,6 +254,7 @@ public String toString() { /////////////////////////////////////////////////////////////////////////// /////////// All Private Below ///////////////////////// /////////////////////////////////////////////////////////////////////////// + private static final Logger LOGGER = Logger.getLogger(ServerDirs.class.getName()); private final String serverName; private final File serverDir; private final File parentDir; diff --git a/nucleus/common/common-util/src/main/java/com/sun/enterprise/util/net/NetUtils.java b/nucleus/common/common-util/src/main/java/com/sun/enterprise/util/net/NetUtils.java index 52016376ac6..264a42f4787 100644 --- a/nucleus/common/common-util/src/main/java/com/sun/enterprise/util/net/NetUtils.java +++ b/nucleus/common/common-util/src/main/java/com/sun/enterprise/util/net/NetUtils.java @@ -37,13 +37,15 @@ * 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.util.net; import com.sun.enterprise.util.CULoggerInfo; import com.sun.enterprise.util.StringUtils; +import org.glassfish.common.util.RandomUtils; + import java.net.*; -import java.security.SecureRandom; +import java.nio.charset.StandardCharsets; import java.util.*; import java.io.*; import java.util.logging.Level; @@ -469,9 +471,8 @@ public static int getFreePort(String hostName, int startingPort, int endingPort) int range = endingPort - startingPort; int port = 0; if (range > 0) { - SecureRandom r = new SecureRandom(); while (true) { - port = r.nextInt(range + 1) + startingPort; + port = RandomUtils.nextInt(range + 1) + startingPort; if (isPortFree(hostName, port)) { break; } @@ -736,7 +737,7 @@ public static boolean isSecurePort(String hostname, int port) throws IOException // Determine protocol from result // Can't read https response w/ OpenSSL (or equiv), so use as // default & try to detect an http response. - String response = new String(input).toLowerCase(Locale.ENGLISH); + String response = new String(input, StandardCharsets.UTF_8).toLowerCase(Locale.ENGLISH); boolean isSecure = true; if (read <= 0 || response.length() == 0) { isSecure = false; diff --git a/nucleus/common/common-util/src/main/java/fish/payara/logging/PayaraLogManager.java b/nucleus/common/common-util/src/main/java/fish/payara/logging/PayaraLogManager.java index db79210a4eb..e25cba24fd8 100644 --- a/nucleus/common/common-util/src/main/java/fish/payara/logging/PayaraLogManager.java +++ b/nucleus/common/common-util/src/main/java/fish/payara/logging/PayaraLogManager.java @@ -1,7 +1,7 @@ /* * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. * - * Copyright (c) 2021 Payara Foundation and/or its affiliates. All rights reserved. + * Copyright (c) 2021-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 @@ -43,6 +43,7 @@ import java.io.*; +import java.nio.charset.StandardCharsets; import java.util.Properties; import java.util.logging.LogManager; @@ -60,6 +61,6 @@ public void readConfiguration(InputStream ins) throws IOException, SecurityExcep StringWriter writer = new StringWriter(); configuration.store(new PrintWriter(writer), null); - super.readConfiguration(new ByteArrayInputStream(writer.getBuffer().toString().getBytes())); + super.readConfiguration(new ByteArrayInputStream(writer.getBuffer().toString().getBytes(StandardCharsets.UTF_8))); } } \ No newline at end of file diff --git a/nucleus/common/common-util/src/main/java/org/glassfish/admin/payload/PayloadImpl.java b/nucleus/common/common-util/src/main/java/org/glassfish/admin/payload/PayloadImpl.java index fbce7fe0b80..c5f7c86099b 100644 --- a/nucleus/common/common-util/src/main/java/org/glassfish/admin/payload/PayloadImpl.java +++ b/nucleus/common/common-util/src/main/java/org/glassfish/admin/payload/PayloadImpl.java @@ -37,13 +37,14 @@ * only if the new code is made subject to such option by the copyright * holder. */ -// Poritons Copyright [2019] Payara Foundation and/or affiliates +// Poritons Copyright [2019-2024] Payara Foundation and/or affiliates package org.glassfish.admin.payload; import java.io.*; import java.net.URI; import java.net.URLConnection; +import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.Collections; import java.util.Iterator; @@ -679,7 +680,7 @@ public InputStream getInputStream() { * Some parts might not have content. */ final byte[] data = (content != null) ? - content.getBytes() : new byte[0]; + content.getBytes(StandardCharsets.UTF_8) : new byte[0]; is = new ByteArrayInputStream(data); } return is; diff --git a/nucleus/common/common-util/src/main/java/org/glassfish/common/util/admin/AsadminInput.java b/nucleus/common/common-util/src/main/java/org/glassfish/common/util/admin/AsadminInput.java index edfadd05b07..6089f28c087 100644 --- a/nucleus/common/common-util/src/main/java/org/glassfish/common/util/admin/AsadminInput.java +++ b/nucleus/common/common-util/src/main/java/org/glassfish/common/util/admin/AsadminInput.java @@ -37,7 +37,7 @@ * only if the new code is made subject to such option by the copyright * holder. */ -// Portions Copyright [2019] Payara Foundation and/or affiliates +// Portions Copyright [2019-2024] Payara Foundation and/or affiliates package org.glassfish.common.util.admin; @@ -48,7 +48,7 @@ import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; -import java.net.URISyntaxException; +import java.nio.charset.StandardCharsets; import java.text.MessageFormat; import java.util.HashMap; import java.util.Map; @@ -126,7 +126,7 @@ public static InputReader reader(final String inputPath) throws IOException { * @throws IOException */ public static InputReader reader(final InputStream is) throws IOException { - final BufferedReader reader = new BufferedReader(new InputStreamReader(is)); + final BufferedReader reader = new BufferedReader(new InputStreamReader(is, StandardCharsets.UTF_8)); final String version = readVersionFromFirstLine(reader); return newReader(reader, version); } diff --git a/nucleus/common/common-util/src/main/java/org/glassfish/common/util/admin/ManPageFinder.java b/nucleus/common/common-util/src/main/java/org/glassfish/common/util/admin/ManPageFinder.java index a475feeb814..758fc35119e 100644 --- a/nucleus/common/common-util/src/main/java/org/glassfish/common/util/admin/ManPageFinder.java +++ b/nucleus/common/common-util/src/main/java/org/glassfish/common/util/admin/ManPageFinder.java @@ -37,7 +37,7 @@ * only if the new code is made subject to such option by the copyright * holder. */ -// Portions Copyright [2019] Payara Foundation and/or affiliates +// Portions Copyright [2019-2024] Payara Foundation and/or affiliates package org.glassfish.common.util.admin; @@ -45,7 +45,7 @@ import java.io.Reader; import java.io.BufferedReader; import java.io.InputStreamReader; -import java.io.UnsupportedEncodingException; +import java.nio.charset.StandardCharsets; import java.util.Locale; import java.util.Iterator; import java.util.NoSuchElementException; @@ -111,11 +111,7 @@ public static BufferedReader getCommandManPage( if (s == null) return null; Reader r; - try { - r = new InputStreamReader(s, "utf-8"); - } catch (UnsupportedEncodingException ex) { - r = new InputStreamReader(s); - } + r = new InputStreamReader(s, StandardCharsets.UTF_8); return new BufferedReader(r); } diff --git a/nucleus/common/common-util/src/main/java/org/glassfish/security/common/FileRealmStorageManager.java b/nucleus/common/common-util/src/main/java/org/glassfish/security/common/FileRealmStorageManager.java index 9a67e4ae02b..919fb93f673 100644 --- a/nucleus/common/common-util/src/main/java/org/glassfish/security/common/FileRealmStorageManager.java +++ b/nucleus/common/common-util/src/main/java/org/glassfish/security/common/FileRealmStorageManager.java @@ -37,7 +37,7 @@ * only if the new code is made subject to such option by the copyright * holder. */ -// Portions Copyright [2019] [Payara Foundation and/or its affiliates] +// Portions Copyright [2019-2024] [Payara Foundation and/or its affiliates] package org.glassfish.security.common; @@ -52,6 +52,7 @@ import java.io.FileOutputStream; import java.io.FileReader; import java.io.IOException; +import java.nio.charset.StandardCharsets; import java.security.SecureRandom; import java.util.ArrayList; import java.util.Arrays; @@ -365,7 +366,7 @@ public void persist() throws IOException { try (FileOutputStream out = new FileOutputStream(keyfile)) { for (Entry userEntry : userTable.entrySet()) { - out.write(encodeUser(userEntry.getKey(), userEntry.getValue(), userEntry.getValue().getAlgo()).getBytes()); + out.write(encodeUser(userEntry.getKey(), userEntry.getValue(), userEntry.getValue().getAlgo()).getBytes(StandardCharsets.UTF_8)); } } catch (IOException e) { throw e; @@ -549,7 +550,7 @@ private static boolean isValid(String s, boolean userName) { * */ private void loadKeyFile() throws IOException { - try (BufferedReader input = new BufferedReader(new FileReader(keyfile))) { + try (BufferedReader input = new BufferedReader(new FileReader(keyfile, StandardCharsets.UTF_8))) { while (input.ready()) { String line = input.readLine(); diff --git a/nucleus/common/common-util/src/main/java/org/glassfish/security/common/SharedSecureRandomImpl.java b/nucleus/common/common-util/src/main/java/org/glassfish/security/common/SharedSecureRandomImpl.java index 95b0d731d73..aa104bc2b9d 100644 --- a/nucleus/common/common-util/src/main/java/org/glassfish/security/common/SharedSecureRandomImpl.java +++ b/nucleus/common/common-util/src/main/java/org/glassfish/security/common/SharedSecureRandomImpl.java @@ -37,7 +37,7 @@ * only if the new code is made subject to such option by the copyright * holder. */ -// Portions Copyright [2018] [Payara Foundation and/or its affiliates] +// Portions Copyright [2018-2024] [Payara Foundation and/or its affiliates] package org.glassfish.security.common; import java.security.SecureRandom; @@ -49,15 +49,7 @@ public class SharedSecureRandomImpl { // the generator has a large period (in Sun's standard implementation, based on the 160-bit SHA1 hash function, the // period is 2^160); - private static final SecureRandom secureRandom = new SecureRandom(); - - static { - // always call java.security.SecureRandom.nextBytes(byte[]) - // immediately after creating a new instance of the PRNG. - // This will force the PRNG to seed itself securely - byte[] key = new byte[20]; - secureRandom.nextBytes(key); - } + private static final SecureRandom secureRandom = new SecureRandom(new byte[20]); /** * Can a single java.security.SecureRandom instance be shared safely by multiple threads ?. Yes. As far as I know. diff --git a/nucleus/core/logging/src/main/java/com/sun/enterprise/server/logging/LogManagerService.java b/nucleus/core/logging/src/main/java/com/sun/enterprise/server/logging/LogManagerService.java index f7abf9697ff..39161696301 100644 --- a/nucleus/core/logging/src/main/java/com/sun/enterprise/server/logging/LogManagerService.java +++ b/nucleus/core/logging/src/main/java/com/sun/enterprise/server/logging/LogManagerService.java @@ -37,7 +37,7 @@ * only if the new code is made subject to such option by the copyright * holder. */ -// Portions Copyright [2016-2022] [Payara Foundation and/or its affiliates] +// Portions Copyright [2016-2024] [Payara Foundation and/or its affiliates] package com.sun.enterprise.server.logging; @@ -733,7 +733,7 @@ public void changed(File changedFile) { } else if (a.equals(FAST_LOGGER_PROPERTY)) { if (!val.equals(fastLoggingDetail)) { fastLoggingDetail = val; - GFLogRecord.fastLogging = Boolean.parseBoolean(fastLoggingDetail); + GFLogRecord.fastLoggingAtomic.set(Boolean.parseBoolean(fastLoggingDetail)); } } else if (a.equals(COMPRESS_ON_ROTATION_PROPERTY)) { if (!val.equals(compressOnRotationDetail)) {