Skip to content

Commit

Permalink
address some LGTM reported issues and other inspections (#188)
Browse files Browse the repository at this point in the history
* make package privat and remove redundant returns and var initialization

* use parametrized constructor

addresses #172

* LGTM - This check is useless, myfilereader cannot be null here, since new BufferedReader(...) always is non-null.

* LGTM - This FileOutputStream is not always closed on method exit.

* LGTM - The variable 'tmp' is only assigned values of primitive type and is never 'null', but it is declared with the boxed type 'Integer'.
  • Loading branch information
Pitterling committed Sep 8, 2019
1 parent e94f191 commit dea8d8b
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 24 deletions.
34 changes: 12 additions & 22 deletions src/main/java/net/atomique/ksar/LocalCommand.java
Expand Up @@ -22,16 +22,15 @@ public class LocalCommand extends Thread {

private static final Logger log = LoggerFactory.getLogger(LocalCommand.class);

public LocalCommand(kSar hissar) {
LocalCommand(kSar hissar) {
mysar = hissar;
try {
command = JOptionPane.showInputDialog(GlobalOptions.getUI(), "Enter local command ", "sar -A");
if (command == null) {
return;
}
String[] cmdArray = command.split(" +");
List<String> cmdList = new ArrayList<String>();
cmdList.addAll(Arrays.asList(cmdArray));
List<String> cmdList = new ArrayList<>(Arrays.asList(cmdArray));
ProcessBuilder pb = new ProcessBuilder(cmdList);
pb.environment().put("LC_ALL", "C");
p = pb.start();
Expand All @@ -42,10 +41,9 @@ public LocalCommand(kSar hissar) {
in = null;
}

return;
}

public LocalCommand(kSar hissar, String hiscommand) {
LocalCommand(kSar hissar, String hiscommand) {
mysar = hissar;
command = hiscommand;
try {
Expand All @@ -66,50 +64,42 @@ public LocalCommand(kSar hissar, String hiscommand) {
in = null;
}

return;
}

private void close() {
if (p != null) {
p.destroy();
}

try {
if (myfilereader != null) {
myfilereader.close();
}
} catch (IOException ex) {
log.error("IO Exception", ex);
}
}

public void run() {
String current_line;

if (in == null) {
return;
}
myfilereader = new BufferedReader(new InputStreamReader(in));
if (myfilereader == null) {
return;

try {
BufferedReader myfilereader = new BufferedReader(new InputStreamReader(in));
mysar.parse(myfilereader);
myfilereader.close();
} catch (IOException ex) {
log.error("IO Exception", ex);
}

mysar.parse(myfilereader);

close();
}

public String get_action() {
String get_action() {
if (command != null) {
return "cmd://" + command;
} else {
return null;
}
}

private kSar mysar = null;
private kSar mysar;
private InputStream in = null;
private String command = null;
private BufferedReader myfilereader = null;
private Process p = null;
}
1 change: 1 addition & 0 deletions src/main/java/net/atomique/ksar/export/FilePDF.java
Expand Up @@ -118,6 +118,7 @@ public void run() {
export_treenode(mysar.graphtree, root);

document.close();
writer.close();

if (dialog != null) {
dialog.dispose();
Expand Down
3 changes: 1 addition & 2 deletions src/main/java/net/atomique/ksar/xml/CnxHistory.java
Expand Up @@ -62,8 +62,7 @@ public String getPort() {
}

public int getPortInt() {
Integer tmp = Integer.parseInt(port);
return tmp.intValue();
return Integer.parseInt(port);
}

public void setPort(String port) {
Expand Down

0 comments on commit dea8d8b

Please sign in to comment.