Skip to content

Commit dea8d8b

Browse files
authored
address some LGTM reported issues and other inspections (#188)
* 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'.
1 parent e94f191 commit dea8d8b

File tree

3 files changed

+14
-24
lines changed

3 files changed

+14
-24
lines changed

src/main/java/net/atomique/ksar/LocalCommand.java

+12-22
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,15 @@ public class LocalCommand extends Thread {
2222

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

25-
public LocalCommand(kSar hissar) {
25+
LocalCommand(kSar hissar) {
2626
mysar = hissar;
2727
try {
2828
command = JOptionPane.showInputDialog(GlobalOptions.getUI(), "Enter local command ", "sar -A");
2929
if (command == null) {
3030
return;
3131
}
3232
String[] cmdArray = command.split(" +");
33-
List<String> cmdList = new ArrayList<String>();
34-
cmdList.addAll(Arrays.asList(cmdArray));
33+
List<String> cmdList = new ArrayList<>(Arrays.asList(cmdArray));
3534
ProcessBuilder pb = new ProcessBuilder(cmdList);
3635
pb.environment().put("LC_ALL", "C");
3736
p = pb.start();
@@ -42,10 +41,9 @@ public LocalCommand(kSar hissar) {
4241
in = null;
4342
}
4443

45-
return;
4644
}
4745

48-
public LocalCommand(kSar hissar, String hiscommand) {
46+
LocalCommand(kSar hissar, String hiscommand) {
4947
mysar = hissar;
5048
command = hiscommand;
5149
try {
@@ -66,50 +64,42 @@ public LocalCommand(kSar hissar, String hiscommand) {
6664
in = null;
6765
}
6866

69-
return;
7067
}
7168

7269
private void close() {
7370
if (p != null) {
7471
p.destroy();
7572
}
76-
77-
try {
78-
if (myfilereader != null) {
79-
myfilereader.close();
80-
}
81-
} catch (IOException ex) {
82-
log.error("IO Exception", ex);
83-
}
8473
}
8574

8675
public void run() {
87-
String current_line;
8876

8977
if (in == null) {
9078
return;
9179
}
92-
myfilereader = new BufferedReader(new InputStreamReader(in));
93-
if (myfilereader == null) {
94-
return;
80+
81+
try {
82+
BufferedReader myfilereader = new BufferedReader(new InputStreamReader(in));
83+
mysar.parse(myfilereader);
84+
myfilereader.close();
85+
} catch (IOException ex) {
86+
log.error("IO Exception", ex);
9587
}
9688

97-
mysar.parse(myfilereader);
9889

9990
close();
10091
}
10192

102-
public String get_action() {
93+
String get_action() {
10394
if (command != null) {
10495
return "cmd://" + command;
10596
} else {
10697
return null;
10798
}
10899
}
109100

110-
private kSar mysar = null;
101+
private kSar mysar;
111102
private InputStream in = null;
112103
private String command = null;
113-
private BufferedReader myfilereader = null;
114104
private Process p = null;
115105
}

src/main/java/net/atomique/ksar/export/FilePDF.java

+1
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ public void run() {
118118
export_treenode(mysar.graphtree, root);
119119

120120
document.close();
121+
writer.close();
121122

122123
if (dialog != null) {
123124
dialog.dispose();

src/main/java/net/atomique/ksar/xml/CnxHistory.java

+1-2
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,7 @@ public String getPort() {
6262
}
6363

6464
public int getPortInt() {
65-
Integer tmp = Integer.parseInt(port);
66-
return tmp.intValue();
65+
return Integer.parseInt(port);
6766
}
6867

6968
public void setPort(String port) {

0 commit comments

Comments
 (0)