Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"java.compile.nullAnalysis.mode": "automatic"
}
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public LruLoadingCache(int cacheSize, ValueLoader<K, V> loader) {
*/
LruLoadingCache(int cacheSize, ValueLoader<K, V> loader, int concurrency) {
super(cacheSize, concurrency, false);
setCacheLoader(loader);
this.loader = loader;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public class CloudRequestException extends PipelineDataException {
private static final long serialVersionUID = 2110016714691972118L;

private int httpStatusCode;
private Map<String, List<String>> responseHeaders;
private transient Map<String, List<String>> responseHeaders;

/**
* Get the HTTP status code from the response.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ public CloudRequestEngine getInstance() throws PipelineConfigurationException {
* @param aspectDataFactory the factory to use when creating a TData
* instance
*/
@SuppressWarnings("this-escape")
public CloudAspectEngineBase(
Logger logger,
ElementDataFactory<TData> aspectDataFactory) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
Expand Down Expand Up @@ -121,6 +124,7 @@ public CloudRequestEngineDefault(
cloudRequestOrigin);
}

@SuppressWarnings("this-escape")
public CloudRequestEngineDefault(
Logger logger,
ElementDataFactory<CloudRequestData> aspectDataFactory,
Expand Down Expand Up @@ -208,7 +212,7 @@ public EvidenceKeyFilter getEvidenceKeyFilter() throws CloudRequestException, Ag
@Override
protected void processEngine(FlowData data, CloudRequestData aspectData) throws IOException {
byte[] content = getContent(data);
HttpURLConnection connection = httpClient.connect(new URL(endPoint.trim()));
HttpURLConnection connection = httpClient.connect(toUrl(endPoint.trim()));
if (timeoutMillis != null) {
connection.setConnectTimeout(timeoutMillis);
connection.setReadTimeout(timeoutMillis);
Expand Down Expand Up @@ -386,14 +390,35 @@ private void setCommonHeaders(Map<String, String> headers) {
}
}

/**
* Convert a string into a {@link URL} instance.
* <p>
* Replaces the deprecated {@code new URL(String)} constructor with
* {@link URI#toURL()}, translating the checked {@link URISyntaxException}
* into a {@link MalformedURLException} so that callers continue to see the
* same {@link java.io.IOException} as they did previously.
* @param spec the string to parse as a URL
* @return the parsed {@link URL}
* @throws MalformedURLException if the string is not a valid URL
*/
private static URL toUrl(String spec) throws MalformedURLException {
try {
return new URI(spec).toURL();
} catch (URISyntaxException e) {
MalformedURLException ex = new MalformedURLException(e.getMessage());
ex.initCause(e);
throw ex;
}
}

private void getCloudProperties() throws CloudRequestException, AggregateException, PropertyNotLoadedException {
try {
String jsonResult;

Map<String, String> headers = new HashMap<>();
setCommonHeaders(headers);

HttpURLConnection connection = httpClient.connect(new URL(propertiesEndpoint.trim() + (resourceKey != null ? "?Resource=" + resourceKey : "")));
HttpURLConnection connection = httpClient.connect(toUrl(propertiesEndpoint.trim() + (resourceKey != null ? "?Resource=" + resourceKey : "")));
jsonResult = httpClient.getResponseString(connection, headers);
validateResponse(jsonResult, connection);

Expand Down Expand Up @@ -423,7 +448,7 @@ private void getCloudEvidenceKeys() throws CloudRequestException, AggregateExcep
Map<String, String> headers = new HashMap<>();
setCommonHeaders(headers);

HttpURLConnection connection = httpClient.connect(new URL(evidenceKeysEndpoint.trim()));
HttpURLConnection connection = httpClient.connect(toUrl(evidenceKeysEndpoint.trim()));
jsonResult = httpClient.getResponseString(connection, headers);
validateResponse(jsonResult, connection, false);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import java.io.IOException;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URI;
import java.net.URL;
import java.util.HashMap;
import java.util.List;
Expand All @@ -45,7 +46,7 @@ public class CloudRequestEngineTestsBase {
HttpClient httpClient;
protected TestLoggerFactory loggerFactory;

protected URL expectedUrl = new URL("https://cloud.51degrees.com/api/v4/resource_key.json");
protected URL expectedUrl = URI.create("https://cloud.51degrees.com/api/v4/resource_key.json").toURL();
protected String jsonResponse = "{'device':{'value':'1'}}";
protected String evidenceKeysResponse = "['query.User-Agent']";
protected String accessiblePropertiesResponse =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ public abstract class FlowElementBase<
* @param elementDataFactory the factory to use when creating a
* {@link ElementDataBase} instance
*/
@SuppressWarnings("this-escape")
public FlowElementBase(
Logger logger,
ElementDataFactory<TData> elementDataFactory) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ public class AggregateException extends RuntimeException {
* @param message the message to give to the exception
* @param causes multiple causes to be contained in the exception
*/
@SuppressWarnings("this-escape")
public AggregateException(String message, Collection<Throwable> causes) {
super(message);
for (Throwable cause : causes) {
Expand All @@ -52,6 +53,7 @@ public AggregateException(String message, Collection<Throwable> causes) {
* Construct a new instance with no message.
* @param causes multiple causes to be contained in the exception
*/
@SuppressWarnings("this-escape")
public AggregateException(Collection<Throwable> causes) {
super();
for (Throwable cause : causes) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ public static StringSubstitutor getSubstitutor() {
* which is not what we want.
*/
public static class FiftyOneStringSubstitutor extends StringSubstitutor {
@SuppressWarnings("this-escape")
public FiftyOneStringSubstitutor(StringLookup variableResolver) {
super(variableResolver);
setEnableSubstitutionInVariables(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public void WeightedValue_GetWeighting_1() {
@Test
public void WeightedValue_GetWeighting_05() {
IWeightedValue<?>[] values =
new IWeightedValue[]{
new IWeightedValue<?>[]{
new WeightedValue<>(MAX_RAW_WEIGHTING / 2 + 1, 5),
new WeightedValue<>(MAX_RAW_WEIGHTING / 2, 13),
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ public class FiftyOneAspectPropertyMetaDataDefault
private final Iterable<ValueMetaDataDefault> values;
private final ValueMetaDataDefault defaultValue;

@SuppressWarnings("this-escape")
public FiftyOneAspectPropertyMetaDataDefault(
String name,
FlowElement<?,?> element,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ public FiftyOneOnPremiseAspectEngineBuilderBase(ILoggerFactory loggerFactory) {
* @param dataUpdateService the {@link DataUpdateService} to use when
* automatic updates happen on the data file
*/
@SuppressWarnings("this-escape")
public FiftyOneOnPremiseAspectEngineBuilderBase(
ILoggerFactory loggerFactory,
DataUpdateService dataUpdateService) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ public class SetHeadersElement
private final List<ElementPropertyMetaData> properties;
private final Hashtable<Pipeline, PipelineConfig> pipelineConfigs;

@SuppressWarnings("this-escape")
public SetHeadersElement(
Logger logger,
ElementDataFactory<SetHeadersData> elementDataFactory) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,7 @@ protected ShareUsageBase(
languageVersion = System.getProperty("java.version");
osVersion = System.getProperty("os.name");

setEnginesVersion(getClass().getPackage().getImplementationVersion());
this.enginesVersion = getClass().getPackage().getImplementationVersion();
coreVersion = Pipeline.class.getPackage().getImplementationVersion();

includedQueryStringParameters.add(Constants.EVIDENCE_SESSIONID_SUFFIX);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
import java.io.IOException;
import java.net.HttpCookie;
import java.net.MalformedURLException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import java.util.*;

Expand Down Expand Up @@ -357,9 +359,9 @@ public ShareUsageBuilderBase<T> setTakeTimeoutMillis(int milliseconds) {
@DefaultValue(value="Send to 51D - " + Constants.SHARE_USAGE_DEFAULT_URL)
public ShareUsageBuilderBase<T> setShareUsageUrl(String shareUsageUrl) {
try {
URL url = new URL(shareUsageUrl);
URL url = new URI(shareUsageUrl).toURL();
assert !url.toString().isEmpty();
} catch (MalformedURLException e) {
} catch (MalformedURLException | URISyntaxException e) {
throw new IllegalArgumentException(e);
}
this.shareUsageUrl = shareUsageUrl;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
import java.io.ByteArrayOutputStream;
import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URI;
import java.util.*;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
Expand Down Expand Up @@ -545,7 +545,7 @@ protected void legacySendAsXML(List<ShareUsageData> allData) throws Exception {
streamXml(allData, os);
}

HttpURLConnection connection = httpClient.connect(new URL(shareUsageUrl.trim()));
HttpURLConnection connection = httpClient.connect(new URI(shareUsageUrl.trim()).toURL());
String response = httpClient.postData(connection, headers, baos.toByteArray());
int responseCode = connection.getResponseCode();
String responseMessage = connection.getResponseMessage() + "data: '" + response + "'";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ public static String getLibName(Class<?> engineClass) {
* a native library for the environment
* @throws IOException thrown if there is a problem copying the resource
*/
@SuppressWarnings("restricted")
public static void load(Class<?> engineClass)
throws IOException, UnsupportedOperationException {
File nativeLibraryFile = copyResource(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ public AspectPropertyValueDefault() {
* @param value the value to set
*/
public AspectPropertyValueDefault(T value) {
setValue(value);
this.hasValue = true;
this.value = value;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public PropertyMissingException(
String propertyName,
String message) {
super(message);
this.setReason(reason);
this.reason = reason;
this.propertyName = propertyName;
}

Expand All @@ -76,7 +76,7 @@ public PropertyMissingException(
String message,
Throwable cause) {
super(message, cause);
this.setReason(reason);
this.reason = reason;
this.propertyName = propertyName;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public OnPremiseAspectEngineBase(
String tempDataDirPath) {
super(logger, aspectDataFactory);
this.dataFiles = new ArrayList<>();
setTempDataDirPath(tempDataDirPath);
this.tempDataDirPath = tempDataDirPath;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public OnPremiseAspectEngineBuilderBase(
createAndVerifyTempDir(Paths.get(tempDir));
}

public void createAndVerifyTempDir(Path pathToCreate) {
public final void createAndVerifyTempDir(Path pathToCreate) {
try {
File directory = pathToCreate.toFile();
if (isFalse(directory.exists())) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@

import java.io.*;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URI;
import java.nio.file.*;
import java.security.DigestInputStream;
import java.security.MessageDigest;
Expand Down Expand Up @@ -596,7 +596,7 @@ private AutoUpdateStatus downloadFile(
logger.debug("downloadFile from {}", url);

try {
HttpURLConnection connection = httpClient.connect(new URL(url.trim()));
HttpURLConnection connection = httpClient.connect(new URI(url.trim()).toURL());
if (connection == null) {
logger.error("No response from data update service at '{}' for engine '{}'",
dataFile.getFormattedUrl(), Objects.nonNull(dataFile.getEngine()) ?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
import java.io.IOException;
import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URI;
import java.util.Map;
import java.util.zip.GZIPOutputStream;

Expand Down Expand Up @@ -53,7 +53,7 @@ public DataUploaderHttp(String url, Map<String, String> headers, int timeout) {
*/
@Override
public OutputStream getOutputStream() throws Exception{
connection = (HttpURLConnection) new URL(url.trim()).openConnection();
connection = (HttpURLConnection) new URI(url.trim()).toURL().openConnection();
connection.setConnectTimeout(timeout);
connection.setRequestMethod("POST");
for (Map.Entry<String, String> header : headers.entrySet()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@

import java.io.IOException;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URI;
import java.util.HashMap;
import java.util.Map;

Expand All @@ -55,7 +55,7 @@ public void VerifyErrorHandling() {
String result = null;

try{
HttpURLConnection connection = client.connect(new URL(testUrl));
HttpURLConnection connection = client.connect(URI.create(testUrl).toURL());
result = client.getResponseString(connection);
} catch (IOException ex) {
assertTrue("Unexpected exception: " + ex.getMessage(), false);
Expand All @@ -81,7 +81,7 @@ public void VerifyHeaders() {
headers.put("Origin", "51degrees.com");

try{
HttpURLConnection connection = client.connect(new URL(testUrl));
HttpURLConnection connection = client.connect(URI.create(testUrl).toURL());
result = client.getResponseString(connection, headers);
code = connection.getResponseCode();
} catch (IOException ex) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,10 @@ public class EmptyEngine
private EvidenceKeyFilterWhitelist evidenceWhitelist =
new EvidenceKeyFilterWhitelist(Arrays.asList("test.value"));

@SuppressWarnings("this-escape")
private final TypedKey<EmptyEngineData> typedKey = new TypedKeyDefault<>(getElementDataKey(), EmptyEngineData.class);

@SuppressWarnings("this-escape")
public EmptyEngine(
Logger logger,
ElementDataFactory<EmptyEngineData> aspectDataFactory) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ public class JsonBuilderElement
* @param logger The logger.
* @param elementDataFactory The element data factory.
*/
@SuppressWarnings("this-escape")
public JsonBuilderElement(
Logger logger,
ElementDataFactory<JsonBuilderData> elementDataFactory) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ public Default(
* Initialise the service.
*/
@SuppressWarnings("rawtypes")
protected void init() {
protected final void init() {
headersAffectingJavaScript = new ArrayList<>();
// Get evidence filters for all elements.
List<EvidenceKeyFilter> filters = new ArrayList<>();
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@
<showWarnings>true</showWarnings>
<compilerArgs>
<arg>-Xlint:all,-try,-options</arg>
<!-- <arg>-Werror</arg>-->
<arg>-Werror</arg>
</compilerArgs>
</configuration>
</plugin>
Expand Down
Loading