Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add IntRange annotations to applicable configuration so that Android Studio can warn users #1808

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# Changelog

## TBD

### Enhancements

* Added numeric range annotations to Configuration
[#1808](https://github.com/bugsnag/bugsnag-android/pull/1808)

## 5.28.4 (2023-02-08)

### Bug fixes
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import android.content.Context;

import androidx.annotation.IntRange;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.VisibleForTesting;
Expand Down Expand Up @@ -305,7 +306,7 @@ public long getLaunchDurationMillis() {
* By default, this value is set at 5,000ms. Setting the value to 0 will count all crashes
* as launch crashes until markLaunchCompleted() is called.
*/
public void setLaunchDurationMillis(long launchDurationMillis) {
public void setLaunchDurationMillis(@IntRange(from = 0) long launchDurationMillis) {
if (launchDurationMillis >= MIN_LAUNCH_CRASH_THRESHOLD_MS) {
impl.setLaunchDurationMillis(launchDurationMillis);
} else {
Expand Down Expand Up @@ -524,12 +525,12 @@ public int getMaxBreadcrumbs() {
*
* By default, 100 breadcrumbs are stored: this can be amended up to a maximum of 500.
*/
public void setMaxBreadcrumbs(int maxBreadcrumbs) {
public void setMaxBreadcrumbs(@IntRange(from = 0, to = 500) int maxBreadcrumbs) {
if (maxBreadcrumbs >= MIN_BREADCRUMBS && maxBreadcrumbs <= MAX_BREADCRUMBS) {
impl.setMaxBreadcrumbs(maxBreadcrumbs);
} else {
getLogger().e("Invalid configuration value detected. "
+ "Option maxBreadcrumbs should be an integer between 0-100. "
+ "Option maxBreadcrumbs should be an integer between 0-500. "
+ "Supplied value is " + maxBreadcrumbs);
}
}
Expand All @@ -540,8 +541,8 @@ public void setMaxBreadcrumbs(int maxBreadcrumbs) {
*
* By default, 32 events are persisted.
*/
public int getMaxPersistedEvents() {
return impl.getMaxPersistedEvents();
public int getMaxPersistedEvents() {
return impl.getMaxPersistedEvents();
}

/**
Expand All @@ -550,7 +551,7 @@ public int getMaxPersistedEvents() {
*
* By default, 32 events are persisted.
*/
public void setMaxPersistedEvents(int maxPersistedEvents) {
public void setMaxPersistedEvents(@IntRange(from = 0) int maxPersistedEvents) {
if (maxPersistedEvents >= 0) {
impl.setMaxPersistedEvents(maxPersistedEvents);
} else {
Expand All @@ -576,7 +577,7 @@ public int getMaxReportedThreads() {
*
* By default, up to 200 threads are reported.
*/
public void setMaxReportedThreads(int maxReportedThreads) {
public void setMaxReportedThreads(@IntRange(from = 0) int maxReportedThreads) {
if (maxReportedThreads >= 0) {
impl.setMaxReportedThreads(maxReportedThreads);
} else {
Expand All @@ -602,7 +603,7 @@ public int getMaxPersistedSessions() {
*
* By default, 128 sessions are persisted.
*/
public void setMaxPersistedSessions(int maxPersistedSessions) {
public void setMaxPersistedSessions(@IntRange(from = 0) int maxPersistedSessions) {
if (maxPersistedSessions >= 0) {
impl.setMaxPersistedSessions(maxPersistedSessions);
} else {
Expand All @@ -628,7 +629,7 @@ public int getMaxStringValueLength() {
*
* By default, the limit is 10,000.
*/
public void setMaxStringValueLength(int maxStringValueLength) {
public void setMaxStringValueLength(@IntRange(from = 0) int maxStringValueLength) {
if (maxStringValueLength >= 0) {
impl.setMaxStringValueLength(maxStringValueLength);
} else {
Expand Down