> content) throws IOException {
final ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
final Writer writer = new OutputStreamWriter(outputStream, ACRAConstants.UTF8);
//noinspection TryFinallyCanBeTryWithResources we do not target api 19
diff --git a/acra-http/src/main/java/org/acra/security/BaseKeyStoreFactory.java b/acra-http/src/main/java/org/acra/security/BaseKeyStoreFactory.java
index b51c98217..fa717f664 100644
--- a/acra-http/src/main/java/org/acra/security/BaseKeyStoreFactory.java
+++ b/acra-http/src/main/java/org/acra/security/BaseKeyStoreFactory.java
@@ -67,16 +67,19 @@ public BaseKeyStoreFactory(String certificateType) {
this.certificateType = certificateType;
}
+ @Nullable
protected abstract InputStream getInputStream(@NonNull Context context);
protected String getKeyStoreType() {
return KeyStore.getDefaultType();
}
+ @NonNull
protected Type getStreamType() {
return Type.CERTIFICATE;
}
+ @Nullable
protected char[] getPassword() {
return null;
}
diff --git a/acra-http/src/main/java/org/acra/sender/HttpSender.java b/acra-http/src/main/java/org/acra/sender/HttpSender.java
index 5f25141a7..9cf21df5f 100644
--- a/acra-http/src/main/java/org/acra/sender/HttpSender.java
+++ b/acra-http/src/main/java/org/acra/sender/HttpSender.java
@@ -25,7 +25,7 @@
import org.acra.ACRAConstants;
import org.acra.ReportField;
import org.acra.attachment.DefaultAttachmentProvider;
-import org.acra.config.Configuration;
+import org.acra.config.ConfigUtils;
import org.acra.config.CoreConfiguration;
import org.acra.config.HttpSenderConfiguration;
import org.acra.data.CrashReportData;
@@ -57,30 +57,30 @@ public class HttpSender implements ReportSender {
*/
public enum Method {
POST {
+ @NonNull
@Override
- URL createURL(String baseUrl, CrashReportData report) throws MalformedURLException {
+ URL createURL(@NonNull String baseUrl, @NonNull CrashReportData report) throws MalformedURLException {
return new URL(baseUrl);
}
},
PUT {
+ @NonNull
@Override
- URL createURL(String baseUrl, CrashReportData report) throws MalformedURLException {
+ URL createURL(@NonNull String baseUrl, @NonNull CrashReportData report) throws MalformedURLException {
return new URL(baseUrl + '/' + report.getString(ReportField.REPORT_ID));
}
};
- abstract URL createURL(String baseUrl, CrashReportData report) throws MalformedURLException;
+ @NonNull
+ abstract URL createURL(@NonNull String baseUrl, @NonNull CrashReportData report) throws MalformedURLException;
}
private final CoreConfiguration config;
private final HttpSenderConfiguration httpConfig;
- @NonNull
private final Uri mFormUri;
private final Method mMethod;
private final StringFormat mType;
- @Nullable
private String mUsername;
- @Nullable
private String mPassword;
/**
@@ -113,7 +113,7 @@ public HttpSender(@NonNull CoreConfiguration config, @Nullable Method method, @N
*/
public HttpSender(@NonNull CoreConfiguration config, @Nullable Method method, @Nullable StringFormat type, @Nullable String formUri) {
this.config = config;
- this.httpConfig = getHttpSenderConfiguration(config);
+ this.httpConfig = ConfigUtils.getPluginConfiguration(config, HttpSenderConfiguration.class);
mMethod = (method == null) ? httpConfig.httpMethod() : method;
mFormUri = Uri.parse((formUri == null) ? httpConfig.uri() : formUri);
mType = (type == null) ? config.reportFormat() : type;
@@ -121,17 +121,6 @@ public HttpSender(@NonNull CoreConfiguration config, @Nullable Method method, @N
mPassword = null;
}
- private static HttpSenderConfiguration getHttpSenderConfiguration(CoreConfiguration config) {
- HttpSenderConfiguration httpSenderConfiguration = null;
- for (Configuration configuration : config.pluginConfigurations()) {
- if (configuration instanceof HttpSenderConfiguration) {
- httpSenderConfiguration = (HttpSenderConfiguration) configuration;
- break;
- }
- }
- return httpSenderConfiguration;
- }
-
/**
*
* Set credentials for this HttpSender that override (if present) the ones set globally.
@@ -224,8 +213,9 @@ protected void putAttachment(@NonNull CoreConfiguration configuration, @NonNull
* @return a string representation of the report
* @throws Exception if conversion failed
*/
+ @NonNull
@SuppressWarnings("WeakerAccess")
- protected String convertToString(CrashReportData report, StringFormat format) throws Exception {
+ protected String convertToString(CrashReportData report, @NonNull StringFormat format) throws Exception {
return format.toFormattedString(report, config.reportContent(), "&", "\n", true);
}
diff --git a/acra-http/src/main/java/org/acra/util/UriUtils.java b/acra-http/src/main/java/org/acra/util/UriUtils.java
index b4653bb2d..9d2b20b81 100644
--- a/acra-http/src/main/java/org/acra/util/UriUtils.java
+++ b/acra-http/src/main/java/org/acra/util/UriUtils.java
@@ -41,7 +41,7 @@ private UriUtils() {
}
@NonNull
- public static byte[] uriToByteArray(@NonNull Context context, Uri uri) throws IOException {
+ public static byte[] uriToByteArray(@NonNull Context context, @NonNull Uri uri) throws IOException {
final InputStream inputStream = context.getContentResolver().openInputStream(uri);
if (inputStream == null) {
throw new FileNotFoundException("Could not open " + uri.toString());
@@ -55,7 +55,8 @@ public static byte[] uriToByteArray(@NonNull Context context, Uri uri) throws IO
return outputStream.toByteArray();
}
- public static String getFileNameFromUri(Context context, Uri uri) {
+ @NonNull
+ public static String getFileNameFromUri(@NonNull Context context, @NonNull Uri uri) {
String result = null;
if (uri.getScheme().equals(ContentResolver.SCHEME_CONTENT)) {
final Cursor cursor = context.getContentResolver().query(uri, null, null, null, null);
@@ -79,10 +80,12 @@ public static String getFileNameFromUri(Context context, Uri uri) {
return result;
}
- public static String getMimeType(Context context, Uri uri) {
+ @NonNull
+ public static String getMimeType(@NonNull Context context, @NonNull Uri uri) {
if (uri.getScheme().equals(ContentResolver.SCHEME_CONTENT)) {
final ContentResolver contentResolver = context.getContentResolver();
- return contentResolver.getType(uri);
+ String type = contentResolver.getType(uri);
+ if (type != null) return type;
}
return AcraContentProvider.guessMimeType(uri);
}
diff --git a/acra-javacore/src/main/java/org/acra/collections/ImmutableList.java b/acra-javacore/src/main/java/org/acra/collections/ImmutableList.java
index 63b9ecf72..96e1311af 100644
--- a/acra-javacore/src/main/java/org/acra/collections/ImmutableList.java
+++ b/acra-javacore/src/main/java/org/acra/collections/ImmutableList.java
@@ -40,7 +40,7 @@ public ImmutableList(E... elements) {
this(Arrays.asList(elements));
}
- public ImmutableList(Collection collection) {
+ public ImmutableList(@NonNull Collection collection) {
this.mList = new ArrayList<>(collection);
}
diff --git a/acra-javacore/src/main/java/org/acra/collections/ImmutableMap.java b/acra-javacore/src/main/java/org/acra/collections/ImmutableMap.java
index 8fe87777b..a256bf991 100644
--- a/acra-javacore/src/main/java/org/acra/collections/ImmutableMap.java
+++ b/acra-javacore/src/main/java/org/acra/collections/ImmutableMap.java
@@ -33,7 +33,7 @@ public final class ImmutableMap implements Map, Serializable {
private final Map mMap;
- public ImmutableMap(Map map) {
+ public ImmutableMap(@NonNull Map map) {
this.mMap = new HashMap<>(map);
}
@@ -105,7 +105,7 @@ public Collection values() {
return new ImmutableList<>(mMap.values());
}
- public static class ImmutableEntryWrapper implements Map.Entry {
+ private static class ImmutableEntryWrapper implements Map.Entry {
private final Map.Entry mEntry;
ImmutableEntryWrapper(Entry mEntry) {
@@ -122,6 +122,7 @@ public V getValue() {
return mEntry.getValue();
}
+ @NonNull
@Override
public V setValue(Object object) {
throw new UnsupportedOperationException();
diff --git a/acra-javacore/src/main/java/org/acra/collections/ImmutableSet.java b/acra-javacore/src/main/java/org/acra/collections/ImmutableSet.java
index 85736daec..6597bbe4e 100644
--- a/acra-javacore/src/main/java/org/acra/collections/ImmutableSet.java
+++ b/acra-javacore/src/main/java/org/acra/collections/ImmutableSet.java
@@ -34,6 +34,7 @@
public final class ImmutableSet implements Set, Serializable {
private static final ImmutableSet