No need to nest in else.
diff --git a/src/main/java/org/apache/commons/net/bsd/RExecClient.java b/src/main/java/org/apache/commons/net/bsd/RExecClient.java
index b16560a..6628989 100644
--- a/src/main/java/org/apache/commons/net/bsd/RExecClient.java
+++ b/src/main/java/org/apache/commons/net/bsd/RExecClient.java
@@ -276,7 +276,8 @@
}
throw new IOException(buffer.toString());
- } else if (ch < 0) {
+ }
+ if (ch < 0) {
throw new IOException("Server closed connection.");
}
}
diff --git a/src/main/java/org/apache/commons/net/examples/ftp/ServerToServerFTP.java b/src/main/java/org/apache/commons/net/examples/ftp/ServerToServerFTP.java
index bb032d7..908dead 100644
--- a/src/main/java/org/apache/commons/net/examples/ftp/ServerToServerFTP.java
+++ b/src/main/java/org/apache/commons/net/examples/ftp/ServerToServerFTP.java
@@ -190,19 +190,15 @@
// transfer is completed (in the case of passive mode transfers).
// Therefore, calling store first would hang waiting for a preliminary
// reply.
- if (ftp1.remoteRetrieve(file1) && ftp2.remoteStoreUnique(file2))
- {
- // if(ftp1.remoteRetrieve(file1) && ftp2.remoteStore(file2)) {
- // We have to fetch the positive completion reply.
- ftp1.completePendingCommand();
- ftp2.completePendingCommand();
- }
- else
- {
+ if (!ftp1.remoteRetrieve(file1) || !ftp2.remoteStoreUnique(file2)) {
System.err.println(
"Couldn't initiate transfer. Check that file names are valid.");
break __main;
}
+ // if(ftp1.remoteRetrieve(file1) && ftp2.remoteStore(file2)) {
+ // We have to fetch the positive completion reply.
+ ftp1.completePendingCommand();
+ ftp2.completePendingCommand();
}
catch (final IOException e)
diff --git a/src/main/java/org/apache/commons/net/examples/ftp/TFTPExample.java b/src/main/java/org/apache/commons/net/examples/ftp/TFTPExample.java
index ea78266..e89936c 100644
--- a/src/main/java/org/apache/commons/net/examples/ftp/TFTPExample.java
+++ b/src/main/java/org/apache/commons/net/examples/ftp/TFTPExample.java
@@ -99,27 +99,26 @@
for (argc = 0; argc < args.length; argc++)
{
arg = args[argc];
- if (arg.startsWith("-")) {
- if (arg.equals("-r")) {
- receiveFile = true;
- } else if (arg.equals("-s")) {
- receiveFile = false;
- } else if (arg.equals("-a")) {
- transferMode = TFTP.ASCII_MODE;
- } else if (arg.equals("-b")) {
- transferMode = TFTP.BINARY_MODE;
- } else if (arg.equals("-t")) {
- timeout = 1000 * Integer.parseInt(args[++argc]);
- } else if (arg.equals("-v")) {
- verbose = true;
- } else {
- System.err.println("Error: unrecognized option.");
- System.err.print(USAGE);
- System.exit(1);
- }
- } else {
+ if (!arg.startsWith("-")) {
break;
}
+ if (arg.equals("-r")) {
+ receiveFile = true;
+ } else if (arg.equals("-s")) {
+ receiveFile = false;
+ } else if (arg.equals("-a")) {
+ transferMode = TFTP.ASCII_MODE;
+ } else if (arg.equals("-b")) {
+ transferMode = TFTP.BINARY_MODE;
+ } else if (arg.equals("-t")) {
+ timeout = 1000 * Integer.parseInt(args[++argc]);
+ } else if (arg.equals("-v")) {
+ verbose = true;
+ } else {
+ System.err.println("Error: unrecognized option.");
+ System.err.print(USAGE);
+ System.exit(1);
+ }
}
// Make sure there are enough arguments
diff --git a/src/main/java/org/apache/commons/net/examples/mail/IMAPExportMbox.java b/src/main/java/org/apache/commons/net/examples/mail/IMAPExportMbox.java
index bfb41f4..60c81f1 100644
--- a/src/main/java/org/apache/commons/net/examples/mail/IMAPExportMbox.java
+++ b/src/main/java/org/apache/commons/net/examples/mail/IMAPExportMbox.java
@@ -287,12 +287,11 @@
uri = URI.create(uriString);
} catch(final IllegalArgumentException e) { // cannot parse the path as is; let's pull it apart and try again
final Matcher m = Pattern.compile("(imaps?://[^/]+)(/.*)").matcher(uriString);
- if (m.matches()) {
- uri = URI.create(m.group(1)); // Just the scheme and auth parts
- uri = new URI(uri.getScheme(), uri.getAuthority(), m.group(2), null, null);
- } else {
+ if (!m.matches()) {
throw e;
}
+ uri = URI.create(m.group(1)); // Just the scheme and auth parts
+ uri = new URI(uri.getScheme(), uri.getAuthority(), m.group(2), null, null);
}
final String file = args[argIdx++];
String sequenceSet = argCount > 2 ? args[argIdx++] : "1:*";
@@ -385,22 +384,20 @@
while (true) {
final boolean ok = imap.fetch(sequenceSet, itemNames);
// If the fetch failed, can we retry?
- if (!ok && retryWaitSecs > 0 && mboxListener != null && checkSequence) {
- final String replyString = imap.getReplyString(); //includes EOL
- if (startsWith(replyString, PATTEMPFAIL)) {
- System.err.println("Temporary error detected, will retry in " + retryWaitSecs + "seconds");
- sequenceSet = mboxListener.lastSeq+1+":*";
- try {
- Thread.sleep(retryWaitSecs * 1000);
- } catch (final InterruptedException e) {
- // ignored
- }
- } else {
- throw new IOException("FETCH " + sequenceSet + " " + itemNames+ " failed with " + replyString);
- }
- } else {
+ if (ok || (retryWaitSecs <= 0) || (mboxListener == null) || !checkSequence) {
break;
}
+ final String replyString = imap.getReplyString(); //includes EOL
+ if (!startsWith(replyString, PATTEMPFAIL)) {
+ throw new IOException("FETCH " + sequenceSet + " " + itemNames+ " failed with " + replyString);
+ }
+ System.err.println("Temporary error detected, will retry in " + retryWaitSecs + "seconds");
+ sequenceSet = mboxListener.lastSeq+1+":*";
+ try {
+ Thread.sleep(retryWaitSecs * 1000);
+ } catch (final InterruptedException e) {
+ // ignored
+ }
}
} catch (final IOException ioe) {
diff --git a/src/main/java/org/apache/commons/net/examples/mail/POP3ExportMbox.java b/src/main/java/org/apache/commons/net/examples/mail/POP3ExportMbox.java
index db3bf93..c6d2adc 100644
--- a/src/main/java/org/apache/commons/net/examples/mail/POP3ExportMbox.java
+++ b/src/main/java/org/apache/commons/net/examples/mail/POP3ExportMbox.java
@@ -54,11 +54,10 @@
int argIdx;
String file = null;
for(argIdx = 0; argIdx < args.length; argIdx++) {
- if (args[argIdx].equals("-F")) {
- file = args[++argIdx];
- } else {
+ if (!args[argIdx].equals("-F")) {
break;
}
+ file = args[++argIdx];
}
final int argCount = args.length - argIdx;
diff --git a/src/main/java/org/apache/commons/net/examples/mail/POP3Mail.java b/src/main/java/org/apache/commons/net/examples/mail/POP3Mail.java
index 5ea2c86..32cf6b5 100644
--- a/src/main/java/org/apache/commons/net/examples/mail/POP3Mail.java
+++ b/src/main/java/org/apache/commons/net/examples/mail/POP3Mail.java
@@ -124,7 +124,7 @@
pop3.disconnect();
return;
}
- else if (messages.length == 0)
+ if (messages.length == 0)
{
System.out.println("No messages");
pop3.logout();
diff --git a/src/main/java/org/apache/commons/net/examples/mail/Utils.java b/src/main/java/org/apache/commons/net/examples/mail/Utils.java
index 6408c10..92bba30 100644
--- a/src/main/java/org/apache/commons/net/examples/mail/Utils.java
+++ b/src/main/java/org/apache/commons/net/examples/mail/Utils.java
@@ -48,12 +48,11 @@
password = in.readLine();
} else if ("*".equals(password)) { // console
final Console con = System.console(); // Java 1.6
- if (con != null) {
- final char[] pwd = con.readPassword("Password for " + username + ": ");
- password = new String(pwd);
- } else {
+ if (con == null) {
throw new IOException("Cannot access Console");
}
+ final char[] pwd = con.readPassword("Password for " + username + ": ");
+ password = new String(pwd);
} else if (password.equals(password.toUpperCase(Locale.ROOT))) { // environment variable name
final String tmp = System.getenv(password);
if (tmp != null) { // don't overwrite if variable does not exist (just in case password is all uppers)
diff --git a/src/main/java/org/apache/commons/net/ftp/FTP.java b/src/main/java/org/apache/commons/net/ftp/FTP.java
index 90fbcb4..5e04b26 100644
--- a/src/main/java/org/apache/commons/net/ftp/FTP.java
+++ b/src/main/java/org/apache/commons/net/ftp/FTP.java
@@ -775,7 +775,8 @@
} else if (isStrictReplyParsing()) {
if (length == REPLY_CODE_LEN + 1) { // expecting some text
throw new MalformedServerReplyException("Truncated server reply: '" + line +"'");
- } else if (sep != ' ') {
+ }
+ if (sep != ' ') {
throw new MalformedServerReplyException("Invalid server reply: '" + line +"'");
}
}
diff --git a/src/main/java/org/apache/commons/net/ftp/FTPClient.java b/src/main/java/org/apache/commons/net/ftp/FTPClient.java
index 389b47a..f2184fe 100644
--- a/src/main/java/org/apache/commons/net/ftp/FTPClient.java
+++ b/src/main/java/org/apache/commons/net/ftp/FTPClient.java
@@ -2110,11 +2110,10 @@
} else {
// Check if the user has provided a default for when the SYST command fails
final String systDefault = System.getProperty(FTP_SYSTEM_TYPE_DEFAULT);
- if (systDefault != null) {
- systemName = systDefault;
- } else {
+ if (systDefault == null) {
throw new IOException("Unable to determine system type - response: " + getReplyString());
}
+ systemName = systDefault;
}
}
return systemName;
diff --git a/src/main/java/org/apache/commons/net/ftp/FTPClientConfig.java b/src/main/java/org/apache/commons/net/ftp/FTPClientConfig.java
index 8790167..ac07afb 100644
--- a/src/main/java/org/apache/commons/net/ftp/FTPClientConfig.java
+++ b/src/main/java/org/apache/commons/net/ftp/FTPClientConfig.java
@@ -294,7 +294,8 @@
if (lang != null) {
if (lang instanceof Locale) {
return new DateFormatSymbols((Locale) lang);
- } else if (lang instanceof String){
+ }
+ if (lang instanceof String){
return getDateFormatSymbols((String) lang);
}
}
diff --git a/src/main/java/org/apache/commons/net/ftp/FTPHTTPClient.java b/src/main/java/org/apache/commons/net/ftp/FTPHTTPClient.java
index 8e1ab42..c642eb1 100644
--- a/src/main/java/org/apache/commons/net/ftp/FTPHTTPClient.java
+++ b/src/main/java/org/apache/commons/net/ftp/FTPHTTPClient.java
@@ -220,11 +220,10 @@
String code = null;
final String resp = response.get(0);
- if (resp.startsWith("HTTP/") && resp.length() >= 12) {
- code = resp.substring(9, 12);
- } else {
+ if (!resp.startsWith("HTTP/") || (resp.length() < 12)) {
throw new IOException("Invalid response from proxy: " + resp);
}
+ code = resp.substring(9, 12);
if (!"200".equals(code)) {
final StringBuilder msg = new StringBuilder();
diff --git a/src/main/java/org/apache/commons/net/ftp/FTPSClient.java b/src/main/java/org/apache/commons/net/ftp/FTPSClient.java
index c5c0f45..9c1ee80 100644
--- a/src/main/java/org/apache/commons/net/ftp/FTPSClient.java
+++ b/src/main/java/org/apache/commons/net/ftp/FTPSClient.java
@@ -741,18 +741,17 @@
final int repCode = super.sendCommand(command, args);
/* If CCC is issued, restore socket i/o streams to unsecured versions */
if (CMD_CCC.equals(command)) {
- if (FTPReply.COMMAND_OK == repCode) {
- _socket_.close();
- _socket_ = plainSocket;
- _controlInput_ = new BufferedReader(
- new InputStreamReader(
- _socket_ .getInputStream(), getControlEncoding()));
- _controlOutput_ = new BufferedWriter(
- new OutputStreamWriter(
- _socket_.getOutputStream(), getControlEncoding()));
- } else {
+ if (FTPReply.COMMAND_OK != repCode) {
throw new SSLException(getReplyString());
}
+ _socket_.close();
+ _socket_ = plainSocket;
+ _controlInput_ = new BufferedReader(
+ new InputStreamReader(
+ _socket_ .getInputStream(), getControlEncoding()));
+ _controlOutput_ = new BufferedWriter(
+ new OutputStreamWriter(
+ _socket_.getOutputStream(), getControlEncoding()));
}
return repCode;
}
diff --git a/src/main/java/org/apache/commons/net/ftp/parser/FTPTimestampParserImpl.java b/src/main/java/org/apache/commons/net/ftp/parser/FTPTimestampParserImpl.java
index 648fd5a..f2a3945 100644
--- a/src/main/java/org/apache/commons/net/ftp/parser/FTPTimestampParserImpl.java
+++ b/src/main/java/org/apache/commons/net/ftp/parser/FTPTimestampParserImpl.java
@@ -335,14 +335,13 @@
// a valid year (e.g. 22:04 will parse as 22 A.D.)
// so could mistakenly confuse an hour with a year,
// if we don't insist on full length parsing.
- if (parsed != null && pp.getIndex() == timestampStr.length()) {
- working.setTime(parsed);
- } else {
+ if ((parsed == null) || (pp.getIndex() != timestampStr.length())) {
throw new ParseException(
"Timestamp '"+timestampStr+"' could not be parsed using a server time of "
+serverTime.getTime().toString(),
pp.getErrorIndex());
}
+ working.setTime(parsed);
setPrecision(defaultDateSmallestUnitIndex, working);
return working;
}
diff --git a/src/main/java/org/apache/commons/net/ftp/parser/MVSFTPEntryParser.java b/src/main/java/org/apache/commons/net/ftp/parser/MVSFTPEntryParser.java
index fa06533..a84f77e 100644
--- a/src/main/java/org/apache/commons/net/ftp/parser/MVSFTPEntryParser.java
+++ b/src/main/java/org/apache/commons/net/ftp/parser/MVSFTPEntryParser.java
@@ -325,13 +325,17 @@
public FTPFile parseFTPEntry(final String entry) {
if (isType == FILE_LIST_TYPE) {
return parseFileList(entry);
- } else if (isType == MEMBER_LIST_TYPE) {
+ }
+ if (isType == MEMBER_LIST_TYPE) {
return parseMemberList(entry);
- } else if (isType == UNIX_LIST_TYPE) {
+ }
+ if (isType == UNIX_LIST_TYPE) {
return unixFTPEntryParser.parseFTPEntry(entry);
- } else if (isType == JES_LEVEL_1_LIST_TYPE) {
+ }
+ if (isType == JES_LEVEL_1_LIST_TYPE) {
return parseJeslevel1List(entry);
- } else if (isType == JES_LEVEL_2_LIST_TYPE) {
+ }
+ if (isType == JES_LEVEL_2_LIST_TYPE) {
return parseJeslevel2List(entry);
}
diff --git a/src/main/java/org/apache/commons/net/ftp/parser/OS400FTPEntryParser.java b/src/main/java/org/apache/commons/net/ftp/parser/OS400FTPEntryParser.java
index 3e15035..3b6921b 100644
--- a/src/main/java/org/apache/commons/net/ftp/parser/OS400FTPEntryParser.java
+++ b/src/main/java/org/apache/commons/net/ftp/parser/OS400FTPEntryParser.java
@@ -363,15 +363,11 @@
// file.
// Save files are a special type of files which are used
// to save objects, e.g. for backups.
- if (name != null && name.toUpperCase(Locale.ROOT).endsWith(".SAVF"))
- {
- mustScanForPathSeparator = false;
- type = FTPFile.FILE_TYPE;
- }
- else
- {
+ if ((name == null) || !name.toUpperCase(Locale.ROOT).endsWith(".SAVF")) {
return null;
}
+ mustScanForPathSeparator = false;
+ type = FTPFile.FILE_TYPE;
}
else if (typeStr.equalsIgnoreCase("*MEM"))
{
diff --git a/src/main/java/org/apache/commons/net/io/FromNetASCIIInputStream.java b/src/main/java/org/apache/commons/net/io/FromNetASCIIInputStream.java
index 4d5658c..4503cdf 100644
--- a/src/main/java/org/apache/commons/net/io/FromNetASCIIInputStream.java
+++ b/src/main/java/org/apache/commons/net/io/FromNetASCIIInputStream.java
@@ -196,20 +196,16 @@
if (ch == '\r')
{
ch = super.read();
- if (ch == '\n')
- {
- unread(_lineSeparatorBytes);
- ch = super.read();
- // This is a kluge for read(byte[], ...) to read the right amount
- --length;
- }
- else
- {
+ if (ch != '\n') {
if (ch != -1) {
unread(ch);
}
return '\r';
}
+ unread(_lineSeparatorBytes);
+ ch = super.read();
+ // This is a kluge for read(byte[], ...) to read the right amount
+ --length;
}
return ch;
diff --git a/src/main/java/org/apache/commons/net/nntp/NNTPClient.java b/src/main/java/org/apache/commons/net/nntp/NNTPClient.java
index c812c43..806fcc7 100644
--- a/src/main/java/org/apache/commons/net/nntp/NNTPClient.java
+++ b/src/main/java/org/apache/commons/net/nntp/NNTPClient.java
@@ -790,11 +790,10 @@
try (final BufferedReader reader = new DotTerminatedMessageReader(_reader_)) {
while ((line = reader.readLine()) != null) {
final NewsgroupInfo tmp = parseNewsgroupListEntry(line);
- if (tmp != null) {
- list.addElement(tmp);
- } else {
+ if (tmp == null) {
throw new MalformedServerReplyException(line);
}
+ list.addElement(tmp);
}
}
final int size;
diff --git a/src/main/java/org/apache/commons/net/nntp/ThreadContainer.java b/src/main/java/org/apache/commons/net/nntp/ThreadContainer.java
index 0e7a9ed..97e7ba1 100644
--- a/src/main/java/org/apache/commons/net/nntp/ThreadContainer.java
+++ b/src/main/java/org/apache/commons/net/nntp/ThreadContainer.java
@@ -39,11 +39,11 @@
boolean findChild(final ThreadContainer target) {
if (child == null) {
return false;
- } else if (child == target) {
- return true;
- } else {
- return child.findChild(target);
}
+ if (child == target) {
+ return true;
+ }
+ return child.findChild(target);
}
// Copy the ThreadContainer tree structure down into the underlying Threadable objects
diff --git a/src/main/java/org/apache/commons/net/smtp/AuthenticatingSMTPClient.java b/src/main/java/org/apache/commons/net/smtp/AuthenticatingSMTPClient.java
index 263ed30..6204ccd 100644
--- a/src/main/java/org/apache/commons/net/smtp/AuthenticatingSMTPClient.java
+++ b/src/main/java/org/apache/commons/net/smtp/AuthenticatingSMTPClient.java
@@ -63,17 +63,20 @@
{
if (method.equals(AUTH_METHOD.PLAIN)) {
return "PLAIN";
- } else if (method.equals(AUTH_METHOD.CRAM_MD5)) {
- return "CRAM-MD5";
- } else if (method.equals(AUTH_METHOD.LOGIN)) {
- return "LOGIN";
- } else if (method.equals(AUTH_METHOD.XOAUTH)) {
- return "XOAUTH";
- } else if (method.equals(AUTH_METHOD.XOAUTH2)) {
- return "XOAUTH2";
- } else {
- return null;
}
+ if (method.equals(AUTH_METHOD.CRAM_MD5)) {
+ return "CRAM-MD5";
+ }
+ if (method.equals(AUTH_METHOD.LOGIN)) {
+ return "LOGIN";
+ }
+ if (method.equals(AUTH_METHOD.XOAUTH)) {
+ return "XOAUTH";
+ }
+ if (method.equals(AUTH_METHOD.XOAUTH2)) {
+ return "XOAUTH2";
+ }
+ return null;
}
}
@@ -180,7 +183,7 @@
Base64.encodeBase64StringUnChunked(("\000" + username + "\000" + password).getBytes(getCharset()))
));
}
- else if (method.equals(AUTH_METHOD.CRAM_MD5))
+ if (method.equals(AUTH_METHOD.CRAM_MD5))
{
// get the CRAM challenge
final byte[] serverChallenge = Base64.decodeBase64(getReplyString().substring(4).trim());
@@ -199,7 +202,7 @@
return SMTPReply.isPositiveCompletion(sendCommand(
Base64.encodeBase64StringUnChunked(toEncode)));
}
- else if (method.equals(AUTH_METHOD.LOGIN))
+ if (method.equals(AUTH_METHOD.LOGIN))
{
// the server sends fixed responses (base64("Username") and
// base64("Password")), so we don't have to read them.
@@ -210,14 +213,13 @@
return SMTPReply.isPositiveCompletion(sendCommand(
Base64.encodeBase64StringUnChunked(password.getBytes(getCharset()))));
}
- else if (method.equals(AUTH_METHOD.XOAUTH) || method.equals(AUTH_METHOD.XOAUTH2))
+ if (method.equals(AUTH_METHOD.XOAUTH) || method.equals(AUTH_METHOD.XOAUTH2))
{
return SMTPReply.isPositiveIntermediate(sendCommand(
Base64.encodeBase64StringUnChunked(username.getBytes(getCharset()))
));
- } else {
- return false; // safety check
}
+ return false; // safety check
}
diff --git a/src/main/java/org/apache/commons/net/telnet/Telnet.java b/src/main/java/org/apache/commons/net/telnet/Telnet.java
index 65b9185..ac0a2da 100644
--- a/src/main/java/org/apache/commons/net/telnet/Telnet.java
+++ b/src/main/java/org/apache/commons/net/telnet/Telnet.java
@@ -332,35 +332,27 @@
throws InvalidTelnetOptionException, IOException
{
final int optcode = opthand.getOptionCode();
- if (TelnetOption.isValidOption(optcode))
- {
- if (optionHandlers[optcode] == null)
- {
- optionHandlers[optcode] = opthand;
- if (isConnected())
- {
- if (opthand.getInitLocal())
- {
- requestWill(optcode);
- }
-
- if (opthand.getInitRemote())
- {
- requestDo(optcode);
- }
- }
- }
- else
- {
- throw new InvalidTelnetOptionException(
- "Already registered option", optcode);
- }
- }
- else
- {
+ if (!TelnetOption.isValidOption(optcode)) {
throw new InvalidTelnetOptionException(
"Invalid Option Code", optcode);
}
+ if (optionHandlers[optcode] != null) {
+ throw new InvalidTelnetOptionException(
+ "Already registered option", optcode);
+ }
+ optionHandlers[optcode] = opthand;
+ if (isConnected())
+ {
+ if (opthand.getInitLocal())
+ {
+ requestWill(optcode);
+ }
+
+ if (opthand.getInitRemote())
+ {
+ requestDo(optcode);
+ }
+ }
}
/**
@@ -373,31 +365,27 @@
void deleteOptionHandler(final int optcode)
throws InvalidTelnetOptionException, IOException
{
- if (TelnetOption.isValidOption(optcode))
- {
- if (optionHandlers[optcode] == null)
- {
- throw new InvalidTelnetOptionException(
- "Unregistered option", optcode);
- }
- final TelnetOptionHandler opthand = optionHandlers[optcode];
- optionHandlers[optcode] = null;
-
- if (opthand.getWill())
- {
- requestWont(optcode);
- }
-
- if (opthand.getDo())
- {
- requestDont(optcode);
- }
- }
- else
- {
+ if (!TelnetOption.isValidOption(optcode)) {
throw new InvalidTelnetOptionException(
"Invalid Option Code", optcode);
}
+ if (optionHandlers[optcode] == null)
+ {
+ throw new InvalidTelnetOptionException(
+ "Unregistered option", optcode);
+ }
+ final TelnetOptionHandler opthand = optionHandlers[optcode];
+ optionHandlers[optcode] = null;
+
+ if (opthand.getWill())
+ {
+ requestWont(optcode);
+ }
+
+ if (opthand.getDo())
+ {
+ requestDont(optcode);
+ }
}
/* open TelnetOptionHandler functionality (end)*/
diff --git a/src/main/java/org/apache/commons/net/telnet/TelnetInputStream.java b/src/main/java/org/apache/commons/net/telnet/TelnetInputStream.java
index e562ef1..ca873a6 100644
--- a/src/main/java/org/apache/commons/net/telnet/TelnetInputStream.java
+++ b/src/main/java/org/apache/commons/net/telnet/TelnetInputStream.java
@@ -143,24 +143,20 @@
{
// The queue is full. We need to wait before adding any more data to it. Hopefully the stream owner
// will consume some data soon!
- if(threaded)
- {
- queue.notify();
- try
- {
- queue.wait();
- }
- catch (final InterruptedException e)
- {
- throw e;
- }
- }
- else
- {
+ if(!threaded) {
// We've been asked to add another character to the queue, but it is already full and there's
// no other thread to drain it. This should not have happened!
throw new IllegalStateException("Queue is full! Cannot process another character.");
}
+ queue.notify();
+ try
+ {
+ queue.wait();
+ }
+ catch (final InterruptedException e)
+ {
+ throw e;
+ }
}
// Need to do this in case we're not full, but block on a read
diff --git a/src/main/java/org/apache/commons/net/util/SubnetUtils.java b/src/main/java/org/apache/commons/net/util/SubnetUtils.java
index 4553357..359ee7e 100644
--- a/src/main/java/org/apache/commons/net/util/SubnetUtils.java
+++ b/src/main/java/org/apache/commons/net/util/SubnetUtils.java
@@ -284,30 +284,29 @@
public SubnetUtils(final String cidrNotation) {
final Matcher matcher = cidrPattern.matcher(cidrNotation);
- if (matcher.matches()) {
- this.address = matchAddress(matcher);
-
- /* Create a binary netmask from the number of bits specification /x */
-
- final int trailingZeroes = NBITS - rangeCheck(Integer.parseInt(matcher.group(5)), 0, NBITS);
- /*
- * An IPv4 netmask consists of 32 bits, a contiguous sequence
- * of the specified number of ones followed by all zeros.
- * So, it can be obtained by shifting an unsigned integer (32 bits) to the left by
- * the number of trailing zeros which is (32 - the # bits specification).
- * Note that there is no unsigned left shift operator, so we have to use
- * a long to ensure that the left-most bit is shifted out correctly.
- */
- this.netmask = (int) (0x0FFFFFFFFL << trailingZeroes );
-
- /* Calculate base network address */
- this.network = address & netmask;
-
- /* Calculate broadcast address */
- this.broadcast = network | ~netmask;
- } else {
+ if (!matcher.matches()) {
throw new IllegalArgumentException(String.format(PARSE_FAIL, cidrNotation));
}
+ this.address = matchAddress(matcher);
+
+ /* Create a binary netmask from the number of bits specification /x */
+
+ final int trailingZeroes = NBITS - rangeCheck(Integer.parseInt(matcher.group(5)), 0, NBITS);
+ /*
+ * An IPv4 netmask consists of 32 bits, a contiguous sequence
+ * of the specified number of ones followed by all zeros.
+ * So, it can be obtained by shifting an unsigned integer (32 bits) to the left by
+ * the number of trailing zeros which is (32 - the # bits specification).
+ * Note that there is no unsigned left shift operator, so we have to use
+ * a long to ensure that the left-most bit is shifted out correctly.
+ */
+ this.netmask = (int) (0x0FFFFFFFFL << trailingZeroes );
+
+ /* Calculate base network address */
+ this.network = address & netmask;
+
+ /* Calculate broadcast address */
+ this.broadcast = network | ~netmask;
}
/**
diff --git a/src/test/java/org/apache/commons/net/tftp/TFTPServer.java b/src/test/java/org/apache/commons/net/tftp/TFTPServer.java
index 20ce11f..21f6fa8 100644
--- a/src/test/java/org/apache/commons/net/tftp/TFTPServer.java
+++ b/src/test/java/org/apache/commons/net/tftp/TFTPServer.java
@@ -140,23 +140,19 @@
createDirectory(parent);
}
- if (parent.isDirectory())
- {
- if (file.isDirectory())
- {
- return;
- }
- final boolean result = file.mkdir();
- if (!result)
- {
- throw new IOException("Couldn't create requested directory");
- }
- }
- else
- {
+ if (!parent.isDirectory()) {
throw new IOException(
"Invalid directory path - file in the way of requested folder");
}
+ if (file.isDirectory())
+ {
+ return;
+ }
+ final boolean result = file.mkdir();
+ if (!result)
+ {
+ throw new IOException("Couldn't create requested directory");
+ }
}
/*
diff --git a/src/test/java/org/apache/commons/net/tftp/TFTPServerMain.java b/src/test/java/org/apache/commons/net/tftp/TFTPServerMain.java
index 1d8bdc3..0fd10da 100644
--- a/src/test/java/org/apache/commons/net/tftp/TFTPServerMain.java
+++ b/src/test/java/org/apache/commons/net/tftp/TFTPServerMain.java
@@ -47,20 +47,18 @@
for (argc = 0; argc < args.length; argc++)
{
final String arg = args[argc];
- if (arg.startsWith("-"))
- {
- if (arg.equals("-v") || arg.equals("-r")) {
- opts.put(arg, arg);
- } else if (arg.equals("-p")) {
- opts.put(arg, args[++argc]);
- } else {
- System.err.println("Error: unrecognized option.");
- System.err.print(USAGE);
- System.exit(1);
- }
- } else {
+ if (!arg.startsWith("-")) {
break;
}
+ if (arg.equals("-v") || arg.equals("-r")) {
+ opts.put(arg, arg);
+ } else if (arg.equals("-p")) {
+ opts.put(arg, args[++argc]);
+ } else {
+ System.err.println("Error: unrecognized option.");
+ System.err.print(USAGE);
+ System.exit(1);
+ }
}
if (argc < args.length) {