OSDN Git Service

C# 8.0 のnull許容参照型を有効化
[opentween/open-tween.git] / OpenTween / Tween.cs
index 7bd1bdb..c7efd06 100644 (file)
@@ -24,6 +24,8 @@
 // the Free Software Foundation, Inc., 51 Franklin Street - Fifth Floor,
 // Boston, MA 02110-1301, USA.
 
+#nullable enable
+
 //コンパイル後コマンド
 //"c:\Program Files\Microsoft.NET\SDK\v2.0\Bin\sgen.exe" /f /a:"$(TargetPath)"
 //"C:\Program Files\Microsoft Visual Studio 8\SDK\v2.0\Bin\sgen.exe" /f /a:"$(TargetPath)"
@@ -33,6 +35,7 @@ using System.Collections.Concurrent;
 using System.Collections.Generic;
 using System.ComponentModel;
 using System.Diagnostics;
+using System.Diagnostics.CodeAnalysis;
 using System.Drawing;
 using System.Globalization;
 using System.IO;
@@ -93,11 +96,11 @@ namespace OpenTween
         /// <summary>タブドラッグ中フラグ(DoDragDropを実行するかの判定用)</summary>
         private bool _tabDrag;
 
-        private TabPage _beforeSelectedTab; // タブが削除されたときに前回選択されていたときのタブを選択する為に保持
+        private TabPage? _beforeSelectedTab; // タブが削除されたときに前回選択されていたときのタブを選択する為に保持
         private Point _tabMouseDownPoint;
 
         /// <summary>右クリックしたタブの名前(Tabコントロール機能不足対応)</summary>
-        private string _rclickTabName;
+        private string? _rclickTabName;
 
         private readonly object _syncObject = new object(); // ロック用
 
@@ -127,8 +130,8 @@ namespace OpenTween
             + "--></style>"
             + "</head><body><p>";
         private const string detailHtmlFormatFooterColor = "</p></body></html>";
-        private string detailHtmlFormatHeader;
-        private string detailHtmlFormatFooter;
+        private string detailHtmlFormatHeader = null!;
+        private string detailHtmlFormatFooter = null!;
 
         private bool _myStatusError = false;
         private bool _myStatusOnline = false;
@@ -137,7 +140,7 @@ namespace OpenTween
 
         //twitter解析部
         private readonly TwitterApi twitterApi = new TwitterApi();
-        private Twitter tw;
+        private Twitter tw = null!;
 
         //Growl呼び出し部
         private readonly GrowlHelper gh = new GrowlHelper(ApplicationSettings.ApplicationName);
@@ -150,24 +153,24 @@ namespace OpenTween
         private readonly OpenURL UrlDialog = new OpenURL();
 
         /// <summary>@id補助</summary>
-        public AtIdSupplement AtIdSupl;
+        public AtIdSupplement AtIdSupl = null!;
 
         /// <summary>Hashtag補助</summary>
-        public AtIdSupplement HashSupl;
+        public AtIdSupplement HashSupl = null!;
 
-        public HashtagManage HashMgr;
-        private EventViewerDialog evtDialog;
+        public HashtagManage HashMgr = null!;
+        private EventViewerDialog evtDialog = null!;
 
         //表示フォント、色、アイコン
 
         /// <summary>未読用フォント</summary>
-        private Font _fntUnread;
+        private Font _fntUnread = null!;
 
         /// <summary>未読用文字色</summary>
         private Color _clUnread;
 
         /// <summary>既読用フォント</summary>
-        private Font _fntReaded;
+        private Font _fntReaded = null!;
 
         /// <summary>既読用文字色</summary>
         private Color _clReaded;
@@ -185,7 +188,7 @@ namespace OpenTween
         private readonly Color _clHighLight = Color.FromKnownColor(KnownColor.HighlightText);
 
         /// <summary>発言詳細部用フォント</summary>
-        private Font _fntDetail;
+        private Font _fntDetail = null!;
 
         /// <summary>発言詳細部用色</summary>
         private Color _clDetail;
@@ -224,36 +227,36 @@ namespace OpenTween
         private Color _clInputFont;
 
         /// <summary>入力欄フォント</summary>
-        private Font _fntInputFont;
+        private Font _fntInputFont = null!;
 
         /// <summary>アイコン画像リスト</summary>
-        private ImageCache IconCache;
+        private ImageCache IconCache = null!;
 
         /// <summary>タスクトレイアイコン:通常時 (At.ico)</summary>
-        private Icon NIconAt;
+        private Icon NIconAt = null!;
 
         /// <summary>タスクトレイアイコン:通信エラー時 (AtRed.ico)</summary>
-        private Icon NIconAtRed;
+        private Icon NIconAtRed = null!;
 
         /// <summary>タスクトレイアイコン:オフライン時 (AtSmoke.ico)</summary>
-        private Icon NIconAtSmoke;
+        private Icon NIconAtSmoke = null!;
 
         /// <summary>タスクトレイアイコン:更新中 (Refresh.ico)</summary>
         private Icon[] NIconRefresh = new Icon[4];
 
         /// <summary>未読のあるタブ用アイコン (Tab.ico)</summary>
-        private Icon TabIcon;
+        private Icon TabIcon = null!;
 
         /// <summary>画面左上のアイコン (Main.ico)</summary>
-        private Icon MainIcon;
+        private Icon MainIcon = null!;
 
-        private Icon ReplyIcon;
-        private Icon ReplyIconBlink;
+        private Icon ReplyIcon = null!;
+        private Icon ReplyIconBlink = null!;
 
-        private readonly ImageList _listViewImageList = new ImageList(); // ListViewItemの高さ変更用
+        private readonly ImageList _listViewImageList = new ImageList();    //ListViewItemの高さ変更用
 
-        private PostClass _anchorPost;
-        private bool _anchorFlag; // true:関連発言移動中(関連移動以外のオペレーションをするとfalseへ。trueだとリスト背景色をアンカー発言選択中として描画)
+        private PostClass? _anchorPost;
+        private bool _anchorFlag;        //true:関連発言移動中(関連移動以外のオペレーションをするとfalseへ。trueだとリスト背景色をアンカー発言選択中として描画)
 
         /// <summary>発言履歴</summary>
         private readonly List<StatusTextHistory> _history = new List<StatusTextHistory>();
@@ -272,13 +275,13 @@ namespace OpenTween
 
         // 以下DrawItem関連
         private readonly SolidBrush _brsHighLight = new SolidBrush(Color.FromKnownColor(KnownColor.Highlight));
-        private SolidBrush _brsBackColorMine;
-        private SolidBrush _brsBackColorAt;
-        private SolidBrush _brsBackColorYou;
-        private SolidBrush _brsBackColorAtYou;
-        private SolidBrush _brsBackColorAtFromTarget;
-        private SolidBrush _brsBackColorAtTo;
-        private SolidBrush _brsBackColorNone;
+        private SolidBrush _brsBackColorMine = null!;
+        private SolidBrush _brsBackColorAt = null!;
+        private SolidBrush _brsBackColorYou = null!;
+        private SolidBrush _brsBackColorAtYou = null!;
+        private SolidBrush _brsBackColorAtFromTarget = null!;
+        private SolidBrush _brsBackColorAtTo = null!;
+        private SolidBrush _brsBackColorNone = null!;
 
         /// <summary>Listにフォーカスないときの選択行の背景色</summary>
         private readonly SolidBrush _brsDeactiveSelection = new SolidBrush(Color.FromKnownColor(KnownColor.ButtonFace));
@@ -286,7 +289,7 @@ namespace OpenTween
         private readonly StringFormat sfTab = new StringFormat();
 
         //////////////////////////////////////////////////////////////////////////////////////////////////////////
-        private TabInformations _statuses;
+        private TabInformations _statuses = null!;
 
         /// <summary>
         /// 現在表示している発言一覧の <see cref="ListView"/> に対するキャッシュ
@@ -296,12 +299,12 @@ namespace OpenTween
         /// 使用する場合には <see cref="_listItemCache"/> に対して直接メソッド等を呼び出さずに
         /// 一旦ローカル変数に代入してから参照すること。
         /// </remarks>
-        private ListViewItemCache _listItemCache = null;
+        private ListViewItemCache? _listItemCache = null;
 
         internal class ListViewItemCache
         {
             /// <summary>アイテムをキャッシュする対象の <see cref="ListView"/></summary>
-            public ListView TargetList { get; set; }
+            public ListView TargetList { get; set; } = null!;
 
             /// <summary>キャッシュする範囲の開始インデックス</summary>
             public int StartIndex { get; set; }
@@ -310,7 +313,7 @@ namespace OpenTween
             public int EndIndex { get; set; }
 
             /// <summary>キャッシュされた範囲に対応する <see cref="ListViewItem"/> と <see cref="PostClass"/> の組</summary>
-            public (ListViewItem, PostClass)[] Cache { get; set; }
+            public (ListViewItem, PostClass)[] Cache { get; set; } = null!;
 
             /// <summary>キャッシュされたアイテムの件数</summary>
             public int Count
@@ -328,7 +331,7 @@ namespace OpenTween
 
             /// <summary>指定されたインデックスの <see cref="ListViewItem"/> と <see cref="PostClass"/> をキャッシュから取得することを試みます</summary>
             /// <returns>取得に成功すれば true、それ以外は false</returns>
-            public bool TryGetValue(int index, out ListViewItem item, out PostClass post)
+            public bool TryGetValue(int index, [NotNullWhen(true)] out ListViewItem? item, [NotNullWhen(true)] out PostClass? post)
             {
                 if (this.Contains(index))
                 {
@@ -349,7 +352,7 @@ namespace OpenTween
         private const int MAX_WORKER_THREADS = 20;
         private readonly SemaphoreSlim workerSemaphore = new SemaphoreSlim(MAX_WORKER_THREADS);
         private readonly CancellationTokenSource workerCts = new CancellationTokenSource();
-        private readonly IProgress<string> workerProgress;
+        private readonly IProgress<string> workerProgress = null!;
 
         private int UnreadCounter = -1;
         private int UnreadAtCounter = -1;
@@ -362,12 +365,12 @@ namespace OpenTween
         //////////////////////////////////////////////////////////////////////////////////////////////////////////
 
         private readonly TimelineScheduler timelineScheduler = new TimelineScheduler();
-        private ThrottlingTimer RefreshThrottlingTimer;
-        private ThrottlingTimer colorizeDebouncer;
-        private ThrottlingTimer selectionDebouncer;
-        private ThrottlingTimer saveConfigDebouncer;
+        private ThrottlingTimer RefreshThrottlingTimer = null!;
+        private ThrottlingTimer colorizeDebouncer = null!;
+        private ThrottlingTimer selectionDebouncer = null!;
+        private ThrottlingTimer saveConfigDebouncer = null!;
 
-        private string recommendedStatusFooter;
+        private string recommendedStatusFooter = null!;
         private bool urlMultibyteSplit = false;
         private bool preventSmsCommand = true;
 
@@ -378,7 +381,7 @@ namespace OpenTween
             public string After;
         }
 
-        private List<urlUndo> urlUndoBuffer = null;
+        private List<urlUndo>? urlUndoBuffer = null;
 
         private readonly struct ReplyChain
         {
@@ -395,10 +398,10 @@ namespace OpenTween
         }
 
         /// <summary>[, ]でのリプライ移動の履歴</summary>
-        private Stack<ReplyChain> replyChains;
+        private Stack<ReplyChain>? replyChains;
 
         /// <summary>ポスト選択履歴</summary>
-        private readonly Stack<(TabModel, PostClass)> selectPostChains = new Stack<(TabModel, PostClass)>();
+        private readonly Stack<(TabModel, PostClass?)> selectPostChains = new Stack<(TabModel, PostClass?)>();
 
         public TabModel CurrentTab
             => this._statuses.SelectedTab;
@@ -412,7 +415,7 @@ namespace OpenTween
         public DetailsListView CurrentListView
             => (DetailsListView)this.CurrentTabPage.Tag;
 
-        public PostClass CurrentPost
+        public PostClass? CurrentPost
             => this.CurrentTab.SelectedPost;
 
         /// <summary>検索処理タイプ</summary>
@@ -431,7 +434,7 @@ namespace OpenTween
             /// <summary>画像投稿サービス名</summary>
             public string imageService = "";
 
-            public IMediaItem[] mediaItems = null;
+            public IMediaItem[]? mediaItems = null;
             public StatusTextHistory()
             {
             }
@@ -592,7 +595,7 @@ namespace OpenTween
             }
         }
 
-        private Icon LoadIcon(string filePath)
+        private Icon? LoadIcon(string filePath)
         {
             if (!File.Exists(filePath))
                 return null;
@@ -611,7 +614,7 @@ namespace OpenTween
         {
             this.InitColumnText();
 
-            ColumnHeader[] columns = null;
+            ColumnHeader[]? columns = null;
             try
             {
                 if (this._iconCol)
@@ -1241,7 +1244,7 @@ namespace OpenTween
             TimerRefreshIcon.Enabled = false;
 
             _ignoreConfigSave = false;
-            this.TweenMain_Resize(null, null);
+            this.TweenMain_Resize(this, EventArgs.Empty);
             if (saveRequired) SaveConfigsAll(false);
 
             foreach (var ua in SettingManager.Common.UserAccounts)
@@ -1344,7 +1347,7 @@ namespace OpenTween
                         tab = new FilterTabModel(tabSetting.TabName);
                         break;
                     case MyCommon.TabUsageType.UserTimeline:
-                        tab = new UserTimelineTabModel(tabSetting.TabName, tabSetting.User);
+                        tab = new UserTimelineTabModel(tabSetting.TabName, tabSetting.User!);
                         break;
                     case MyCommon.TabUsageType.PublicSearch:
                         tab = new PublicSearchTabModel(tabSetting.TabName)
@@ -1354,7 +1357,7 @@ namespace OpenTween
                         };
                         break;
                     case MyCommon.TabUsageType.Lists:
-                        tab = new ListTimelineTabModel(tabSetting.TabName, tabSetting.ListInfo);
+                        tab = new ListTimelineTabModel(tabSetting.TabName, tabSetting.ListInfo!);
                         break;
                     case MyCommon.TabUsageType.Mute:
                         tab = new MuteTabModel(tabSetting.TabName);
@@ -1604,7 +1607,7 @@ namespace OpenTween
 
         internal struct ListViewSelection
         {
-            public long[] SelectedStatusIds { get; set; }
+            public long[]? SelectedStatusIds { get; set; }
             public long? SelectionMarkStatusId { get; set; }
             public long? FocusedStatusId { get; set; }
         }
@@ -1706,7 +1709,7 @@ namespace OpenTween
         private void RestoreListViewSelection(DetailsListView listView, TabModel tab, ListViewSelection listSelection)
         {
             // status_id から ListView 上のインデックスに変換
-            int[] selectedIndices = null;
+            int[]? selectedIndices = null;
             if (listSelection.SelectedStatusIds != null)
                 selectedIndices = tab.IndexOf(listSelection.SelectedStatusIds).Where(x => x != -1).ToArray();
 
@@ -1982,7 +1985,7 @@ namespace OpenTween
 
             this.PushSelectPostChain();
 
-            var post = this.CurrentPost;
+            var post = this.CurrentPost!;
             this._statuses.SetReadAllTab(post.StatusId, read: true);
 
             //キャッシュの書き換え
@@ -2011,7 +2014,7 @@ namespace OpenTween
             ChangeItemStyleRead(Read, itm, post, (DetailsListView)listCache.TargetList);
         }
 
-        private void ChangeItemStyleRead(bool Read, ListViewItem Item, PostClass Post, DetailsListView DList)
+        private void ChangeItemStyleRead(bool Read, ListViewItem Item, PostClass Post, DetailsListView? DList)
         {
             Font fnt;
             string star;
@@ -2063,7 +2066,7 @@ namespace OpenTween
         {
             //Index:更新対象のListviewItem.Index。Colorを返す。
             //-1は全キャッシュ。Colorは返さない(ダミーを戻す)
-            PostClass _post;
+            PostClass? _post;
             if (_anchorFlag)
                 _post = _anchorPost;
             else
@@ -2091,7 +2094,7 @@ namespace OpenTween
         {
             //Index:更新対象のListviewItem.Index。Colorを返す。
             //-1は全キャッシュ。Colorは返さない(ダミーを戻す)
-            PostClass _post;
+            PostClass? _post;
             if (_anchorFlag)
                 _post = _anchorPost;
             else
@@ -2175,7 +2178,7 @@ namespace OpenTween
             }
 
             var currentPost = this.CurrentPost;
-            if (this.ExistCurrentPost && StatusText.Text.Trim() == string.Format("RT @{0}: {1}", currentPost.ScreenName, currentPost.TextFromApi))
+            if (this.ExistCurrentPost && currentPost != null && StatusText.Text.Trim() == string.Format("RT @{0}: {1}", currentPost.ScreenName, currentPost.TextFromApi))
             {
                 var rtResult = MessageBox.Show(string.Format(Properties.Resources.PostButton_Click1, Environment.NewLine),
                                                                "Retweet",
@@ -2259,8 +2262,8 @@ namespace OpenTween
                     return;
             }
 
-            IMediaUploadService uploadService = null;
-            IMediaItem[] uploadItems = null;
+            IMediaUploadService? uploadService = null;
+            IMediaItem[]? uploadItems = null;
             if (ImageSelector.Visible)
             {
                 //画像投稿
@@ -2465,7 +2468,7 @@ namespace OpenTween
                             .ConfigureAwait(false);
                     }
                     catch (TwitterApiException ex)
-                        when (ex.ErrorResponse.Errors.All(x => x.Code == TwitterErrorCode.AlreadyFavorited))
+                        when (ex.Errors.All(x => x.Code == TwitterErrorCode.AlreadyFavorited))
                     {
                         // エラーコード 139 のみの場合は成功と見なす
                     }
@@ -2482,12 +2485,11 @@ namespace OpenTween
                     this._favTimestamps.Add(DateTimeUtc.Now);
 
                     // TLでも取得済みならfav反映
-                    if (this._statuses.ContainsKey(statusId))
+                    if (this._statuses.Posts.TryGetValue(statusId, out var postTl))
                     {
-                        var postTl = this._statuses[statusId];
                         postTl.IsFav = true;
 
-                        var favTab = this._statuses.GetTabByType(MyCommon.TabUsageType.Favorites);
+                        var favTab = this._statuses.FavoriteTab;
                         favTab.AddPostQueue(postTl);
                     }
 
@@ -2600,10 +2602,8 @@ namespace OpenTween
                     successIds.Add(statusId);
                     post.IsFav = false; // リスト再描画必要
 
-                    if (this._statuses.ContainsKey(statusId))
-                    {
-                        this._statuses[statusId].IsFav = false;
-                    }
+                    if (this._statuses.Posts.TryGetValue(statusId, out var tabinfoPost))
+                        tabinfoPost.IsFav = false;
 
                     // 検索,リスト,UserTimeline,Relatedの各タブに反映
                     foreach (var tb in this._statuses.GetTabsInnerStorageType())
@@ -2617,7 +2617,7 @@ namespace OpenTween
             if (ct.IsCancellationRequested)
                 return;
 
-            var favTab = this._statuses.GetTabByType(MyCommon.TabUsageType.Favorites);
+            var favTab = this._statuses.FavoriteTab;
             foreach (var statusId in successIds)
             {
                 // ツイートが削除された訳ではないので IsDeleted はセットしない
@@ -2654,7 +2654,7 @@ namespace OpenTween
             }
         }
 
-        private async Task PostMessageAsync(PostStatusParams postParams, IMediaUploadService uploadService, IMediaItem[] uploadItems)
+        private async Task PostMessageAsync(PostStatusParams postParams, IMediaUploadService? uploadService, IMediaItem[]? uploadItems)
         {
             await this.workerSemaphore.WaitAsync();
             this.RefreshTasktrayIcon();
@@ -2677,7 +2677,7 @@ namespace OpenTween
         }
 
         private async Task PostMessageAsyncInternal(IProgress<string> p, CancellationToken ct, PostStatusParams postParams,
-            IMediaUploadService uploadService, IMediaItem[] uploadItems)
+            IMediaUploadService? uploadService, IMediaItem[]? uploadItems)
         {
             if (ct.IsCancellationRequested)
                 return;
@@ -2687,7 +2687,7 @@ namespace OpenTween
 
             p.Report("Posting...");
 
-            PostClass post = null;
+            PostClass? post = null;
             var errMsg = "";
 
             try
@@ -3032,13 +3032,13 @@ namespace OpenTween
                     await ShowUserTimeline();
                     break;
                 case 4:
-                    ShowRelatedStatusesMenuItem_Click(null, null);
+                    ShowRelatedStatusesMenuItem_Click(this.ShowRelatedStatusesMenuItem, EventArgs.Empty);
                     break;
                 case 5:
-                    MoveToHomeToolStripMenuItem_Click(null, null);
+                    MoveToHomeToolStripMenuItem_Click(this.MoveToHomeToolStripMenuItem, EventArgs.Empty);
                     break;
                 case 6:
-                    StatusOpenMenuItem_Click(null, null);
+                    StatusOpenMenuItem_Click(this.StatusOpenMenuItem, EventArgs.Empty);
                     break;
                 case 7:
                     //動作なし
@@ -3320,7 +3320,7 @@ namespace OpenTween
             }
             var tab = this.CurrentTab;
             var post = this.CurrentPost;
-            if (tab.TabType == MyCommon.TabUsageType.DirectMessage || !this.ExistCurrentPost || post.IsDm)
+            if (tab.TabType == MyCommon.TabUsageType.DirectMessage || !this.ExistCurrentPost || post == null || post.IsDm)
             {
                 FavAddToolStripMenuItem.Enabled = false;
                 FavRemoveToolStripMenuItem.Enabled = false;
@@ -3365,7 +3365,7 @@ namespace OpenTween
             //{
             //    RefreshMoreStripMenuItem.Enabled = false;
             //}
-            if (!this.ExistCurrentPost || post.InReplyToStatusId == null)
+            if (!this.ExistCurrentPost || post == null || post.InReplyToStatusId == null)
             {
                 RepliedStatusOpenMenuItem.Enabled = false;
             }
@@ -3373,7 +3373,7 @@ namespace OpenTween
             {
                 RepliedStatusOpenMenuItem.Enabled = true;
             }
-            if (!this.ExistCurrentPost || string.IsNullOrEmpty(post.RetweetedBy))
+            if (!this.ExistCurrentPost || post == null || string.IsNullOrEmpty(post.RetweetedBy))
             {
                 MoveToRTHomeMenuItem.Enabled = false;
             }
@@ -3382,7 +3382,7 @@ namespace OpenTween
                 MoveToRTHomeMenuItem.Enabled = true;
             }
 
-            if (this.ExistCurrentPost)
+            if (this.ExistCurrentPost && post != null)
             {
                 this.DeleteStripMenuItem.Enabled = post.CanDeleteBy(this.tw.UserId);
                 if (post.RetweetedByUserId == this.tw.UserId)
@@ -3421,7 +3421,7 @@ namespace OpenTween
 
             using (ControlTransaction.Cursor(this, Cursors.WaitCursor))
             {
-                Exception lastException = null;
+                Exception? lastException = null;
                 foreach (var post in posts)
                 {
                     if (!post.CanDeleteBy(this.tw.UserId))
@@ -3843,7 +3843,7 @@ namespace OpenTween
                     if (SettingManager.Common.IsUseNotifyGrowl) gh.RegisterGrowl();
                     try
                     {
-                        StatusText_TextChanged(null, null);
+                        StatusText_TextChanged(this.StatusText, EventArgs.Empty);
                     }
                     catch (Exception)
                     {
@@ -3985,13 +3985,14 @@ namespace OpenTween
             cmb.Text = searchWord;
             SaveConfigsTabs();
             //検索実行
-            this.SearchButton_Click(tabPage.Controls["panelSearch"].Controls["comboSearch"], null);
+            this.SearchButton_Click(tabPage.Controls["panelSearch"].Controls["comboSearch"], EventArgs.Empty);
         }
 
         private async Task ShowUserTimeline()
         {
-            if (!this.ExistCurrentPost) return;
-            await this.AddNewTabForUserTimeline(this.CurrentPost.ScreenName);
+            var post = this.CurrentPost;
+            if (post == null || !this.ExistCurrentPost) return;
+            await this.AddNewTabForUserTimeline(post.ScreenName);
         }
 
         private void SearchComboBox_KeyDown(object sender, KeyEventArgs e)
@@ -4240,7 +4241,8 @@ namespace OpenTween
         public bool RemoveSpecifiedTab(string TabName, bool confirm)
         {
             var tabInfo = _statuses.GetTabByName(TabName);
-            if (tabInfo.IsDefaultTabType || tabInfo.Protected) return false;
+            if (tabInfo == null || tabInfo.IsDefaultTabType || tabInfo.Protected)
+                return false;
 
             if (confirm)
             {
@@ -4552,11 +4554,11 @@ namespace OpenTween
                     {
                         e.Handled = true;
                         StatusText.Text = "";
-                        JumpUnreadMenuItem_Click(null, null);
+                        JumpUnreadMenuItem_Click(this.JumpUnreadMenuItem, EventArgs.Empty);
                     }
                 }
             }
-            this.StatusText_TextChanged(null, null);
+            this.StatusText_TextChanged(this.StatusText, EventArgs.Empty);
         }
 
         private void StatusText_TextChanged(object sender, EventArgs e)
@@ -4641,7 +4643,7 @@ namespace OpenTween
         /// <summary>
         /// attachment_url に指定可能な URL が含まれていれば除去
         /// </summary>
-        private string RemoveAttachmentUrl(string statusText, out string attachmentUrl)
+        private string RemoveAttachmentUrl(string statusText, out string? attachmentUrl)
         {
             attachmentUrl = null;
 
@@ -4668,7 +4670,7 @@ namespace OpenTween
         /// <summary>
         /// <see cref="FormatStatusText"/> に加えて、拡張モードで140字にカウントされない文字列の除去を行います
         /// </summary>
-        private string FormatStatusTextExtended(string statusText, out long[] autoPopulatedUserIds, out string attachmentUrl)
+        private string FormatStatusTextExtended(string statusText, out long[] autoPopulatedUserIds, out string? attachmentUrl)
         {
             statusText = this.RemoveAutoPopuratedMentions(statusText, out autoPopulatedUserIds);
 
@@ -4788,7 +4790,7 @@ namespace OpenTween
             return remainCount;
         }
 
-        private IMediaUploadService GetSelectedImageService()
+        private IMediaUploadService? GetSelectedImageService()
             => this.ImageSelector.Visible ? this.ImageSelector.SelectedService : null;
 
         private void MyList_CacheVirtualItems(object sender, CacheVirtualItemsEventArgs e)
@@ -5346,7 +5348,7 @@ namespace OpenTween
             }
             this.TopMost = SettingManager.Common.AlwaysTop;
 
-            var searchOptions = this.SearchDialog.ResultOptions;
+            var searchOptions = this.SearchDialog.ResultOptions!;
             if (searchOptions.Type == SearchWordDialog.SearchType.Timeline)
             {
                 if (searchOptions.NewTab)
@@ -5450,11 +5452,9 @@ namespace OpenTween
             if (ImageSelector.Enabled)
                 return;
 
-            TabModel foundTab = null;
+            TabModel? foundTab = null;
             var foundIndex = 0;
 
-            DetailsListView lst = null;
-
             //現在タブから最終タブまで探索
             foreach (var (tab, index) in this._statuses.Tabs.WithIndex().Skip(bgnIdx))
             {
@@ -5464,7 +5464,6 @@ namespace OpenTween
                     ListTab.SelectedIndex = index;
                     foundTab = tab;
                     foundIndex = unreadIndex;
-                    lst = (DetailsListView)this.ListTab.TabPages[index].Tag;
                     break;
                 }
             }
@@ -5480,12 +5479,13 @@ namespace OpenTween
                         ListTab.SelectedIndex = index;
                         foundTab = tab;
                         foundIndex = unreadIndex;
-                        lst = (DetailsListView)this.ListTab.TabPages[index].Tag;
                         break;
                     }
                 }
             }
 
+            DetailsListView lst;
+
             if (foundTab == null)
             {
                 //全部調べたが未読見つからず→先頭タブの最新発言へ
@@ -5503,6 +5503,11 @@ namespace OpenTween
 
                 lst = (DetailsListView)tabPage.Tag;
             }
+            else
+            {
+                var foundTabIndex = this._statuses.Tabs.IndexOf(foundTab);
+                lst = (DetailsListView)this.ListTab.TabPages[foundTabIndex].Tag;
+            }
 
             SelectListItem(lst, foundIndex);
 
@@ -5559,9 +5564,12 @@ namespace OpenTween
 
         public class VersionInfo
         {
-            public Version Version { get; set; }
-            public Uri DownloadUri { get; set; }
-            public string ReleaseNote { get; set; }
+            public Version Version { get; }
+            public Uri DownloadUri { get; }
+            public string ReleaseNote { get; }
+
+            public VersionInfo(Version version, Uri downloadUri, string releaseNote)
+                => (this.Version, this.DownloadUri, this.ReleaseNote) = (version, downloadUri, releaseNote);
         }
 
         /// <summary>
@@ -5583,12 +5591,11 @@ namespace OpenTween
 
             msgBody = Regex.Replace(msgBody, "(?<!\r)\n", "\r\n"); // LF -> CRLF
 
-            return new VersionInfo
-            {
-                Version = Version.Parse(msgHeader[0]),
-                DownloadUri = new Uri(msgHeader[1]),
-                ReleaseNote = msgBody,
-            };
+            return new VersionInfo(
+                version: Version.Parse(msgHeader[0]),
+                downloadUri: new Uri(msgHeader[1]),
+                releaseNote: msgBody
+            );
         }
 
         private async Task CheckNewVersion(bool startup = false)
@@ -5691,7 +5698,7 @@ namespace OpenTween
         /// <summary>
         /// サムネイル表示に使用する CancellationToken の生成元
         /// </summary>
-        private CancellationTokenSource thumbnailTokenSource = null;
+        private CancellationTokenSource? thumbnailTokenSource = null;
 
         private void DispSelectedPost(bool forceupdate)
         {
@@ -5717,7 +5724,7 @@ namespace OpenTween
                 var oldTokenSource = Interlocked.Exchange(ref this.thumbnailTokenSource, new CancellationTokenSource());
                 oldTokenSource?.Cancel();
 
-                var token = this.thumbnailTokenSource.Token;
+                var token = this.thumbnailTokenSource!.Token;
                 loadTasks.Add(this.tweetThumbnail1.ShowThumbnailAsync(currentPost, token));
             }
 
@@ -5794,7 +5801,7 @@ namespace OpenTween
                     .Do(() => this.OpenApplicationWebsite()),
 
                 ShortcutCommand.Create(Keys.F3)
-                    .Do(() => this.MenuItemSearchNext_Click(null, null)),
+                    .Do(() => this.MenuItemSearchNext_Click(this.MenuItemSearchNext, EventArgs.Empty)),
 
                 ShortcutCommand.Create(Keys.F5)
                     .Do(() => this.DoRefresh()),
@@ -5807,11 +5814,11 @@ namespace OpenTween
 
                 ShortcutCommand.Create(Keys.Space, Keys.ProcessKey)
                     .NotFocusedOn(FocusedControl.StatusText)
-                    .Do(() => { this._anchorFlag = false; this.JumpUnreadMenuItem_Click(null, null); }),
+                    .Do(() => { this._anchorFlag = false; this.JumpUnreadMenuItem_Click(this.JumpUnreadMenuItem, EventArgs.Empty); }),
 
                 ShortcutCommand.Create(Keys.G)
                     .NotFocusedOn(FocusedControl.StatusText)
-                    .Do(() => { this._anchorFlag = false; this.ShowRelatedStatusesMenuItem_Click(null, null); }),
+                    .Do(() => { this._anchorFlag = false; this.ShowRelatedStatusesMenuItem_Click(this.ShowRelatedStatusesMenuItem, EventArgs.Empty); }),
 
                 ShortcutCommand.Create(Keys.Right, Keys.N)
                     .FocusedOn(FocusedControl.ListTab)
@@ -5910,35 +5917,35 @@ namespace OpenTween
                     .Do(() => this.doQuoteOfficial()),
 
                 ShortcutCommand.Create(Keys.Control | Keys.B)
-                    .Do(() => this.ReadedStripMenuItem_Click(null, null)),
+                    .Do(() => this.ReadedStripMenuItem_Click(this.ReadedStripMenuItem, EventArgs.Empty)),
 
                 ShortcutCommand.Create(Keys.Control | Keys.T)
-                    .Do(() => this.HashManageMenuItem_Click(null, null)),
+                    .Do(() => this.HashManageMenuItem_Click(this.HashManageMenuItem, EventArgs.Empty)),
 
                 ShortcutCommand.Create(Keys.Control | Keys.L)
-                    .Do(() => this.UrlConvertAutoToolStripMenuItem_Click(null, null)),
+                    .Do(() => this.UrlConvertAutoToolStripMenuItem_Click(this.UrlConvertAutoToolStripMenuItem, EventArgs.Empty)),
 
                 ShortcutCommand.Create(Keys.Control | Keys.Y)
                     .NotFocusedOn(FocusedControl.PostBrowser)
-                    .Do(() => this.MultiLineMenuItem_Click(null, null)),
+                    .Do(() => this.MultiLineMenuItem_Click(this.MultiLineMenuItem, EventArgs.Empty)),
 
                 ShortcutCommand.Create(Keys.Control | Keys.F)
-                    .Do(() => this.MenuItemSubSearch_Click(null, null)),
+                    .Do(() => this.MenuItemSubSearch_Click(this.MenuItemSubSearch, EventArgs.Empty)),
 
                 ShortcutCommand.Create(Keys.Control | Keys.U)
                     .Do(() => this.ShowUserTimeline()),
 
                 ShortcutCommand.Create(Keys.Control | Keys.H)
-                    .Do(() => this.MoveToHomeToolStripMenuItem_Click(null, null)),
+                    .Do(() => this.MoveToHomeToolStripMenuItem_Click(this.MoveToHomeToolStripMenuItem, EventArgs.Empty)),
 
                 ShortcutCommand.Create(Keys.Control | Keys.G)
-                    .Do(() => this.MoveToFavToolStripMenuItem_Click(null, null)),
+                    .Do(() => this.MoveToFavToolStripMenuItem_Click(this.MoveToFavToolStripMenuItem, EventArgs.Empty)),
 
                 ShortcutCommand.Create(Keys.Control | Keys.O)
-                    .Do(() => this.StatusOpenMenuItem_Click(null, null)),
+                    .Do(() => this.StatusOpenMenuItem_Click(this.StatusOpenMenuItem, EventArgs.Empty)),
 
                 ShortcutCommand.Create(Keys.Control | Keys.E)
-                    .Do(() => this.OpenURLMenuItem_Click(null, null)),
+                    .Do(() => this.OpenURLMenuItem_Click(this.OpenURLMenuItem, EventArgs.Empty)),
 
                 ShortcutCommand.Create(Keys.Control | Keys.Home, Keys.Control | Keys.End)
                     .FocusedOn(FocusedControl.ListTab)
@@ -6055,7 +6062,7 @@ namespace OpenTween
                     }),
 
                 ShortcutCommand.Create(Keys.Shift | Keys.F3)
-                    .Do(() => this.MenuItemSearchPrev_Click(null, null)),
+                    .Do(() => this.MenuItemSearchPrev_Click(this.MenuItemSearchPrev, EventArgs.Empty)),
 
                 ShortcutCommand.Create(Keys.Shift | Keys.F5)
                     .Do(() => this.DoRefreshMore()),
@@ -6117,7 +6124,7 @@ namespace OpenTween
 
                 ShortcutCommand.Create(Keys.Alt | Keys.P)
                     .OnlyWhen(() => this.CurrentPost != null)
-                    .Do(() => this.doShowUserStatus(this.CurrentPost.ScreenName, ShowInputDialog: false)),
+                    .Do(() => this.doShowUserStatus(this.CurrentPost!.ScreenName, ShowInputDialog: false)),
 
                 ShortcutCommand.Create(Keys.Alt | Keys.Up)
                     .Do(() => this.tweetDetailsView.ScrollDownPostBrowser(forward: false)),
@@ -6154,13 +6161,13 @@ namespace OpenTween
                     .Do(() => this.FavoriteChange(FavAdd: false)),
 
                 ShortcutCommand.Create(Keys.Control | Keys.Shift | Keys.B)
-                    .Do(() => this.UnreadStripMenuItem_Click(null, null)),
+                    .Do(() => this.UnreadStripMenuItem_Click(this.UnreadStripMenuItem, EventArgs.Empty)),
 
                 ShortcutCommand.Create(Keys.Control | Keys.Shift | Keys.T)
-                    .Do(() => this.HashToggleMenuItem_Click(null, null)),
+                    .Do(() => this.HashToggleMenuItem_Click(this.HashToggleMenuItem, EventArgs.Empty)),
 
                 ShortcutCommand.Create(Keys.Control | Keys.Shift | Keys.P)
-                    .Do(() => this.ImageSelectMenuItem_Click(null, null)),
+                    .Do(() => this.ImageSelectMenuItem_Click(this.ImageSelectMenuItem, EventArgs.Empty)),
 
                 ShortcutCommand.Create(Keys.Control | Keys.Shift | Keys.H)
                     .Do(() => this.doMoveToRTHome()),
@@ -6304,7 +6311,7 @@ namespace OpenTween
             };
         }
 
-        internal bool CommonKeyDown(Keys keyData, FocusedControl focusedOn, out Task asyncTask)
+        internal bool CommonKeyDown(Keys keyData, FocusedControl focusedOn, out Task? asyncTask)
         {
             // Task を返す非同期処理があれば asyncTask に代入する
             asyncTask = null;
@@ -6547,7 +6554,7 @@ namespace OpenTween
             }
 
             string name;
-            if (currentPost.RetweetedId == null)
+            if (currentPost.RetweetedBy == null)
             {
                 name = currentPost.ScreenName;
             }
@@ -6962,7 +6969,7 @@ namespace OpenTween
             if (this.selectPostChains.Count > 1)
             {
                 var idx = -1;
-                TabModel foundTab = null;
+                TabModel? foundTab = null;
 
                 do
                 {
@@ -7037,7 +7044,7 @@ namespace OpenTween
         private void TrimPostChain()
         {
             if (this.selectPostChains.Count <= 2000) return;
-            var p = new Stack<(TabModel, PostClass)>(2000);
+            var p = new Stack<(TabModel, PostClass?)>(2000);
             for (var i = 0; i < 2000; i++)
             {
                 p.Push(this.selectPostChains.Pop());
@@ -7077,7 +7084,7 @@ namespace OpenTween
         {
             if (statusId == 0) return false;
 
-            var tab = this._statuses.GetTabByType<DirectMessagesTabModel>();
+            var tab = this._statuses.DirectMessageTab;
             var index = tab.IndexOf(statusId);
 
             if (index == -1)
@@ -7124,7 +7131,7 @@ namespace OpenTween
                 e.SuppressKeyPress = true;
             }
 
-            this.StatusText_TextChanged(null, null);
+            this.StatusText_TextChanged(this.StatusText, EventArgs.Empty);
 
             if (asyncTask != null)
                 await asyncTask;
@@ -7379,7 +7386,7 @@ namespace OpenTween
             this.TopMost = SettingManager.Common.AlwaysTop;
         }
 
-        public bool TabRename(string origTabName, out string newTabName)
+        public bool TabRename(string origTabName, [NotNullWhen(true)] out string? newTabName)
         {
             //タブ名変更
             newTabName = null;
@@ -7926,7 +7933,7 @@ namespace OpenTween
 
         private void TabMenuControl(string tabName)
         {
-            var tabInfo = _statuses.GetTabByName(tabName);
+            var tabInfo = _statuses.GetTabByName(tabName)!;
 
             this.FilterEditMenuItem.Enabled = true;
             this.EditRuleTbMenuItem.Enabled = true;
@@ -8048,7 +8055,7 @@ namespace OpenTween
 
         private void FilterEditMenuItem_Click(object sender, EventArgs e)
         {
-            if (string.IsNullOrEmpty(_rclickTabName)) _rclickTabName = _statuses.GetTabByType(MyCommon.TabUsageType.Home).TabName;
+            if (string.IsNullOrEmpty(_rclickTabName)) _rclickTabName = _statuses.HomeTab.TabName;
 
             using (var fltDialog = new FilterDialog())
             {
@@ -8064,7 +8071,7 @@ namespace OpenTween
 
         private async void AddTabMenuItem_Click(object sender, EventArgs e)
         {
-            string tabName = null;
+            string? tabName = null;
             MyCommon.TabUsageType tabUsage;
             using (var inputName = new InputTabName())
             {
@@ -8079,7 +8086,7 @@ namespace OpenTween
             if (!string.IsNullOrEmpty(tabName))
             {
                 //List対応
-                ListElement list = null;
+                ListElement? list = null;
                 if (tabUsage == MyCommon.TabUsageType.Lists)
                 {
                     using var listAvail = new ListAvailable();
@@ -8100,7 +8107,7 @@ namespace OpenTween
                         tab = new PublicSearchTabModel(tabName);
                         break;
                     case MyCommon.TabUsageType.Lists:
-                        tab = new ListTimelineTabModel(tabName, list);
+                        tab = new ListTimelineTabModel(tabName, list!);
                         break;
                     default:
                         return;
@@ -8146,7 +8153,7 @@ namespace OpenTween
 
                     fltDialog.SetCurrent(tabName);
 
-                    if (post.RetweetedId == null)
+                    if (post.RetweetedBy == null)
                     {
                         fltDialog.AddNewFilter(post.ScreenName, post.TextFromApi);
                     }
@@ -8231,7 +8238,7 @@ namespace OpenTween
                     }
                     else if (_Post)
                     {
-                        PostButton_Click(null, null);
+                        PostButton_Click(this.PostButton, EventArgs.Empty);
                         return true;
                     }
                 }
@@ -8244,7 +8251,7 @@ namespace OpenTween
                         if (tabPage.Controls["panelSearch"].Controls["comboSearch"].Focused ||
                             tabPage.Controls["panelSearch"].Controls["comboLang"].Focused)
                         {
-                            this.SearchButton_Click(tabPage.Controls["panelSearch"].Controls["comboSearch"], null);
+                            this.SearchButton_Click(tabPage.Controls["panelSearch"].Controls["comboSearch"], EventArgs.Empty);
                             return true;
                         }
                     }
@@ -8267,7 +8274,7 @@ namespace OpenTween
                 return;
 
             var screenNameArray = selectedPosts
-                .Select(x => x.RetweetedId != null ? x.RetweetedBy : x.ScreenName)
+                .Select(x => x.RetweetedBy ?? x.ScreenName)
                 .ToArray();
 
             this.AddFilterRuleByScreenName(screenNameArray);
@@ -8375,7 +8382,7 @@ namespace OpenTween
             this.SaveConfigsTabs();
         }
 
-        private bool SelectTab(out string tabName)
+        private bool SelectTab([NotNullWhen(true)] out string? tabName)
         {
             do
             {
@@ -8627,13 +8634,13 @@ namespace OpenTween
                         ttl.Append(_history[_history.Count - 2].status.Replace("\r\n", " "));
                     break;
                 case MyCommon.DispTitleEnum.UnreadRepCount:
-                    ttl.AppendFormat(Properties.Resources.SetMainWindowTitleText1, _statuses.GetTabByType(MyCommon.TabUsageType.Mentions).UnreadCount + _statuses.GetTabByType(MyCommon.TabUsageType.DirectMessage).UnreadCount);
+                    ttl.AppendFormat(Properties.Resources.SetMainWindowTitleText1, _statuses.MentionTab.UnreadCount + _statuses.DirectMessageTab.UnreadCount);
                     break;
                 case MyCommon.DispTitleEnum.UnreadAllCount:
                     ttl.AppendFormat(Properties.Resources.SetMainWindowTitleText2, ur);
                     break;
                 case MyCommon.DispTitleEnum.UnreadAllRepCount:
-                    ttl.AppendFormat(Properties.Resources.SetMainWindowTitleText3, ur, _statuses.GetTabByType(MyCommon.TabUsageType.Mentions).UnreadCount + _statuses.GetTabByType(MyCommon.TabUsageType.DirectMessage).UnreadCount);
+                    ttl.AppendFormat(Properties.Resources.SetMainWindowTitleText3, ur, _statuses.MentionTab.UnreadCount + _statuses.DirectMessageTab.UnreadCount);
                     break;
                 case MyCommon.DispTitleEnum.UnreadCountAllCount:
                     ttl.AppendFormat(Properties.Resources.SetMainWindowTitleText4, ur, al);
@@ -8659,8 +8666,8 @@ namespace OpenTween
             //ステータス欄にカウント表示
             //タブ未読数/タブ発言数 全未読数/総発言数 (未読@+未読DM数)
             if (_statuses == null) return "";
-            var tbRep = _statuses.GetTabByType(MyCommon.TabUsageType.Mentions);
-            var tbDm = _statuses.GetTabByType(MyCommon.TabUsageType.DirectMessage);
+            var tbRep = _statuses.MentionTab;
+            var tbDm = _statuses.DirectMessageTab;
             if (tbRep == null || tbDm == null) return "";
             var urat = tbRep.UnreadCount + tbDm.UnreadCount;
             var ur = 0;
@@ -8689,7 +8696,7 @@ namespace OpenTween
             UnreadCounter = ur;
             UnreadAtCounter = urat;
 
-            var homeTab = this._statuses.GetTabByType<HomeTabModel>();
+            var homeTab = this._statuses.HomeTab;
 
             slbl.AppendFormat(Properties.Resources.SetStatusLabelText1, tur, tal, ur, al, urat, _postTimestamps.Count, _favTimestamps.Count, homeTab.TweetsPerHour);
             if (SettingManager.Common.TimelinePeriod == 0)
@@ -8713,7 +8720,7 @@ namespace OpenTween
                 }
                 else
                 {
-                    var endpointName = (e as TwitterApiStatus.AccessLimitUpdatedEventArgs).EndpointName;
+                    var endpointName = ((TwitterApiStatus.AccessLimitUpdatedEventArgs)e).EndpointName;
                     SetApiStatusLabel(endpointName);
                 }
             }
@@ -8727,7 +8734,7 @@ namespace OpenTween
             }
         }
 
-        private void SetApiStatusLabel(string endpointName = null)
+        private void SetApiStatusLabel(string? endpointName = null)
         {
             var tabType = this.CurrentTab.TabType;
 
@@ -9023,16 +9030,15 @@ namespace OpenTween
         private async Task doRepliedStatusOpen()
         {
             var currentPost = this.CurrentPost;
-            if (this.ExistCurrentPost && currentPost.InReplyToUser != null && currentPost.InReplyToStatusId != null)
+            if (this.ExistCurrentPost && currentPost != null && currentPost.InReplyToUser != null && currentPost.InReplyToStatusId != null)
             {
                 if (MyCommon.IsKeyDown(Keys.Shift))
                 {
                     await this.OpenUriInBrowserAsync(MyCommon.GetStatusUrl(currentPost.InReplyToUser, currentPost.InReplyToStatusId.Value));
                     return;
                 }
-                if (_statuses.ContainsKey(currentPost.InReplyToStatusId.Value))
+                if (this._statuses.Posts.TryGetValue(currentPost.InReplyToStatusId.Value, out var repPost))
                 {
-                    var repPost = _statuses[currentPost.InReplyToStatusId.Value];
                     MessageBox.Show($"{repPost.ScreenName} / {repPost.Nickname}   ({repPost.CreatedAt.ToLocalTimeString()})" + Environment.NewLine + repPost.TextFromApi);
                 }
                 else
@@ -9040,7 +9046,7 @@ namespace OpenTween
                     foreach (var tb in _statuses.GetTabsByType(MyCommon.TabUsageType.Lists | MyCommon.TabUsageType.PublicSearch))
                     {
                         if (tb == null || !tb.Contains(currentPost.InReplyToStatusId.Value)) break;
-                        var repPost = _statuses[currentPost.InReplyToStatusId.Value];
+                        repPost = tb.Posts[currentPost.InReplyToStatusId.Value];
                         MessageBox.Show($"{repPost.ScreenName} / {repPost.Nickname}   ({repPost.CreatedAt.ToLocalTimeString()})" + Environment.NewLine + repPost.TextFromApi);
                         return;
                     }
@@ -9546,7 +9552,7 @@ namespace OpenTween
         /// </remarks>
         /// <exception cref="ArgumentException">不正なフォーマットが入力された場合</exception>
         /// <exception cref="NotSupportedException">サポートされていないデータが入力された場合</exception>
-        internal static (string Url, string Title) GetUrlFromDataObject(IDataObject data)
+        internal static (string Url, string? Title) GetUrlFromDataObject(IDataObject data)
         {
             if (data.GetDataPresent("text/x-moz-url"))
             {
@@ -9779,7 +9785,7 @@ namespace OpenTween
             if (flg) LView.Invalidate(bnd);
         }
 
-        private void SelectListItem(DetailsListView LView , int[] Index, int focusedIndex, int selectionMarkIndex)
+        private void SelectListItem(DetailsListView LView , int[]? Index, int focusedIndex, int selectionMarkIndex)
         {
             //複数
             var bnd = new Rectangle();
@@ -9894,7 +9900,7 @@ namespace OpenTween
                 if (MyCommon.TwitterApiInfo.AccessLevel == TwitterApiAccessLevel.ReadWrite)
                 {
                     MessageBox.Show(Properties.Resources.ReAuthorizeText);
-                    SettingStripMenuItem_Click(null, null);
+                    SettingStripMenuItem_Click(this.SettingStripMenuItem, EventArgs.Empty);
                 }
 
                 // 取得失敗の場合は再試行する
@@ -10007,7 +10013,7 @@ namespace OpenTween
         private async Task FavoritesRetweetUnofficial()
         {
             var post = this.CurrentPost;
-            if (this.ExistCurrentPost && !post.IsDm)
+            if (this.ExistCurrentPost && post != null && !post.IsDm)
             {
                 _DoFavRetweetFlags = true;
                 var favoriteTask = this.FavoriteChange(true);
@@ -10136,7 +10142,7 @@ namespace OpenTween
 
         private async void ApiUsageInfoMenuItem_Click(object sender, EventArgs e)
         {
-            TwitterApiStatus apiStatus;
+            TwitterApiStatus? apiStatus;
 
             using (var dialog = new WaitingDialog(Properties.Resources.ApiInfo6))
             {
@@ -10402,9 +10408,9 @@ namespace OpenTween
 
         private void doQuoteOfficial()
         {
-            if (this.ExistCurrentPost)
+            var post = this.CurrentPost;
+            if (this.ExistCurrentPost && post != null)
             {
-                var post = this.CurrentPost;
                 if (post.IsDm || !StatusText.Enabled)
                     return;
 
@@ -10428,9 +10434,9 @@ namespace OpenTween
         private void doReTweetUnofficial()
         {
             //RT @id:内容
-            if (this.ExistCurrentPost)
+            var post = this.CurrentPost;
+            if (this.ExistCurrentPost && post != null)
             {
-                var post = this.CurrentPost;
                 if (post.IsDm || !StatusText.Enabled)
                     return;
 
@@ -10547,8 +10553,9 @@ namespace OpenTween
             }
             else
             {
+                DetailsListView? listView;
+
                 var tb = _statuses.RemovedTab.Pop();
-                DetailsListView listView;
                 if (tb.TabType == MyCommon.TabUsageType.Related)
                 {
                     var relatedTab = _statuses.GetTabByType(MyCommon.TabUsageType.Related);
@@ -10710,7 +10717,7 @@ namespace OpenTween
             //    StatusText.Focus();
             //}
             this.MarkSettingCommonModified();
-            this.StatusText_TextChanged(null, null);
+            this.StatusText_TextChanged(this.StatusText, EventArgs.Empty);
         }
 
         private void HashToggleMenuItem_Click(object sender, EventArgs e)
@@ -10729,11 +10736,11 @@ namespace OpenTween
                 HashTogglePullDownMenuItem.Checked = false;
             }
             this.MarkSettingCommonModified();
-            this.StatusText_TextChanged(null, null);
+            this.StatusText_TextChanged(this.StatusText, EventArgs.Empty);
         }
 
         private void HashStripSplitButton_ButtonClick(object sender, EventArgs e)
-            => this.HashToggleMenuItem_Click(null, null);
+            => this.HashToggleMenuItem_Click(this.HashToggleMenuItem, EventArgs.Empty);
 
         public void SetPermanentHashtag(string hashtag)
         {
@@ -10780,7 +10787,7 @@ namespace OpenTween
 
             var tab = this.CurrentTab;
             var post = this.CurrentPost;
-            if (tab.TabType == MyCommon.TabUsageType.DirectMessage || !this.ExistCurrentPost || post.IsDm)
+            if (tab.TabType == MyCommon.TabUsageType.DirectMessage || !this.ExistCurrentPost || post == null || post.IsDm)
             {
                 this.FavOpMenuItem.Enabled = false;
                 this.UnFavOpMenuItem.Enabled = false;
@@ -10825,7 +10832,7 @@ namespace OpenTween
             {
                 this.RefreshPrevOpMenuItem.Enabled = false;
             }
-            if (!this.ExistCurrentPost || post.InReplyToStatusId == null)
+            if (!this.ExistCurrentPost || post == null || post.InReplyToStatusId == null)
             {
                 OpenRepSourceOpMenuItem.Enabled = false;
             }
@@ -10833,7 +10840,7 @@ namespace OpenTween
             {
                 OpenRepSourceOpMenuItem.Enabled = true;
             }
-            if (!this.ExistCurrentPost || string.IsNullOrEmpty(post.RetweetedBy))
+            if (!this.ExistCurrentPost || post == null || string.IsNullOrEmpty(post.RetweetedBy))
             {
                 OpenRterHomeMenuItem.Enabled = false;
             }
@@ -10842,14 +10849,14 @@ namespace OpenTween
                 OpenRterHomeMenuItem.Enabled = true;
             }
 
-            if (this.ExistCurrentPost)
+            if (this.ExistCurrentPost && post != null)
             {
                 this.DelOpMenuItem.Enabled = post.CanDeleteBy(this.tw.UserId);
             }
         }
 
         private void MenuItemTab_DropDownOpening(object sender, EventArgs e)
-            => this.ContextMenuTabProperty_Opening(sender, null);
+            => this.ContextMenuTabProperty_Opening(sender, null!);
 
         public Twitter TwitterInstance
             => this.tw;
@@ -10895,7 +10902,8 @@ namespace OpenTween
             else
                 PublicSearchQueryMenuItem.Enabled = false;
 
-            if (!this.ExistCurrentPost)
+            var post = this.CurrentPost;
+            if (!this.ExistCurrentPost || post == null)
             {
                 this.CopySTOTMenuItem.Enabled = false;
                 this.CopyURLMenuItem.Enabled = false;
@@ -10907,7 +10915,6 @@ namespace OpenTween
                 this.CopyURLMenuItem.Enabled = true;
                 this.CopyUserIdStripMenuItem.Enabled = true;
 
-                var post = this.CurrentPost;
                 if (post.IsDm) this.CopyURLMenuItem.Enabled = false;
                 if (post.IsProtect) this.CopySTOTMenuItem.Enabled = false;
             }
@@ -10921,7 +10928,7 @@ namespace OpenTween
 
         private async Task doShowUserStatus(string id, bool ShowInputDialog)
         {
-            TwitterUser user = null;
+            TwitterUser? user = null;
 
             if (ShowInputDialog)
             {
@@ -10991,10 +10998,10 @@ namespace OpenTween
 
         private async void RtCountMenuItem_Click(object sender, EventArgs e)
         {
-            if (!this.ExistCurrentPost)
+            var post = this.CurrentPost;
+            if (!this.ExistCurrentPost || post == null)
                 return;
 
-            var post = this.CurrentPost;
             var statusId = post.RetweetedId ?? post.StatusId;
             TwitterStatus status;
 
@@ -11126,12 +11133,12 @@ namespace OpenTween
             if (ImageSelector.Visible)
             {
                 this.MarkSettingCommonModified();
-                this.StatusText_TextChanged(null, null);
+                this.StatusText_TextChanged(this.StatusText, EventArgs.Empty);
             }
         }
 
         private void ImageSelector_VisibleChanged(object sender, EventArgs e)
-            => this.StatusText_TextChanged(null, null);
+            => this.StatusText_TextChanged(this.StatusText, EventArgs.Empty);
 
         /// <summary>
         /// StatusTextでCtrl+Vが押下された時の処理
@@ -11181,7 +11188,7 @@ namespace OpenTween
         private void MenuItemCommand_DropDownOpening(object sender, EventArgs e)
         {
             var post = this.CurrentPost;
-            if (this.ExistCurrentPost && !post.IsDm)
+            if (this.ExistCurrentPost && post != null && !post.IsDm)
                 RtCountMenuItem.Enabled = true;
             else
                 RtCountMenuItem.Enabled = false;
@@ -11213,7 +11220,7 @@ namespace OpenTween
         private async void ShowRelatedStatusesMenuItem_Click(object sender, EventArgs e)
         {
             var post = this.CurrentPost;
-            if (this.ExistCurrentPost && !post.IsDm)
+            if (this.ExistCurrentPost && post != null && !post.IsDm)
             {
                 try
                 {
@@ -11449,7 +11456,7 @@ namespace OpenTween
                 }
                 if (ev.Event == "unfavorite" && ev.Username.Equals(tw.Username, StringComparison.InvariantCultureIgnoreCase))
                 {
-                    var favTab = this._statuses.GetTabByType(MyCommon.TabUsageType.Favorites);
+                    var favTab = this._statuses.FavoriteTab;
                     favTab.EnqueueRemovePost(ev.Id, setIsDeleted: false);
                 }
             }
@@ -11800,7 +11807,7 @@ namespace OpenTween
         {
             if (e.KeyCode == Keys.Space)
             {
-                this.JumpUnreadMenuItem_Click(null, null);
+                this.JumpUnreadMenuItem_Click(this.JumpUnreadMenuItem, EventArgs.Empty);
 
                 e.SuppressKeyPress = true;
             }