diff options
author | ByteHamster <info@bytehamster.com> | 2021-03-27 22:31:10 +0100 |
---|---|---|
committer | ByteHamster <info@bytehamster.com> | 2021-03-28 22:32:40 +0200 |
commit | 998535515bae8ec5bcd2bd95bc0cf4f34416dff7 (patch) | |
tree | 0e069520f4ef706b428e587cccfd94c0434f3600 /core/src | |
parent | b1e15e8704f459014d76332014e81c3619bbc51c (diff) | |
download | AntennaPod-998535515bae8ec5bcd2bd95bc0cf4f34416dff7.zip |
Make AntennaPod pass the medium SpotBugs findings
Diffstat (limited to 'core/src')
9 files changed, 16 insertions, 12 deletions
diff --git a/core/src/main/java/de/danoeh/antennapod/core/backup/OpmlBackupAgent.java b/core/src/main/java/de/danoeh/antennapod/core/backup/OpmlBackupAgent.java index c05e2e9f1..6ca84ff87 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/backup/OpmlBackupAgent.java +++ b/core/src/main/java/de/danoeh/antennapod/core/backup/OpmlBackupAgent.java @@ -94,7 +94,7 @@ public class OpmlBackupAgent extends BackupAgentHelper { if (len != -1) { byte[] oldChecksum = new byte[len]; - inState.read(oldChecksum); + IOUtils.read(inState, oldChecksum, 0, len); Log.d(TAG, "Old checksum: " + new BigInteger(1, oldChecksum).toString(16)); if (Arrays.equals(oldChecksum, newChecksum)) { diff --git a/core/src/main/java/de/danoeh/antennapod/core/feed/Chapter.java b/core/src/main/java/de/danoeh/antennapod/core/feed/Chapter.java index 08a531d17..1c13471a5 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/feed/Chapter.java +++ b/core/src/main/java/de/danoeh/antennapod/core/feed/Chapter.java @@ -43,7 +43,7 @@ public abstract class Chapter extends FeedComponent { String imageUrl = cursor.getString(indexImage); int chapterType = cursor.getInt(indexChapterType); - Chapter chapter = null; + Chapter chapter; switch (chapterType) { case SimpleChapter.CHAPTERTYPE_SIMPLECHAPTER: chapter = new SimpleChapter(start, title, link, imageUrl); @@ -54,6 +54,8 @@ public abstract class Chapter extends FeedComponent { case VorbisCommentChapter.CHAPTERTYPE_VORBISCOMMENT_CHAPTER: chapter = new VorbisCommentChapter(start, title, link, imageUrl); break; + default: + throw new IllegalArgumentException("Unknown chapter type"); } chapter.setId(id); return chapter; diff --git a/core/src/main/java/de/danoeh/antennapod/core/feed/FeedItem.java b/core/src/main/java/de/danoeh/antennapod/core/feed/FeedItem.java index 47df099b5..25857dad2 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/feed/FeedItem.java +++ b/core/src/main/java/de/danoeh/antennapod/core/feed/FeedItem.java @@ -65,7 +65,7 @@ public class FeedItem extends FeedComponent implements Serializable { * The list of chapters of this item. This might be null even if there are chapters of this item * in the database. The 'hasChapters' attribute should be used to check if this item has any chapters. * */ - private List<Chapter> chapters; + private transient List<Chapter> chapters; private String imageUrl; /* diff --git a/core/src/main/java/de/danoeh/antennapod/core/service/download/HttpDownloader.java b/core/src/main/java/de/danoeh/antennapod/core/service/download/HttpDownloader.java index 2d955859f..5050225f7 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/service/download/HttpDownloader.java +++ b/core/src/main/java/de/danoeh/antennapod/core/service/download/HttpDownloader.java @@ -188,8 +188,11 @@ public class HttpDownloader extends Downloader { out = new RandomAccessFile(destination, "rw"); out.seek(request.getSoFar()); } else { - destination.delete(); - destination.createNewFile(); + boolean success = destination.delete(); + success |= destination.createNewFile(); + if (!success) { + throw new IOException("Unable to recreate partially downloaded file"); + } out = new RandomAccessFile(destination, "rw"); } diff --git a/core/src/main/java/de/danoeh/antennapod/core/service/playback/PlaybackServiceMediaPlayer.java b/core/src/main/java/de/danoeh/antennapod/core/service/playback/PlaybackServiceMediaPlayer.java index 1f047ceee..785784497 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/service/playback/PlaybackServiceMediaPlayer.java +++ b/core/src/main/java/de/danoeh/antennapod/core/service/playback/PlaybackServiceMediaPlayer.java @@ -217,7 +217,7 @@ public abstract class PlaybackServiceMediaPlayer { * could result in nonsensical results (like a status of PLAYING, but a null playable) * @return the current player status */ - public PlayerStatus getPlayerStatus() { + public synchronized PlayerStatus getPlayerStatus() { return playerStatus; } diff --git a/core/src/main/java/de/danoeh/antennapod/core/storage/DatabaseExporter.java b/core/src/main/java/de/danoeh/antennapod/core/storage/DatabaseExporter.java index 271babc6e..a0fac0c74 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/storage/DatabaseExporter.java +++ b/core/src/main/java/de/danoeh/antennapod/core/storage/DatabaseExporter.java @@ -91,7 +91,10 @@ public class DatabaseExporter { db.close(); File currentDB = context.getDatabasePath(PodDBAdapter.DATABASE_NAME); - currentDB.delete(); + boolean success = currentDB.delete(); + if (!success) { + throw new IOException("Unable to delete old database"); + } FileUtils.moveFile(tempDB, currentDB); } catch (IOException | SQLiteException e) { Log.e(TAG, Log.getStackTraceString(e)); diff --git a/core/src/main/java/de/danoeh/antennapod/core/storage/PodDBAdapter.java b/core/src/main/java/de/danoeh/antennapod/core/storage/PodDBAdapter.java index 98d5e6310..7ab776856 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/storage/PodDBAdapter.java +++ b/core/src/main/java/de/danoeh/antennapod/core/storage/PodDBAdapter.java @@ -331,7 +331,7 @@ public class PodDBAdapter { PodDBAdapter.context = context.getApplicationContext(); } - public static PodDBAdapter getInstance() { + public static synchronized PodDBAdapter getInstance() { if (instance == null) { instance = new PodDBAdapter(); } diff --git a/core/src/play/java/de/danoeh/antennapod/core/cast/CastUtils.java b/core/src/play/java/de/danoeh/antennapod/core/cast/CastUtils.java index 86c85de6b..248f6dc46 100644 --- a/core/src/play/java/de/danoeh/antennapod/core/cast/CastUtils.java +++ b/core/src/play/java/de/danoeh/antennapod/core/cast/CastUtils.java @@ -35,7 +35,6 @@ public class CastUtils { public static final String KEY_FEED_URL = "de.danoeh.antennapod.core.cast.FeedUrl"; public static final String KEY_FEED_WEBSITE = "de.danoeh.antennapod.core.cast.FeedWebsite"; public static final String KEY_EPISODE_NOTES = "de.danoeh.antennapod.core.cast.EpisodeNotes"; - public static final int EPISODE_NOTES_MAX_LENGTH = Integer.MAX_VALUE; /** * The field <code>AntennaPod.FormatVersion</code> specifies which version of MediaMetaData diff --git a/core/src/play/java/de/danoeh/antennapod/core/cast/MediaInfoCreator.java b/core/src/play/java/de/danoeh/antennapod/core/cast/MediaInfoCreator.java index 91de5418d..a9df49176 100644 --- a/core/src/play/java/de/danoeh/antennapod/core/cast/MediaInfoCreator.java +++ b/core/src/play/java/de/danoeh/antennapod/core/cast/MediaInfoCreator.java @@ -39,9 +39,6 @@ public class MediaInfoCreator { } String notes = media.getNotes(); if (notes != null) { - if (notes.length() > CastUtils.EPISODE_NOTES_MAX_LENGTH) { - notes = notes.substring(0, CastUtils.EPISODE_NOTES_MAX_LENGTH); - } metadata.putString(CastUtils.KEY_EPISODE_NOTES, notes); } // Default id value |