1
0
mirror of https://github.com/TeamNewPipe/NewPipe.git synced 2024-11-22 11:02:35 +01:00

Merge pull request #5254 from Isira-Seneviratne/Use_Objects_requireNonNull

Use Objects.requireNonNull().
This commit is contained in:
Robin 2021-01-02 11:30:24 +01:00 committed by GitHub
commit e75ef086af
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 16 additions and 25 deletions

View File

@ -19,6 +19,7 @@ import org.schabi.newpipe.util.ShareUtils;
import java.io.Serializable;
import java.util.Arrays;
import java.util.Comparator;
import java.util.Objects;
import io.reactivex.rxjava3.disposables.CompositeDisposable;
@ -35,12 +36,9 @@ public class LicenseFragment extends Fragment {
private final CompositeDisposable compositeDisposable = new CompositeDisposable();
public static LicenseFragment newInstance(final SoftwareComponent[] softwareComponents) {
if (softwareComponents == null) {
throw new NullPointerException("softwareComponents is null");
}
final LicenseFragment fragment = new LicenseFragment();
final Bundle bundle = new Bundle();
bundle.putParcelableArray(ARG_COMPONENTS, softwareComponents);
bundle.putParcelableArray(ARG_COMPONENTS, Objects.requireNonNull(softwareComponents));
final LicenseFragment fragment = new LicenseFragment();
fragment.setArguments(bundle);
return fragment;
}

View File

@ -246,10 +246,7 @@ public class DownloadSettingsFragment extends BasePreferenceFragment {
// revoke permissions on the old save path (required for SAF only)
final Context context = getContext();
if (context == null) {
throw new NullPointerException("getContext()");
}
final Context context = requireContext();
forgetSAFTree(context, defaultPreferences.getString(key, ""));

View File

@ -22,6 +22,7 @@ import java.net.SocketTimeoutException;
import java.net.URL;
import java.net.UnknownHostException;
import java.nio.channels.ClosedByInterruptException;
import java.util.Objects;
import javax.net.ssl.SSLException;
@ -154,8 +155,8 @@ public class DownloadMission extends Mission {
public transient Thread init = null;
public DownloadMission(String[] urls, StoredFileHelper storage, char kind, Postprocessing psInstance) {
if (urls == null) throw new NullPointerException("urls is null");
if (urls.length < 1) throw new IllegalArgumentException("urls is empty");
if (Objects.requireNonNull(urls).length < 1)
throw new IllegalArgumentException("urls array is empty");
this.urls = urls;
this.kind = kind;
this.offsets = new long[urls.length];

View File

@ -8,6 +8,7 @@ import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.nio.channels.ClosedByInterruptException;
import java.util.Objects;
import us.shandian.giga.get.DownloadMission.Block;
import us.shandian.giga.get.DownloadMission.HttpError;
@ -29,8 +30,7 @@ public class DownloadRunnable extends Thread {
private HttpURLConnection mConn;
DownloadRunnable(DownloadMission mission, int id) {
if (mission == null) throw new NullPointerException("mission is null");
mMission = mission;
mMission = Objects.requireNonNull(mission);
mId = id;
}

View File

@ -12,6 +12,7 @@ import androidx.annotation.NonNull;
import java.io.File;
import java.util.ArrayList;
import java.util.Objects;
import us.shandian.giga.get.DownloadMission;
import us.shandian.giga.get.FinishedMission;
@ -140,9 +141,7 @@ public class FinishedMissionStore extends SQLiteOpenHelper {
}
private FinishedMission getMissionFromCursor(Cursor cursor) {
if (cursor == null) throw new NullPointerException("cursor is null");
String kind = cursor.getString(cursor.getColumnIndex(KEY_KIND));
String kind = Objects.requireNonNull(cursor).getString(cursor.getColumnIndex(KEY_KIND));
if (kind == null || kind.isEmpty()) kind = "?";
String path = cursor.getString(cursor.getColumnIndexOrThrow(KEY_PATH));
@ -186,15 +185,13 @@ public class FinishedMissionStore extends SQLiteOpenHelper {
}
public void addFinishedMission(DownloadMission downloadMission) {
if (downloadMission == null) throw new NullPointerException("downloadMission is null");
ContentValues values = getValuesOfMission(Objects.requireNonNull(downloadMission));
SQLiteDatabase database = getWritableDatabase();
ContentValues values = getValuesOfMission(downloadMission);
database.insert(FINISHED_TABLE_NAME, null, values);
}
public void deleteMission(Mission mission) {
if (mission == null) throw new NullPointerException("mission is null");
String ts = String.valueOf(mission.timestamp);
String ts = String.valueOf(Objects.requireNonNull(mission).timestamp);
SQLiteDatabase database = getWritableDatabase();
@ -212,9 +209,8 @@ public class FinishedMissionStore extends SQLiteOpenHelper {
}
public void updateMission(Mission mission) {
if (mission == null) throw new NullPointerException("mission is null");
ContentValues values = getValuesOfMission(Objects.requireNonNull(mission));
SQLiteDatabase database = getWritableDatabase();
ContentValues values = getValuesOfMission(mission);
String ts = String.valueOf(mission.timestamp);
int rowsAffected;

View File

@ -7,6 +7,7 @@ import org.schabi.newpipe.streams.io.SharpStream;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Objects;
public class CircularFileWriter extends SharpStream {
@ -27,9 +28,7 @@ public class CircularFileWriter extends SharpStream {
private BufferedFile aux;
public CircularFileWriter(SharpStream target, File temp, OffsetChecker checker) throws IOException {
if (checker == null) {
throw new NullPointerException("checker is null");
}
Objects.requireNonNull(checker);
if (!temp.exists()) {
if (!temp.createNewFile()) {