Skip to content

Commit

Permalink
JERSEY-224 && JERSEY-222 part II: (findbugs & javadocs issues)
Browse files Browse the repository at this point in the history
Change-Id: Ic0d111e179d9b546c076eb24050ed854a8aef41e
  • Loading branch information
Adam Lindenthal committed Sep 1, 2014
1 parent 4619317 commit 712c410
Show file tree
Hide file tree
Showing 12 changed files with 72 additions and 45 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@
@SuppressWarnings("deprecation")
class ApacheConnector implements Connector {

private final static Logger LOGGER = Logger.getLogger(ApacheConnector.class.getName());
private static final Logger LOGGER = Logger.getLogger(ApacheConnector.class.getName());

private static final VersionInfo vi;
private static final String release;
Expand All @@ -205,7 +205,7 @@ class ApacheConnector implements Connector {
*
* @param config client configuration.
*/
ApacheConnector(Configuration config) {
ApacheConnector(final Configuration config) {
Object reqConfig = null;

if (config != null) {
Expand Down Expand Up @@ -259,15 +259,15 @@ class ApacheConnector implements Connector {
clientBuilder.setDefaultCredentialsProvider((CredentialsProvider) credentialsProvider);
}

Object proxyUri;
final Object proxyUri;
proxyUri = config.getProperty(ClientProperties.PROXY_URI);
if (proxyUri != null) {
final URI u = getProxyUri(proxyUri);
final HttpHost proxy = new HttpHost(u.getHost(), u.getPort(), u.getScheme());
String userName;
final String userName;
userName = ClientProperties.getValue(config.getProperties(), ClientProperties.PROXY_USERNAME, String.class);
if (userName != null) {
String password;
final String password;
password = ClientProperties.getValue(config.getProperties(), ClientProperties.PROXY_PASSWORD, String.class);

if (password != null) {
Expand All @@ -291,7 +291,7 @@ class ApacheConnector implements Connector {


if (reqConfig != null) {
RequestConfig.Builder reqConfigBuilder = RequestConfig.copy((RequestConfig) reqConfig);
final RequestConfig.Builder reqConfigBuilder = RequestConfig.copy((RequestConfig) reqConfig);
if (connectTimeout > 0) {
reqConfigBuilder.setConnectTimeout(connectTimeout);
}
Expand Down Expand Up @@ -322,6 +322,10 @@ class ApacheConnector implements Connector {
}

private SSLContext getSslContext(final Configuration config) {
if (config == null) {
return null;
}

final SslConfigurator sslConfigurator = ApacheClientProperties.getValue(
config.getProperties(),
ApacheClientProperties.SSL_CONFIG,
Expand Down Expand Up @@ -624,9 +628,9 @@ public boolean isStreaming() {
}

private static Map<String, String> writeOutBoundHeaders(final MultivaluedMap<String, Object> headers, final HttpUriRequest request) {
Map<String, String> stringHeaders = HeaderUtils.asStringHeadersSingleValue(headers);
final Map<String, String> stringHeaders = HeaderUtils.asStringHeadersSingleValue(headers);

for (Map.Entry<String, String> e : stringHeaders.entrySet()) {
for (final Map.Entry<String, String> e : stringHeaders.entrySet()) {
request.addHeader(e.getKey(), e.getValue());
}
return stringHeaders;
Expand Down
14 changes: 14 additions & 0 deletions etc/config/findbugs-exclude.xml
Original file line number Diff line number Diff line change
Expand Up @@ -90,4 +90,18 @@
<Match>
<Bug pattern="GF_INVALID_MSG_ID_PATTERN,GF_MISSING_LOGGER_INFO_ANNOTATION,GF_MISSING_LOGMESSAGE_INFO_ANNOTATION" />
</Match>

<!-- individual ad-hoc ignores -->
<!-- ServerScopeProvider.getFilteringScopes() - returned object would be identical -->
<Match>
<Class name="~.*.ServerScopeProvider" />
<Method name="getFilteringScopes()" />
<Bug pattern="RV_RETURN_VALUE_OF_PUTIFABSENT_IGNORED" />
</Match>

<!-- There are few cases in the codebase -->
<Match>
<Bug pattern="CN_IMPLEMENTS_CLONE_BUT_NOT_CLONEABLE" />
</Match>

</FindBugsFilter>
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,12 @@ public class SelectableScopeResolver implements ScopeResolver {
/**
* Prefix for all selectable scopes
*/
public static String PREFIX = SelectableScopeResolver.class.getName() + "_";
public static final String PREFIX = SelectableScopeResolver.class.getName() + "_";

/**
* Scope used for selecting all fields, i.e.: when no filter is applied
*/
public static String DEFAULT_SCOPE = PREFIX + "*";
public static final String DEFAULT_SCOPE = PREFIX + "*";

/**
* Query parameter name for selectable feature, set to default value
Expand All @@ -88,7 +88,7 @@ private void init(){

@Override
public Set<String> resolve(final Annotation[] annotations) {
final Set<String> scopes = new HashSet<String>();
final Set<String> scopes = new HashSet<>();

final List<String> fields = uriInfo.getQueryParameters().get(SELECTABLE_PARAM_NAME);
if (fields != null && !fields.isEmpty()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ private T resolve(final String name) {
// ServletContext.
if (servletContext != null) {
final InputStream stream = servletContext.getResourceAsStream(template);
reader = stream != null ? new InputStreamReader(stream, encoding) : null;
reader = stream != null ? new InputStreamReader(stream) : null;
}

// Classloader.
Expand Down Expand Up @@ -316,14 +316,14 @@ protected Charset setContentType(final MediaType mediaType, final MultivaluedMap
final MediaType finalMediaType;
if (charset == null) {
encoding = getEncoding();
final HashMap<String, String> params = new HashMap<String, String>(mediaType.getParameters());
final HashMap<String, String> params = new HashMap<>(mediaType.getParameters());
params.put(MediaType.CHARSET_PARAMETER, encoding.name());
finalMediaType = new MediaType(mediaType.getType(), mediaType.getSubtype(), params);
} else {
encoding = Charset.forName(charset);
finalMediaType = mediaType;
}
final ArrayList<Object> typeList = new ArrayList<Object>(1);
final ArrayList<Object> typeList = new ArrayList<>(1);
typeList.add(finalMediaType.toString());
httpHeaders.put(HttpHeaders.CONTENT_TYPE, typeList);
return encoding;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
*/
public class ContentDisposition {

private String type;
private final String type;
private final Map<String, String> parameters;
private String fileName;
private Date creationDate;
Expand Down Expand Up @@ -229,7 +229,7 @@ private long createLong(final String name) throws ParseException {
return -1;
}
try {
return Long.valueOf(value);
return Long.parseLong(value);
} catch (final NumberFormatException e) {
throw new ParseException("Error parsing size parameter of value, " + value, 0);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,22 +183,22 @@ private void configure() {
if (stream == null) {
return;
}
Properties props = new Properties();
final Properties props = new Properties();
props.load(stream);

if (props.containsKey(BUFFER_THRESHOLD)) {
this.bufferThreshold = Integer.valueOf(props.getProperty(BUFFER_THRESHOLD));
this.bufferThreshold = Integer.parseInt(props.getProperty(BUFFER_THRESHOLD));
}
if (props.containsKey(TEMP_DIRECTORY)) {
this.tempDir = props.getProperty(TEMP_DIRECTORY);
}
} catch (IOException e) {
} catch (final IOException e) {
throw new IllegalArgumentException(e);
} finally {
if (stream != null) {
try {
stream.close();
} catch (IOException e) {
} catch (final IOException e) {
// Pass through
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,28 +101,29 @@ public void writeTo(final OutboundEvent outboundEvent,
final MultivaluedMap<String, Object> httpHeaders,
final OutputStream entityStream) throws IOException, WebApplicationException {

final Charset charset = MessageUtils.getCharset(mediaType);
if (outboundEvent.getComment() != null) {
for (final String comment : outboundEvent.getComment().split("\n")) {
entityStream.write(COMMENT_LEAD);
entityStream.write(comment.getBytes(MessageUtils.getCharset(mediaType)));
entityStream.write(comment.getBytes(charset));
entityStream.write(EOL);
}
}

if (outboundEvent.getType() != null) {
if (outboundEvent.getName() != null) {
entityStream.write(NAME_LEAD);
entityStream.write(outboundEvent.getName().getBytes());
entityStream.write(outboundEvent.getName().getBytes(charset));
entityStream.write(EOL);
}
if (outboundEvent.getId() != null) {
entityStream.write(ID_LEAD);
entityStream.write(outboundEvent.getId().getBytes());
entityStream.write(outboundEvent.getId().getBytes(charset));
entityStream.write(EOL);
}
if (outboundEvent.getReconnectDelay() > SseFeature.RECONNECT_NOT_SET) {
entityStream.write(RETRY_LEAD);
entityStream.write(Long.toString(outboundEvent.getReconnectDelay()).getBytes());
entityStream.write(Long.toString(outboundEvent.getReconnectDelay()).getBytes(charset));
entityStream.write(EOL);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ public class SseFeature implements Feature {
*
* @since 2.3
*/
public static long RECONNECT_NOT_SET = -1;
public static final long RECONNECT_NOT_SET = -1;

/**
* {@code "Last-Event-ID"} HTTP request header name as defined by
Expand All @@ -126,7 +126,7 @@ public class SseFeature implements Feature {


@Override
public boolean configure(FeatureContext context) {
public boolean configure(final FeatureContext context) {
if (context.getConfiguration().isEnabled(this.getClass())) {
return false;
}
Expand All @@ -149,7 +149,7 @@ public boolean configure(FeatureContext context) {
* @param ctx configurable context in which the SSE feature should be registered.
* @return updated configurable context.
*/
static <T extends Configurable<T>> T register(T ctx) {
static <T extends Configurable<T>> T register(final T ctx) {
if (!ctx.getConfiguration().isRegistered(SseFeature.class)) {
ctx.register(SseFeature.class);
}
Expand Down
8 changes: 8 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,15 @@
<links>
<link>http://jax-rs-spec.java.net/nonav/2.0/apidocs</link>
<link>http://hk2.java.net/nonav/hk2-api/apidocs</link>
<link>http://docs.oracle.com/javaee/7/api</link>
</links>
<excludePackageNames>
*.examples.*:*.internal.*:*.tests.*
</excludePackageNames>
<sourceFileExcludes>
<exclude>bundles/**</exclude>
</sourceFileExcludes>
<verbose />
</configuration>
<executions>
<execution>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ final class NonceManager {
/**
* Maps timestamps to key-nonce pairs.
*/
private final SortedMap<Long, Map<String, Set<String>>> tsToKeyNoncePairs = new TreeMap<Long, Map<String, Set<String>>>();
private final SortedMap<Long, Map<String, Set<String>>> tsToKeyNoncePairs = new TreeMap<>();

private volatile long mapSize = 0;

Expand All @@ -95,7 +95,7 @@ final class NonceManager {
* @param maximumCacheSize maximum size of the cache that keeps nonces. If the cache exceeds the method
* {@link #verify(String, String, String)} will return {@code false}.
*/
public NonceManager(long maxAge, int gcPeriod, TimeUnit timestampUnit, long maximumCacheSize) {
public NonceManager(final long maxAge, final int gcPeriod, final TimeUnit timestampUnit, final long maximumCacheSize) {
if (maxAge <= 0 || gcPeriod <= 0) {
throw new IllegalArgumentException();
}
Expand All @@ -120,9 +120,9 @@ public NonceManager(long maxAge, int gcPeriod, TimeUnit timestampUnit, long maxi
* @param now current time in milliseconds
* @return true if the timestamp/nonce are valid.
*/
synchronized boolean verify(String key, String timestamp, String nonce, long now) {
synchronized boolean verify(final String key, final String timestamp, final String nonce, final long now) {
// convert timestamp to milliseconds since epoch to deal with uniformly
long stamp = timestampUnit.toMillis(longValue(timestamp));
final long stamp = timestampUnit.toMillis(longValue(timestamp));

if (mapSize + 1 > maximumMapSize) {
gc(now);
Expand All @@ -139,17 +139,17 @@ synchronized boolean verify(String key, String timestamp, String nonce, long now

Map<String, Set<String>> keyToNonces = tsToKeyNoncePairs.get(stamp);
if (keyToNonces == null) {
keyToNonces = new HashMap<String, Set<String>>();
keyToNonces = new HashMap<>();
tsToKeyNoncePairs.put(stamp, keyToNonces);
}

Set<String> nonces = keyToNonces.get(key);
if (nonces == null) {
nonces = new HashSet<String>();
nonces = new HashSet<>();
keyToNonces.put(key, nonces);
}

boolean result = nonces.add(nonce);
final boolean result = nonces.add(nonce);
if (result) {
mapSize++;
}
Expand All @@ -172,7 +172,7 @@ synchronized boolean verify(String key, String timestamp, String nonce, long now
* @param nonce the oauth_nonce value for a given consumer request.
* @return true if the timestamp/nonce are valid.
*/
public synchronized boolean verify(String key, String timestamp, String nonce) {
public synchronized boolean verify(final String key, final String timestamp, final String nonce) {
return verify(key, timestamp, nonce, System.currentTimeMillis());
}

Expand All @@ -182,11 +182,11 @@ public synchronized boolean verify(String key, String timestamp, String nonce) {
*
* @param now milliseconds since epoch representing "now"
*/
void gc(long now) {
void gc(final long now) {
gcCounter = 0;
final SortedMap<Long, Map<String, Set<String>>> headMap = tsToKeyNoncePairs.headMap(now - maxAge);
for (Map.Entry<Long, Map<String, Set<String>>> entry : headMap.entrySet()) {
for (Map.Entry<String, Set<String>> timeEntry : entry.getValue().entrySet()) {
for (final Map.Entry<Long, Map<String, Set<String>>> entry : headMap.entrySet()) {
for (final Map.Entry<String, Set<String>> timeEntry : entry.getValue().entrySet()) {
mapSize -= timeEntry.getValue().size();
}
}
Expand All @@ -200,17 +200,17 @@ void gc(long now) {
*/
long checkAndGetSize() {
long size = 0;
for (Map<String, Set<String>> keyToNonces : tsToKeyNoncePairs.values()) {
for (final Map<String, Set<String>> keyToNonces : tsToKeyNoncePairs.values()) {
size += keyToNonces.values().size();
}
assert mapSize == size;
return mapSize;
}

private static long longValue(String value) {
private static long longValue(final String value) {
try {
return Long.valueOf(value);
} catch (NumberFormatException nfe) {
return Long.parseLong(value);
} catch (final NumberFormatException nfe) {
return -1;
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
*
* Copyright (c) 2013 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2013-2014 Oracle and/or its affiliates. All rights reserved.
*
* The contents of this file are subject to the terms of either the GNU
* General Public License Version 2 only ("GPL") or the Common Development
Expand Down Expand Up @@ -92,7 +92,7 @@ public final class OAuth2ClientSupport {
* The value of the property must be a {@link String}.
* </p>
*/
public static String OAUTH2_PROPERTY_ACCESS_TOKEN = "jersey.config.client.oauth2.access.token";
public static final String OAUTH2_PROPERTY_ACCESS_TOKEN = "jersey.config.client.oauth2.access.token";

/**
* Build the {@link Feature client filter feature} from the {@code accessToken} that will add
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -941,7 +941,7 @@ private class JerseyTestLogHandler extends Handler {
private final List<LogRecord> records;

private JerseyTestLogHandler() {
this.logLevel = Integer.valueOf(getProperty(TestProperties.RECORD_LOG_LEVEL));
this.logLevel = Integer.parseInt(getProperty(TestProperties.RECORD_LOG_LEVEL));
this.records = new ArrayList<>();
}

Expand Down

0 comments on commit 712c410

Please sign in to comment.