You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
C# 8 introduced [Nullable Reference Types][0], which allows reuse of
the `nullable_type` grammar in which a `?` suffix on a type indicates
that the value may be null -- which previously could only be placed
on value types -- so that it can be placed onto reference types.
As part of this C# change, within an `enabled` [nullable context][1],
values of reference types such as `string` are *not null* by default.
`string?` would need to be used to indicate that the value may be
`null`.
This change presents a potentially significant *semantic* change,
particularly if `-warnaserror` is used, as source code which
previously allowed `null` values can now elicit C# *warnings* if code
flow analysis/etc. indicates that a non-nullable value may be null.
Enable Nullable Reference Type support for `Java.Interop.dll`:
* Set `$(Nullable)`=enable, so that nullable reference types are
enabled project wide.
* Perform the *minimal* review of the current API to indicate that
certain parameters or return types may accept or return `null`
values.
* Use [additional custom attributes][2] to further "tighten" the
semantics we're trying to describe. In particular,
*type parameters* are generally *non-null*, so if a method
(1) has a return value which is a type parameter, and (2) the
value returned may be null, then the method should be annotated
with a [`MaybeNullAttribute`][3] to indicate that the value could
be null even though the type appears to forbid it.
* Add a `NullableAttributes.cs` file so that we can use the
additional custom attributes, as these types may not be present
in the BCL that we're building against.
`INTERNAL_NULLABLE_ATTRIBUTES` is added to `$(DefineConstants)`
so that these types are `internal` to `Java.Interop.dll`.
* Update `JniRuntime` to move away from `ConcurrentDictionary` to
`lock` + `Dictionary`, because `ConcurrentDictionary.TryUpdate()`
didn't support passing `null` as a new value. To do so, we'd have
to move to `ConcurrentDictionary<IntPtr, JniRuntime?>`, which would
alter the type of `Runtime.Values`, and change other things.
* Update `JniPeerMembers` so that we no longer `null` out various
members in `JniPeerMembers.Dispose()` and we instead call
`InstanceFields.Clear()`. This was easier than making everything
nullable, and the `Dispose()` codepath really shouldn't ever be
invoked anyway....
After all this, there are two remaining nullable-reference type
warnings produced by `Java.Interop.csproj`:
src\Java.Interop\Java.Interop\JniRuntime.JniValueManager.cs(399,13): Warning CS8601: Possible null reference assignment.
src\Java.Interop\Java.Interop\JniRuntime.JniValueManager.cs(476,13): Warning CS8601: Possible null reference assignment.
We currently do not know why this CS8601 is being emitted, and will
need to investigate further.
Additionally:
* Bump to .NET Core 3.1.x which supports nullable reference types.
* Install a newer `boots` tool which supports .Net Core 3.1.
[0]: https://docs.microsoft.com/en-us/dotnet/csharp/nullable-references
[1]: https://docs.microsoft.com/en-us/dotnet/csharp/nullable-references#nullable-contexts
[2]: https://docs.microsoft.com/en-us/dotnet/csharp/nullable-attributes#specify-post-conditions-maybenull-and-notnull
[3]: https://docs.microsoft.com/en-us/dotnet/api/system.diagnostics.codeanalysis.maybenullattribute?view=netcore-3.1
Copy file name to clipboardExpand all lines: src/Java.Interop/GlobalSuppressions.cs
+6Lines changed: 6 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -72,6 +72,10 @@
72
72
73
73
[assembly:SuppressMessage("Performance","CA1822:Mark members as static",Justification="<Pending>",Scope="member",Target="~M:Java.Interop.JniRuntime.JniMarshalMemberBuilder.IsDirectMethod(System.Reflection.ParameterInfo[])~System.Boolean")]
74
74
[assembly:SuppressMessage("Performance","CA1822:Mark members as static",Justification="<Pending>",Scope="member",Target="~M:Java.Interop.JniRuntime.JniValueManager.GetJniIdentityHashCode(Java.Interop.JniObjectReference)~System.Int32")]
75
+
[assembly:SuppressMessage("Performance","CA1822:Mark members as static",Justification="<Pending>",Scope="member",Target="~P:Java.Interop.JniFieldInfo.Name")]
76
+
[assembly:SuppressMessage("Performance","CA1822:Mark members as static",Justification="<Pending>",Scope="member",Target="~P:Java.Interop.JniFieldInfo.Signature")]
77
+
[assembly:SuppressMessage("Performance","CA1822:Mark members as static",Justification="<Pending>",Scope="member",Target="~P:Java.Interop.JniMethodInfo.Name")]
78
+
[assembly:SuppressMessage("Performance","CA1822:Mark members as static",Justification="<Pending>",Scope="member",Target="~P:Java.Interop.JniMethodInfo.Signature")]
75
79
76
80
[assembly:SuppressMessage("Performance","CA1823:Avoid unused private fields",Justification="Used for native interop",Scope="type",Target="~T:Java.Interop.JavaException")]
77
81
[assembly:SuppressMessage("Performance","CA1823:Avoid unused private fields",Justification="Used for native interop",Scope="type",Target="~T:Java.Interop.JavaObject")]
[assembly:SuppressMessage("Usage","CA2213:Disposable fields should be disposed",Justification="<Pending>",Scope="member",Target="~F:Java.Interop.JniRuntime.valueManager")]
0 commit comments