Skip to content

Commit

Permalink
[Java.Interop] suppress IL3050 with #pragma
Browse files Browse the repository at this point in the history
Context: dotnet/android#8758 (comment)
Context: dotnet#1192

In 7d1e705 and b8f6f88, we suppressed IL3050, an AOT-related
warning with:

    // FIXME: dotnet#1192
    [UnconditionalSuppressMessage ("AOT", "IL3050")]
    // Problematic code here

We don't immediately *plan* to support NativeAOT on Android in .NET 9,
so it would be nice if we could suppress the warning *for now*. But if
anyone tried to use this code in a NativeAOT context, they could get a
warning.

So instead we should use:

    // FIXME: dotnet#1192
    #pragma warning disable IL3050
    // Problematic code here
    #pragma warning restore IL3050

This will prevent us from introducing new `IL3050` and related
warnings, but if anyone consumes `Java.Interop.dll` from NativeAOT --
they will see the warning.
  • Loading branch information
jonathanpeppers committed Feb 28, 2024
1 parent 14a9470 commit ec3d90e
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 10 deletions.
16 changes: 10 additions & 6 deletions src/Java.Interop/Java.Interop/JniRuntime.JniTypeManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -271,14 +271,18 @@ protected virtual IEnumerable<string> GetSimpleReferences (Type type)
static readonly Type[] EmptyTypeArray = Array.Empty<Type> ();
const string NotUsedInAndroid = "This code path is not used in Android projects.";

// FIXME: https://github.com/xamarin/java.interop/issues/1192
[UnconditionalSuppressMessage ("AOT", "IL3050", Justification = NotUsedInAndroid)]
static Type MakeArrayType (Type type) => type.MakeArrayType ();
static Type MakeArrayType (Type type) =>
// FIXME: https://github.com/xamarin/java.interop/issues/1192
#pragma warning disable IL3050
type.MakeArrayType ();
#pragma warning restore IL3050

// FIXME: https://github.com/xamarin/java.interop/issues/1192
[UnconditionalSuppressMessage ("Trimming", "IL2055", Justification = NotUsedInAndroid)]
[UnconditionalSuppressMessage ("AOT", "IL3050", Justification = NotUsedInAndroid)]
static Type MakeGenericType (Type type, Type arrayType) => type.MakeGenericType (arrayType);
static Type MakeGenericType (Type type, Type arrayType) =>
// FIXME: https://github.com/xamarin/java.interop/issues/1192
#pragma warning disable IL3050
type.MakeGenericType (arrayType);
#pragma warning restore IL3050

[UnconditionalSuppressMessage ("Trimming", "IL2073", Justification = "Types returned here should be preserved via other means.")]
[return: DynamicallyAccessedMembers (MethodsConstructorsInterfaces)]
Expand Down
10 changes: 6 additions & 4 deletions src/Java.Interop/Java.Interop/JniRuntime.JniValueManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -370,15 +370,16 @@ static Type GetPeerType ([DynamicallyAccessedMembers (Constructors)] Type type)
static Type? AssemblyGetType (Assembly assembly, string typeName) =>
assembly.GetType (typeName);

// FIXME: https://github.com/xamarin/java.interop/issues/1192
[UnconditionalSuppressMessage ("Trimming", "IL2055", Justification = makeGenericTypeMessage)]
[UnconditionalSuppressMessage ("AOT", "IL3050", Justification = makeGenericTypeMessage)]
[return: DynamicallyAccessedMembers (Constructors)]
static Type MakeGenericType (
[DynamicallyAccessedMembers (Constructors)]
Type type,
Type [] arguments) =>
// FIXME: https://github.com/xamarin/java.interop/issues/1192
#pragma warning disable IL3050
type.MakeGenericType (arguments);
#pragma warning restore IL3050

Type[] arguments = type.GetGenericArguments ();
if (arguments.Length == 0)
Expand Down Expand Up @@ -657,11 +658,12 @@ static JniValueMarshaler GetObjectArrayMarshaler (Type elementType)
{
const string makeGenericMethodMessage = "This code path is not used in Android projects.";

// FIXME: https://github.com/xamarin/java.interop/issues/1192
[UnconditionalSuppressMessage ("Trimming", "IL2060", Justification = makeGenericMethodMessage)]
[UnconditionalSuppressMessage ("AOT", "IL3050", Justification = makeGenericMethodMessage)]
static MethodInfo MakeGenericMethod (MethodInfo method, Type type) =>
// FIXME: https://github.com/xamarin/java.interop/issues/1192
#pragma warning disable IL3050
method.MakeGenericMethod (type);
#pragma warning restore IL3050

Func<JniValueMarshaler> indirect = GetObjectArrayMarshalerHelper<object>;
var reifiedMethodInfo = MakeGenericMethod (
Expand Down

0 comments on commit ec3d90e

Please sign in to comment.