mirror of
				https://github.com/TeamNewPipe/NewPipe
				synced 2025-10-31 07:13:00 +00:00 
			
		
		
		
	Merge pull request #5254 from Isira-Seneviratne/Use_Objects_requireNonNull
Use Objects.requireNonNull().
This commit is contained in:
		| @@ -19,6 +19,7 @@ import org.schabi.newpipe.util.ShareUtils; | |||||||
| import java.io.Serializable; | import java.io.Serializable; | ||||||
| import java.util.Arrays; | import java.util.Arrays; | ||||||
| import java.util.Comparator; | import java.util.Comparator; | ||||||
|  | import java.util.Objects; | ||||||
|  |  | ||||||
| import io.reactivex.rxjava3.disposables.CompositeDisposable; | import io.reactivex.rxjava3.disposables.CompositeDisposable; | ||||||
|  |  | ||||||
| @@ -35,12 +36,9 @@ public class LicenseFragment extends Fragment { | |||||||
|     private final CompositeDisposable compositeDisposable = new CompositeDisposable(); |     private final CompositeDisposable compositeDisposable = new CompositeDisposable(); | ||||||
|  |  | ||||||
|     public static LicenseFragment newInstance(final SoftwareComponent[] softwareComponents) { |     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(); |         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); |         fragment.setArguments(bundle); | ||||||
|         return fragment; |         return fragment; | ||||||
|     } |     } | ||||||
|   | |||||||
| @@ -246,10 +246,7 @@ public class DownloadSettingsFragment extends BasePreferenceFragment { | |||||||
|  |  | ||||||
|  |  | ||||||
|         // revoke permissions on the old save path (required for SAF only) |         // revoke permissions on the old save path (required for SAF only) | ||||||
|         final Context context = getContext(); |         final Context context = requireContext(); | ||||||
|         if (context == null) { |  | ||||||
|             throw new NullPointerException("getContext()"); |  | ||||||
|         } |  | ||||||
|  |  | ||||||
|         forgetSAFTree(context, defaultPreferences.getString(key, "")); |         forgetSAFTree(context, defaultPreferences.getString(key, "")); | ||||||
|  |  | ||||||
|   | |||||||
| @@ -22,6 +22,7 @@ import java.net.SocketTimeoutException; | |||||||
| import java.net.URL; | import java.net.URL; | ||||||
| import java.net.UnknownHostException; | import java.net.UnknownHostException; | ||||||
| import java.nio.channels.ClosedByInterruptException; | import java.nio.channels.ClosedByInterruptException; | ||||||
|  | import java.util.Objects; | ||||||
|  |  | ||||||
| import javax.net.ssl.SSLException; | import javax.net.ssl.SSLException; | ||||||
|  |  | ||||||
| @@ -154,8 +155,8 @@ public class DownloadMission extends Mission { | |||||||
|     public transient Thread init = null; |     public transient Thread init = null; | ||||||
|  |  | ||||||
|     public DownloadMission(String[] urls, StoredFileHelper storage, char kind, Postprocessing psInstance) { |     public DownloadMission(String[] urls, StoredFileHelper storage, char kind, Postprocessing psInstance) { | ||||||
|         if (urls == null) throw new NullPointerException("urls is null"); |         if (Objects.requireNonNull(urls).length < 1) | ||||||
|         if (urls.length < 1) throw new IllegalArgumentException("urls is empty"); |             throw new IllegalArgumentException("urls array is empty"); | ||||||
|         this.urls = urls; |         this.urls = urls; | ||||||
|         this.kind = kind; |         this.kind = kind; | ||||||
|         this.offsets = new long[urls.length]; |         this.offsets = new long[urls.length]; | ||||||
|   | |||||||
| @@ -8,6 +8,7 @@ import java.io.IOException; | |||||||
| import java.io.InputStream; | import java.io.InputStream; | ||||||
| import java.net.HttpURLConnection; | import java.net.HttpURLConnection; | ||||||
| import java.nio.channels.ClosedByInterruptException; | import java.nio.channels.ClosedByInterruptException; | ||||||
|  | import java.util.Objects; | ||||||
|  |  | ||||||
| import us.shandian.giga.get.DownloadMission.Block; | import us.shandian.giga.get.DownloadMission.Block; | ||||||
| import us.shandian.giga.get.DownloadMission.HttpError; | import us.shandian.giga.get.DownloadMission.HttpError; | ||||||
| @@ -29,8 +30,7 @@ public class DownloadRunnable extends Thread { | |||||||
|     private HttpURLConnection mConn; |     private HttpURLConnection mConn; | ||||||
|  |  | ||||||
|     DownloadRunnable(DownloadMission mission, int id) { |     DownloadRunnable(DownloadMission mission, int id) { | ||||||
|         if (mission == null) throw new NullPointerException("mission is null"); |         mMission = Objects.requireNonNull(mission); | ||||||
|         mMission = mission; |  | ||||||
|         mId = id; |         mId = id; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|   | |||||||
| @@ -12,6 +12,7 @@ import androidx.annotation.NonNull; | |||||||
|  |  | ||||||
| import java.io.File; | import java.io.File; | ||||||
| import java.util.ArrayList; | import java.util.ArrayList; | ||||||
|  | import java.util.Objects; | ||||||
|  |  | ||||||
| import us.shandian.giga.get.DownloadMission; | import us.shandian.giga.get.DownloadMission; | ||||||
| import us.shandian.giga.get.FinishedMission; | import us.shandian.giga.get.FinishedMission; | ||||||
| @@ -140,9 +141,7 @@ public class FinishedMissionStore extends SQLiteOpenHelper { | |||||||
|     } |     } | ||||||
|  |  | ||||||
|     private FinishedMission getMissionFromCursor(Cursor cursor) { |     private FinishedMission getMissionFromCursor(Cursor cursor) { | ||||||
|         if (cursor == null) throw new NullPointerException("cursor is null"); |         String kind = Objects.requireNonNull(cursor).getString(cursor.getColumnIndex(KEY_KIND)); | ||||||
|  |  | ||||||
|         String kind = cursor.getString(cursor.getColumnIndex(KEY_KIND)); |  | ||||||
|         if (kind == null || kind.isEmpty()) kind = "?"; |         if (kind == null || kind.isEmpty()) kind = "?"; | ||||||
|  |  | ||||||
|         String path = cursor.getString(cursor.getColumnIndexOrThrow(KEY_PATH)); |         String path = cursor.getString(cursor.getColumnIndexOrThrow(KEY_PATH)); | ||||||
| @@ -186,15 +185,13 @@ public class FinishedMissionStore extends SQLiteOpenHelper { | |||||||
|     } |     } | ||||||
|  |  | ||||||
|     public void addFinishedMission(DownloadMission downloadMission) { |     public void addFinishedMission(DownloadMission downloadMission) { | ||||||
|         if (downloadMission == null) throw new NullPointerException("downloadMission is null"); |         ContentValues values = getValuesOfMission(Objects.requireNonNull(downloadMission)); | ||||||
|         SQLiteDatabase database = getWritableDatabase(); |         SQLiteDatabase database = getWritableDatabase(); | ||||||
|         ContentValues values = getValuesOfMission(downloadMission); |  | ||||||
|         database.insert(FINISHED_TABLE_NAME, null, values); |         database.insert(FINISHED_TABLE_NAME, null, values); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     public void deleteMission(Mission mission) { |     public void deleteMission(Mission mission) { | ||||||
|         if (mission == null) throw new NullPointerException("mission is null"); |         String ts = String.valueOf(Objects.requireNonNull(mission).timestamp); | ||||||
|         String ts = String.valueOf(mission.timestamp); |  | ||||||
|  |  | ||||||
|         SQLiteDatabase database = getWritableDatabase(); |         SQLiteDatabase database = getWritableDatabase(); | ||||||
|  |  | ||||||
| @@ -212,9 +209,8 @@ public class FinishedMissionStore extends SQLiteOpenHelper { | |||||||
|     } |     } | ||||||
|  |  | ||||||
|     public void updateMission(Mission mission) { |     public void updateMission(Mission mission) { | ||||||
|         if (mission == null) throw new NullPointerException("mission is null"); |         ContentValues values = getValuesOfMission(Objects.requireNonNull(mission)); | ||||||
|         SQLiteDatabase database = getWritableDatabase(); |         SQLiteDatabase database = getWritableDatabase(); | ||||||
|         ContentValues values = getValuesOfMission(mission); |  | ||||||
|         String ts = String.valueOf(mission.timestamp); |         String ts = String.valueOf(mission.timestamp); | ||||||
|  |  | ||||||
|         int rowsAffected; |         int rowsAffected; | ||||||
|   | |||||||
| @@ -7,6 +7,7 @@ import org.schabi.newpipe.streams.io.SharpStream; | |||||||
| import java.io.File; | import java.io.File; | ||||||
| import java.io.FileNotFoundException; | import java.io.FileNotFoundException; | ||||||
| import java.io.IOException; | import java.io.IOException; | ||||||
|  | import java.util.Objects; | ||||||
|  |  | ||||||
| public class CircularFileWriter extends SharpStream { | public class CircularFileWriter extends SharpStream { | ||||||
|  |  | ||||||
| @@ -27,9 +28,7 @@ public class CircularFileWriter extends SharpStream { | |||||||
|     private BufferedFile aux; |     private BufferedFile aux; | ||||||
|  |  | ||||||
|     public CircularFileWriter(SharpStream target, File temp, OffsetChecker checker) throws IOException { |     public CircularFileWriter(SharpStream target, File temp, OffsetChecker checker) throws IOException { | ||||||
|         if (checker == null) { |         Objects.requireNonNull(checker); | ||||||
|             throw new NullPointerException("checker is null"); |  | ||||||
|         } |  | ||||||
|  |  | ||||||
|         if (!temp.exists()) { |         if (!temp.exists()) { | ||||||
|             if (!temp.createNewFile()) { |             if (!temp.createNewFile()) { | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 Robin
					Robin