Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FISH-9771 FISH-9688 spot bugs random only used once #6967

Merged
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-2021] [Payara Foundation and/or its affiliates]
// Portions Copyright [2017-2024] [Payara Foundation and/or its affiliates]

package com.sun.enterprise.config.serverbeans;

Expand Down Expand Up @@ -77,6 +77,7 @@
import java.security.SecureRandom;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import java.util.logging.Level;
import java.util.logging.Logger;

Expand Down Expand Up @@ -614,6 +615,7 @@ class Decorator implements CreationDecorator<Cluster> {
public void decorate(AdminCommandContext context, final Cluster instance) throws TransactionFailure, PropertyVetoException {
Logger logger = ConfigApiLoggerInfo.getLogger();
LocalStringManagerImpl localStrings = new LocalStringManagerImpl(Cluster.class);
Random random = new SecureRandom();
NotedSalmon marked this conversation as resolved.
Show resolved Hide resolved
NotedSalmon marked this conversation as resolved.
Show resolved Hide resolved
Transaction t = Transaction.getTransaction(instance);
//check if cluster software is installed else fail , see issue 12023
final CopyConfig command = (CopyConfig) runner
Expand Down Expand Up @@ -723,7 +725,7 @@ public void decorate(AdminCommandContext context, final Cluster instance) throws

// generate a random port since user did not provide one.
// better fix in future would be to walk existing clusters and pick an unused port.
TCPPORT = Integer.toString(new SecureRandom().nextInt(9200 - 9090) + 9090);
TCPPORT = Integer.toString(random.nextInt(9200 - 9090) + 9090);

// hardcode all instances to use same default port.
// generate mode does not support multiple instances on one machine.
Expand All @@ -744,7 +746,7 @@ public void decorate(AdminCommandContext context, final Cluster instance) throws
gmsListenerPortSysProp.setName(propName);
if (TCPPORT == null || TCPPORT.trim().charAt(0) == '$') {
String generateGmsListenerPort = Integer.toString(
new SecureRandom().nextInt(9200 - 9090) + 9090);
random.nextInt(9200 - 9090) + 9090);
gmsListenerPortSysProp.setValue(generateGmsListenerPort);
} else {
gmsListenerPortSysProp.setValue(TCPPORT);
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-2019] [Payara Foundation and/or its affiliates]
// Portions Copyright [2017-2024] [Payara Foundation and/or its affiliates]

package com.sun.enterprise.admin.cli.cluster;

Expand Down Expand Up @@ -132,6 +132,7 @@ public class ImportSyncBundleCommand extends LocalInstanceCommand {
private File backupDir;

private static final String RENDEZVOUS_PROPERTY_NAME = "rendezvousOccurred";
private static final Random random = new SecureRandom();
NotedSalmon marked this conversation as resolved.
Show resolved Hide resolved
private String instanceDottedName;
private String rendevousDottedName;

Expand Down Expand Up @@ -334,8 +335,7 @@ private void writeDasProperties() throws IOException {
private void backupInstanceDir() {
File f = getServerDirs().getServerDir();
if (f != null && f.isDirectory()) {
SecureRandom r = new SecureRandom();
setBackupDir(r.nextInt());
setBackupDir(random.nextInt());
File backup = getBackupDir();
if (!f.renameTo(backup)) {
logger.warning(Strings.get("import.sync.bundle.backupInstanceDirFailed", f.getAbsolutePath(), backup.getAbsolutePath()));
Expand Down