Skip to content

Commit 23baf0b

Browse files
authored
[Java.Interop] Fix NRT warnings introduced by targeting 'net6.0' (#840)
In 4d0cba6 we began targeting `net6.0` instead of `netcoreapp3.1`. This framework contains additional nullable annotations that resulted in new warnings. Fix those warnings.
1 parent 131c149 commit 23baf0b

File tree

4 files changed

+8
-4
lines changed

4 files changed

+8
-4
lines changed

src/Java.Interop/Java.Interop/JniRuntime.JniTypeManager.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ protected virtual IEnumerable<string> GetSimpleReferences (Type type)
176176
static readonly Type[] EmptyTypeArray = Array.Empty<Type> ();
177177

178178

179-
public Type GetType (JniTypeSignature typeSignature)
179+
public Type? GetType (JniTypeSignature typeSignature)
180180
{
181181
AssertValid ();
182182

src/Java.Interop/Java.Interop/JniRuntime.JniValueManager.cs

+3-1
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,7 @@ static Type GetPeerType (Type type)
333333
return GetActivationConstructor (fallbackType);
334334
}
335335

336-
static ConstructorInfo GetActivationConstructor (Type type)
336+
static ConstructorInfo? GetActivationConstructor (Type type)
337337
{
338338
return
339339
(from c in type.GetConstructors (BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance)
@@ -675,6 +675,8 @@ public override Expression CreateReturnValueFromManagedExpression (JniValueMarsh
675675

676676
public override Expression CreateParameterToManagedExpression (JniValueMarshalerContext context, ParameterExpression sourceValue, ParameterAttributes synchronize, Type? targetType)
677677
{
678+
targetType ??= typeof (object);
679+
678680
var r = Expression.Variable (targetType, sourceValue.Name + "_val");
679681
context.LocalVariables.Add (r);
680682
context.CreationStatements.Add (

src/Java.Interop/Java.Interop/JniStringValueMarshaler.cs

+2
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ public override Expression CreateParameterToManagedExpression (JniValueMarshaler
6161
{
6262
Func<IntPtr, string?> m = JniEnvironment.Strings.ToString;
6363

64+
targetType ??= typeof (object);
65+
6466
var value = Expression.Variable (targetType, sourceValue.Name + "_val");
6567
context.LocalVariables.Add (value);
6668
context.CreationStatements.Add (Expression.Assign (value, Expression.Call (m.GetMethodInfo (), sourceValue)));

src/Java.Interop/Java.Interop/JniValueMarshaler.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ sealed class VariableCollection : KeyedCollection<string, ParameterExpression> {
1515

1616
protected override string GetKeyForItem (ParameterExpression item)
1717
{
18-
return item.Name;
18+
return item.Name!;
1919
}
2020
}
2121

@@ -169,7 +169,7 @@ public virtual Expression CreateReturnValueFromManagedExpressi
169169
return ReturnObjectReferenceToJni (context, sourceValue.Name, Expression.Property (s, "ReferenceValue"));
170170
}
171171

172-
protected Expression ReturnObjectReferenceToJni (JniValueMarshalerContext context, string namePrefix, Expression sourceValue)
172+
protected Expression ReturnObjectReferenceToJni (JniValueMarshalerContext context, string? namePrefix, Expression sourceValue)
173173
{
174174
Func<JniObjectReference, IntPtr> m = JniEnvironment.References.NewReturnToJniRef;
175175
var r = Expression.Variable (MarshalType, namePrefix + "_rtn");

0 commit comments

Comments
 (0)