Skip to content

Commit

Permalink
sonar :: remove unnecessary boxing/unboxing (bug) (#422)
Browse files Browse the repository at this point in the history
  • Loading branch information
dev-mlb committed Apr 21, 2023
1 parent 66f7a88 commit 80cee42
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 30 deletions.
24 changes: 12 additions & 12 deletions src/main/java/emissary/client/EmissaryClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@ public class EmissaryClient {

public static final String DEFAULT_CONTEXT = "emissary";
public static final String JETTY_USER_FILE_PROPERTY_NAME = "emissary.jetty.users.file";
public static final Long DEFAULT_CONNECTION_TIMEOUT = TimeUnit.MINUTES.toMillis(100L); // 2 X 50 min
public static final Long DEFAULT_CONNECTION_MANAGER_TIMEOUT = TimeUnit.MINUTES.toMicros(2L);
public static final Long DEFAULT_SO_TIMEOUT = TimeUnit.MINUTES.toMillis(1L);
public static final int DEFAULT_CONNECTION_TIMEOUT = (int) TimeUnit.MINUTES.toMillis(100L); // 2 X 50 min
public static final int DEFAULT_CONNECTION_MANAGER_TIMEOUT = (int) TimeUnit.MINUTES.toMicros(2L);
public static final int DEFAULT_SO_TIMEOUT = (int) TimeUnit.MINUTES.toMillis(1L);
public static final int DEFAULT_RETRIES = 3;
public static final String DEFAULT_USERNAME = "emissary";
public static final String DEFAULT_PASSWORD = "password";
Expand All @@ -68,11 +68,11 @@ public class EmissaryClient {
protected static String username = DEFAULT_USERNAME;
protected static String realm = AuthScope.ANY_REALM;
// How long to wait while establishing a connection (ms)
protected static long connectionTimeout = DEFAULT_CONNECTION_TIMEOUT;
protected static int connectionTimeout = DEFAULT_CONNECTION_TIMEOUT;
// How long to wait for a connection from the pool (ms)
protected static long connectionManagerTimeout = DEFAULT_CONNECTION_MANAGER_TIMEOUT;
protected static int connectionManagerTimeout = DEFAULT_CONNECTION_MANAGER_TIMEOUT;
// How long to wait on a data read in a connection (ms)
protected static long socketTimeout = DEFAULT_SO_TIMEOUT;
protected static int socketTimeout = DEFAULT_SO_TIMEOUT;
// class is thread-safe
protected static final AuthCache AUTH_CACHE = new BasicAuthCache();

Expand All @@ -92,9 +92,9 @@ protected static void configure() {
final Configurator c = ConfigUtil.getConfigInfo(EmissaryClient.class);
retries = c.findIntEntry("retries", DEFAULT_RETRIES);
username = c.findStringEntry("username", DEFAULT_USERNAME);
connectionTimeout = c.findLongEntry("connectionTimeout", DEFAULT_CONNECTION_TIMEOUT);
connectionManagerTimeout = c.findLongEntry("connectionManagerTimeout", DEFAULT_CONNECTION_MANAGER_TIMEOUT);
socketTimeout = c.findLongEntry("soTimeout", DEFAULT_SO_TIMEOUT);
connectionTimeout = c.findIntEntry("connectionTimeout", DEFAULT_CONNECTION_TIMEOUT);
connectionManagerTimeout = c.findIntEntry("connectionManagerTimeout", DEFAULT_CONNECTION_MANAGER_TIMEOUT);
socketTimeout = c.findIntEntry("soTimeout", DEFAULT_SO_TIMEOUT);
CONTEXT = c.findStringEntry("context", DEFAULT_CONTEXT);
} catch (IOException iox) {
LOGGER.warn("Cannot read EmissaryClient properties, configuring defaults: {}", iox.getMessage());
Expand Down Expand Up @@ -135,9 +135,9 @@ protected static void configure() {
}

staticRequestConfig =
RequestConfig.custom().setConnectTimeout(Long.valueOf(connectionTimeout).intValue())
.setConnectionRequestTimeout(Long.valueOf(connectionManagerTimeout).intValue())
.setSocketTimeout(Long.valueOf(socketTimeout).intValue())
RequestConfig.custom().setConnectTimeout(connectionTimeout)
.setConnectionRequestTimeout(connectionManagerTimeout)
.setSocketTimeout(socketTimeout)
.setTargetPreferredAuthSchemes(Collections.singleton(AuthSchemes.DIGEST))
.setProxyPreferredAuthSchemes(Collections.singleton(AuthSchemes.DIGEST))
.build();
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/emissary/server/EmissaryServer.java
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ public Server startServer() {
server.setHandler(handlers);
server.addBean(loginService);
server.setStopAtShutdown(true);
server.setStopTimeout(10000l);
server.setStopTimeout(10000L);
if (this.cmd.shouldDumpJettyBeans()) {
LOG.info(server.dump());
}
Expand Down Expand Up @@ -609,7 +609,7 @@ protected Server configureServer() throws IOException, GeneralSecurityException
int minThreads = 10;
int lowThreads = 50;
int threadsPriority = 9;
int idleTimeout = new Long(TimeUnit.MINUTES.toMillis(15)).intValue();
int idleTimeout = (int) TimeUnit.MINUTES.toMillis(15);

QueuedThreadPool threadPool = new QueuedThreadPool(maxThreads, minThreads, idleTimeout);
threadPool.setLowThreadsThreshold(lowThreads);
Expand Down
22 changes: 11 additions & 11 deletions src/main/java/emissary/util/magic/MagicMath.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,34 +60,34 @@ public static byte[] parseEscapedString(String s) {
while (!chars.empty()) {
Character c = chars.pop();
String val = EMPTYSTRING;
if (c.charValue() == '\\') {
if (c == '\\') {
if (chars.empty()) {
array.add(Integer.valueOf(32));
array.add(32);
break;
}
Character next = chars.peek();
if (literals[next.charValue()] > 0) {
array.add(literals[next.charValue()]);
if (literals[next] > 0) {
array.add(literals[next]);
chars.pop();
} else if (Character.isDigit(next.charValue())) {
} else if (Character.isDigit(next)) {
int max = 3;
while (!chars.empty() && Character.isDigit(next.charValue()) && max-- > 0) {
val += chars.pop().charValue();
while (!chars.empty() && Character.isDigit(next) && max-- > 0) {
val += chars.pop();
if (!chars.empty())
next = chars.peek();
}
array.add(new BigInteger(val, 8));
val = EMPTYSTRING;
} else if (next.charValue() == 'x') {
} else if (next == 'x') {
chars.pop(); // pop the hex symbol
val += (chars.pop()).charValue();
val += (chars.pop()).charValue();
val += chars.pop();
val += chars.pop();
array.add(new BigInteger(val, 16));
val = EMPTYSTRING;
}
continue;
}
array.add(Integer.valueOf(c.charValue()));
array.add((int) c);
}
byte[] bytes = new byte[array.size()];
Iterator<Number> iter = array.iterator();
Expand Down
10 changes: 5 additions & 5 deletions src/test/java/emissary/client/EmissaryClientTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ void testDefaultRequestConfig() {
EmissaryClient.configure();
EmissaryClient client = new EmissaryClient();
RequestConfig requestConfig = client.getRequestConfig();
assertEquals(EmissaryClient.DEFAULT_CONNECTION_TIMEOUT.intValue(), requestConfig.getConnectTimeout());
assertEquals(EmissaryClient.DEFAULT_CONNECTION_MANAGER_TIMEOUT.intValue(), requestConfig.getConnectionRequestTimeout());
assertEquals(EmissaryClient.DEFAULT_SO_TIMEOUT.intValue(), requestConfig.getSocketTimeout());
assertEquals(EmissaryClient.DEFAULT_CONNECTION_TIMEOUT, requestConfig.getConnectTimeout());
assertEquals(EmissaryClient.DEFAULT_CONNECTION_MANAGER_TIMEOUT, requestConfig.getConnectionRequestTimeout());
assertEquals(EmissaryClient.DEFAULT_SO_TIMEOUT, requestConfig.getSocketTimeout());
} catch (IOException e) {
logger.error("Problem moving {}", origCfg.toAbsolutePath(), e);
} finally {
Expand Down Expand Up @@ -98,9 +98,9 @@ void testPassingInRequestConfig() {
EmissaryClient client = new EmissaryClient();
RequestConfig requestConfig = client.getRequestConfig();
// initial value from config file on classpath
int valueInCfgOnClasspath = new Long(TimeUnit.MINUTES.toMillis(10)).intValue();
int valueInCfgOnClasspath = (int) TimeUnit.MINUTES.toMillis(10);
assertEquals(valueInCfgOnClasspath, requestConfig.getConnectTimeout());
int newTimeout = new Long(TimeUnit.MINUTES.toMillis(3)).intValue();
int newTimeout = (int) TimeUnit.MINUTES.toMillis(3);
client.setConnectionTimeout(newTimeout);
// did it get reset?
assertEquals(newTimeout, client.getRequestConfig().getConnectTimeout());
Expand Down

0 comments on commit 80cee42

Please sign in to comment.