Fix criticals sonar issues
Signed-off-by: SirWayne <dennis.melzer@bosch-si.com>
This commit is contained in:
@@ -14,7 +14,7 @@ import java.net.ServerSocket;
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* Look for a free port.
|
||||
*/
|
||||
public class FreePortFileWriter {
|
||||
|
||||
@@ -24,7 +24,9 @@ public class FreePortFileWriter {
|
||||
|
||||
/**
|
||||
* @param from
|
||||
* port range from (start point)
|
||||
* @param to
|
||||
* port range to (end point)
|
||||
*/
|
||||
public FreePortFileWriter(final int from, final int to, final String filePortPath) {
|
||||
this.from = from;
|
||||
@@ -51,25 +53,21 @@ public class FreePortFileWriter {
|
||||
portFile.getParentFile().mkdirs();
|
||||
if (portFile.exists()) {
|
||||
return false;
|
||||
} else {
|
||||
boolean isFree = false;
|
||||
final ServerSocket sock = new ServerSocket();
|
||||
sock.setReuseAddress(true);
|
||||
sock.bind(new InetSocketAddress(port));
|
||||
if (portFile.createNewFile()) {
|
||||
portFile.deleteOnExit();
|
||||
isFree = true;
|
||||
}
|
||||
sock.close();
|
||||
// is free:
|
||||
return isFree;
|
||||
// We rely on an exception thrown to determine availability or
|
||||
// not availability.
|
||||
}
|
||||
} catch (final Exception e) {
|
||||
// not free.
|
||||
boolean isFree = false;
|
||||
final ServerSocket sock = new ServerSocket();
|
||||
sock.setReuseAddress(true);
|
||||
sock.bind(new InetSocketAddress(port));
|
||||
if (portFile.createNewFile()) {
|
||||
portFile.deleteOnExit();
|
||||
isFree = true;
|
||||
}
|
||||
sock.close();
|
||||
return isFree;
|
||||
// We rely on an exception thrown to determine availability or
|
||||
// not availability and don't want to log the exception.
|
||||
} catch (@SuppressWarnings({ "squid:S2221", "squid:S1166" }) final Exception e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user