Skip to content

Commit ece14c8

Browse files
authored
Enable nullable reference types in AndroidDiskInformation.cs (#11813)
`src/Mono.AndroidTools/AndroidDiskInformation.cs` ships in the signed `Mono.AndroidTools` assembly but was nullable-oblivious. This opts the file into nullable reference types for compile-time null-safety with no runtime or API change. ### Changes - Added `#nullable enable` to the top of the file. - Changed the `s` locals in `ParseNewFormat` and `ParseOldFormat` from `string` to `string?`, matching `StringReader.ReadLine()`'s `string?` return. Flow analysis already narrows `s` to non-null inside the `while ((s = reader.ReadLine ()) != null)` bodies. ```csharp string? s; var reader = new StringReader (output); while ((s = reader.ReadLine ()) != null) { // s is non-null here } ``` Annotation-only: no `!` operator, no `ArgumentNullException.ThrowIfNull` (the project targets `netstandard2.0`), and public signatures (`FromDfOutput`, `InternalSpace`, `ExternalSpace`) are unchanged.
1 parent 3341169 commit ece14c8

1 file changed

Lines changed: 3 additions & 2 deletions

File tree

src/Mono.AndroidTools/AndroidDiskInformation.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
2727
// THE SOFTWARE.
2828

29+
#nullable enable
2930
using System;
3031
using System.IO;
3132

@@ -67,7 +68,7 @@ public static AndroidDiskInformation FromDfOutput (string dfOutput)
6768

6869
void ParseNewFormat (string output)
6970
{
70-
string s;
71+
string? s;
7172
var reader = new StringReader (output);
7273

7374
reader.ReadLine (); // header line
@@ -95,7 +96,7 @@ void ParseNewFormat (string output)
9596

9697
void ParseOldFormat (string output)
9798
{
98-
string s;
99+
string? s;
99100
var reader = new StringReader (output);
100101
while ((s = reader.ReadLine ()) != null) {
101102
int idx = s.IndexOf (':');

0 commit comments

Comments
 (0)