Skip to content
This repository was archived by the owner on Jul 6, 2026. It is now read-only.

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

4 files changed

Lines changed: 8 additions & 4 deletions

File tree

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ protected virtual IEnumerable<string> GetSimpleReferences (Type type)
176176
staticreadonlyType[]EmptyTypeArray=Array.Empty<Type>();
177177

178178

179-
publicTypeGetType(JniTypeSignaturetypeSignature)
179+
publicType?GetType(JniTypeSignaturetypeSignature)
180180
{
181181
AssertValid();
182182

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,7 @@ static Type GetPeerType (Type type)
333333
returnGetActivationConstructor(fallbackType);
334334
}
335335

336-
staticConstructorInfoGetActivationConstructor(Typetype)
336+
staticConstructorInfo?GetActivationConstructor(Typetype)
337337
{
338338
return
339339
(fromcintype.GetConstructors(BindingFlags.Public|BindingFlags.NonPublic|BindingFlags.Instance)
@@ -675,6 +675,8 @@ public override Expression CreateReturnValueFromManagedExpression (JniValueMarsh
675675

676676
publicoverrideExpressionCreateParameterToManagedExpression(JniValueMarshalerContextcontext,ParameterExpressionsourceValue,ParameterAttributessynchronize,Type?targetType)
677677
{
678+
targetType??=typeof(object);
679+
678680
varr=Expression.Variable(targetType,sourceValue.Name+"_val");
679681
context.LocalVariables.Add(r);
680682
context.CreationStatements.Add(

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

Lines changed: 2 additions & 0 deletions
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
varvalue=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‎

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

1616
protectedoverridestringGetKeyForItem(ParameterExpressionitem)
1717
{
18-
returnitem.Name;
18+
returnitem.Name!;
1919
}
2020
}
2121

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

172-
protectedExpressionReturnObjectReferenceToJni(JniValueMarshalerContextcontext,stringnamePrefix,ExpressionsourceValue)
172+
protectedExpressionReturnObjectReferenceToJni(JniValueMarshalerContextcontext,string?namePrefix,ExpressionsourceValue)
173173
{
174174
Func<JniObjectReference,IntPtr>m=JniEnvironment.References.NewReturnToJniRef;
175175
varr=Expression.Variable(MarshalType,namePrefix+"_rtn");

0 commit comments

Comments
 (0)