NO-JIRA fix lgtm.com errors

Errors enumerated at
https://lgtm.com/projects/g/apache/activemq-artemis/alerts/?mode=tree&severity=error
This commit is contained in:
Justin Bertram 2018-09-05 22:04:03 -05:00 committed by Michael Andre Pearce
parent 57aacf784c
commit bfefd1f1ed
9 changed files with 49 additions and 43 deletions

View File

@ -75,8 +75,9 @@ public class DecodeJournal extends LockAbstract {
final int minFiles,
final int fileSize,
final String fileInput) throws Exception {
FileInputStream fileInputStream = new FileInputStream(new File(fileInput));
importJournal(directory, journalPrefix, journalSuffix, minFiles, fileSize, fileInputStream);
try (FileInputStream fileInputStream = new FileInputStream(new File(fileInput))) {
importJournal(directory, journalPrefix, journalSuffix, minFiles, fileSize, fileInputStream);
}
}
@ -86,8 +87,9 @@ public class DecodeJournal extends LockAbstract {
final int minFiles,
final int fileSize,
final InputStream stream) throws Exception {
Reader reader = new InputStreamReader(stream);
importJournal(directory, journalPrefix, journalSuffix, minFiles, fileSize, reader);
try (Reader reader = new InputStreamReader(stream)) {
importJournal(directory, journalPrefix, journalSuffix, minFiles, fileSize, reader);
}
}
public static void importJournal(final String directory,

View File

@ -139,8 +139,10 @@ public final class XmlDataImporter extends ActionAbstract {
return null;
}
public void process(String inputFile, String host, int port, boolean transactional) throws Exception {
this.process(new FileInputStream(inputFile), host, port, transactional);
public void process(String inputFileName, String host, int port, boolean transactional) throws Exception {
try (FileInputStream inputFile = new FileInputStream(inputFileName)) {
this.process(inputFile, host, port, transactional);
}
}
/**
@ -207,8 +209,10 @@ public final class XmlDataImporter extends ActionAbstract {
process(inputStream, session, managementSession);
}
public void validate(String file) throws Exception {
validate(new FileInputStream(file));
public void validate(String fileName) throws Exception {
try (FileInputStream file = new FileInputStream(fileName)) {
validate(file);
}
}
public void validate(InputStream inputStream) throws Exception {

View File

@ -176,13 +176,13 @@ public class NetworkHealthCheck extends ActiveMQScheduledComponent {
}
@Override
public NetworkHealthCheck setPeriod(long period) {
public synchronized NetworkHealthCheck setPeriod(long period) {
super.setPeriod(period);
return this;
}
@Override
public NetworkHealthCheck setTimeUnit(TimeUnit timeUnit) {
public synchronized NetworkHealthCheck setTimeUnit(TimeUnit timeUnit) {
super.setTimeUnit(timeUnit);
return this;
}

View File

@ -822,7 +822,7 @@ public class ActiveMQActivationSpec extends ConnectionFactoryProperties implemen
ActiveMQActivationSpec that = (ActiveMQActivationSpec) o;
if (acknowledgeMode != that.acknowledgeMode)
if (acknowledgeMode != null ? !acknowledgeMode.equals(that.acknowledgeMode) : that.acknowledgeMode != null)
return false;
if (subscriptionDurability != that.subscriptionDurability)
return false;

View File

@ -122,10 +122,11 @@ public class MessageServiceManager {
url = new URL(configResourcePath);
}
JAXBContext jaxb = JAXBContext.newInstance(MessageServiceConfiguration.class);
Reader reader = new InputStreamReader(url.openStream());
String xml = XMLUtil.readerToString(reader);
xml = XMLUtil.replaceSystemProps(xml);
configuration = (MessageServiceConfiguration) jaxb.createUnmarshaller().unmarshal(new StringReader(xml));
try (Reader reader = new InputStreamReader(url.openStream())) {
String xml = XMLUtil.readerToString(reader);
xml = XMLUtil.replaceSystemProps(xml);
configuration = (MessageServiceConfiguration) jaxb.createUnmarshaller().unmarshal(new StringReader(xml));
}
}
}
if (threadPool == null)

View File

@ -69,21 +69,22 @@ public class FileDeploymentManager {
url = new URL(configurationUrl);
}
// create a reader
Reader reader = new InputStreamReader(url.openStream());
String xml = XMLUtil.readerToString(reader);
//replace any system props
xml = XMLUtil.replaceSystemProps(xml);
Element e = XMLUtil.stringToElement(xml);
try (Reader reader = new InputStreamReader(url.openStream())) {
String xml = XMLUtil.readerToString(reader);
//replace any system props
xml = XMLUtil.replaceSystemProps(xml);
Element e = XMLUtil.stringToElement(xml);
//iterate around all the deployables
for (Deployable deployable : deployables.values()) {
String root = deployable.getRootElement();
NodeList children = e.getElementsByTagName(root);
//if the root element exists then parse it
if (root != null && children.getLength() > 0) {
Node item = children.item(0);
XMLUtil.validate(item, deployable.getSchema());
deployable.parse((Element) item, url);
//iterate around all the deployables
for (Deployable deployable : deployables.values()) {
String root = deployable.getRootElement();
NodeList children = e.getElementsByTagName(root);
//if the root element exists then parse it
if (root != null && children.getLength() > 0) {
Node item = children.item(0);
XMLUtil.validate(item, deployable.getSchema());
deployable.parse((Element) item, url);
}
}
}
}

View File

@ -1251,17 +1251,6 @@ public final class FileConfigurationParser extends XMLConfigurationUtil {
return configurations.get(0);
}
private static final ArrayList<String> POLICY_LIST = new ArrayList<>();
static {
POLICY_LIST.add("colocated");
POLICY_LIST.add("live-only");
POLICY_LIST.add("replicated");
POLICY_LIST.add("replica");
POLICY_LIST.add("shared-store-master");
POLICY_LIST.add("shared-store-slave");
}
private static final ArrayList<String> HA_LIST = new ArrayList<>();
static {

View File

@ -40,6 +40,7 @@ import static org.apache.activemq.artemis.core.persistence.impl.journal.JournalR
import static org.apache.activemq.artemis.core.persistence.impl.journal.JournalRecordIds.UPDATE_DELIVERY_COUNT;
import java.io.File;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintStream;
import java.io.Reader;
@ -113,10 +114,11 @@ public final class DescribeJournal {
configuration = new FileConfiguration();
File configFile = new File(instanceFolder + "/etc/broker.xml");
URL url;
Reader reader = null;
try {
url = configFile.toURI().toURL();
Reader reader = new InputStreamReader(url.openStream());
reader = new InputStreamReader(url.openStream());
String xml = XMLUtil.readerToString(reader);
xml = XMLUtil.replaceSystemProps(xml);
Element e = XMLUtil.stringToElement(xml);
@ -130,6 +132,14 @@ public final class DescribeJournal {
}
} catch (Exception e) {
logger.error("failed to load broker.xml", e);
} finally {
if (reader != null) {
try {
reader.close();
} catch (IOException e) {
// ignore
}
}
}
} else {
configuration = new ConfigurationImpl();

View File

@ -130,9 +130,8 @@ public final class ClusterConnectionImpl implements ClusterConnection, AfterConn
* however we need the guard to synchronize multiple step operations during topology updates.
*/
private final Object recordsGuard = new Object();
private final Map<String, MessageFlowRecord> records = new ConcurrentHashMap<>();
private final Map<String, MessageFlowRecord> disconnectedRecords = new ConcurrentHashMap<>();
private final Map<String, MessageFlowRecord> records = new ConcurrentHashMap<>();
private final ScheduledExecutorService scheduledExecutor;