Skip to content

Commit

Permalink
Enable null checker on top-level files
Browse files Browse the repository at this point in the history
  • Loading branch information
dahlia committed Sep 28, 2020
1 parent 58985af commit d823b02
Show file tree
Hide file tree
Showing 9 changed files with 27 additions and 16 deletions.
3 changes: 3 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,8 @@ To be released.
constructor. [[#1012]]
- Added `cacheSize` optional parameter to `BlockSet<T>()` constructor.
[[#1013]]
- Removed `Address(SerializationInfo, StreamingContext)` constructor.
[[#1022]]
- Removed constructors from `InvalidMessageException` class. [[#1021]]

### Backward-incompatible network protocol changes
Expand Down Expand Up @@ -366,6 +368,7 @@ To be released.
[#1012]: https://github.com/planetarium/libplanet/pull/1012
[#1013]: https://github.com/planetarium/libplanet/pull/1013
[#1021]: https://github.com/planetarium/libplanet/pull/1021
[#1022]: https://github.com/planetarium/libplanet/pull/1022
[sleep mode]: https://en.wikipedia.org/wiki/Sleep_mode


Expand Down
22 changes: 11 additions & 11 deletions Libplanet/Address.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#nullable enable
using System;
using System.Collections.Immutable;
using System.Diagnostics.Contracts;
Expand Down Expand Up @@ -93,13 +94,6 @@ public Address(byte[] address)
{
}

public Address(
SerializationInfo info,
StreamingContext context)
: this(info.GetValue<byte[]>("address"))
{
}

/// <summary>
/// Derives the corresponding <see cref="Address"/> from a <see
/// cref="PublicKey"/>.
Expand Down Expand Up @@ -138,6 +132,14 @@ public Address(string hex)
{
}

private Address(
SerializationInfo info,
StreamingContext context)
: this(info?.GetValue<byte[]>("address") ??
throw new SerializationException("Missing the address field."))
{
}

/// <summary>
/// An immutable array of 20 <see cref="byte"/>s that represent this
/// <see cref="Address"/>.
Expand Down Expand Up @@ -223,9 +225,7 @@ public override string ToString()
}

/// <inheritdoc />
public void GetObjectData(
SerializationInfo info,
StreamingContext context)
public void GetObjectData(SerializationInfo info, StreamingContext context)
{
info.AddValue("address", ToByteArray());
}
Expand All @@ -246,7 +246,7 @@ int IComparable<Address>.CompareTo(Address other)
return 0;
}

int IComparable.CompareTo(object obj)
int IComparable.CompareTo(object? obj)
{
if (obj is Address other)
{
Expand Down
1 change: 1 addition & 0 deletions Libplanet/AddressExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#nullable enable
using Libplanet.Crypto;

namespace Libplanet
Expand Down
3 changes: 2 additions & 1 deletion Libplanet/ByteArrayExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#nullable enable
using System;
using System.Diagnostics.Contracts;

Expand All @@ -22,7 +23,7 @@ public static class ByteArrayExtensions
/// <paramref name="bytes"/> or <paramref name="prefix"/> is null.
/// </exception>
[Pure]
public static bool StartsWith(this byte[] bytes, byte[] prefix)
public static bool StartsWith(this byte[]? bytes, byte[]? prefix)
{
if (bytes is null)
{
Expand Down
2 changes: 1 addition & 1 deletion Libplanet/ByteUtil.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#nullable enable
using System;
using System.Collections.Immutable;
using System.Diagnostics.Contracts;
Expand Down Expand Up @@ -74,7 +75,6 @@ public static string Hex(byte[] bytes)
}

string s = BitConverter.ToString(bytes);

return s.Replace("-", string.Empty).ToLower(CultureInfo.InvariantCulture);
}

Expand Down
1 change: 1 addition & 0 deletions Libplanet/FixedSizedQueue.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#nullable enable
using System.Collections.Concurrent;

namespace Libplanet
Expand Down
9 changes: 6 additions & 3 deletions Libplanet/HashDigest.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
#nullable enable
using System;
using System.Collections.Immutable;
using System.Diagnostics.Contracts;
using System.Linq;
using System.Numerics;
using System.Reflection;
using System.Security.Cryptography;

namespace Libplanet
Expand Down Expand Up @@ -35,8 +37,9 @@ namespace Libplanet

static HashDigest()
{
var thunk = (T)typeof(T).GetMethod("Create", new Type[0]).Invoke(
null, new object[0]);
MethodInfo? method = typeof(T).GetMethod("Create", new Type[0]);
T thunk = method?.Invoke(null, new object[0]) as T
?? throw new InvalidCastException($"Failed to instantiate {typeof(T).FullName}.");
Size = thunk.HashSize / 8;

_defaultByteArray = new byte[Size];
Expand Down Expand Up @@ -206,7 +209,7 @@ public override string ToString()
}

[Pure]
public override bool Equals(object obj)
public override bool Equals(object? obj)
{
return obj is IEquatable<HashDigest<T>> other
? other.Equals(this)
Expand Down
1 change: 1 addition & 0 deletions Libplanet/Hashcash.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#nullable enable
using System;
using System.Security.Cryptography;
using System.Threading;
Expand Down
1 change: 1 addition & 0 deletions Libplanet/Nonce.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#nullable enable
using System;
using System.Collections.Immutable;
using System.Diagnostics.Contracts;
Expand Down

0 comments on commit d823b02

Please sign in to comment.