Skip to content

Commit 2b80737

Browse files
Guard GetContainerFactory calls with RuntimeFeature.TrimmableTypeMap
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 7348f17 commit 2b80737

2 files changed

Lines changed: 10 additions & 4 deletions

File tree

src/Mono.Android/Android.Runtime/JNIEnv.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,11 @@ public static partial class JNIEnv {
2626

2727
static Array ArrayCreateInstance (Type elementType, int length)
2828
{
29-
var factory = TrimmableTypeMap.Instance?.GetContainerFactory (elementType);
30-
if (factory != null)
31-
return factory.CreateArray (length, 1);
29+
if (RuntimeFeature.TrimmableTypeMap) {
30+
var factory = TrimmableTypeMap.Instance?.GetContainerFactory (elementType);
31+
if (factory is not null)
32+
return factory.CreateArray (length, 1);
33+
}
3234

3335
#pragma warning disable IL3050 // Array.CreateInstance is not AOT-safe, but this is the legacy fallback path
3436
return Array.CreateInstance (elementType, length);

src/Mono.Android/Java.Interop/JavaConvert.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,11 @@ params Type [] typeArguments
148148
if (!typeof (IJavaPeerable).IsAssignableFrom (elementType))
149149
return null;
150150

151-
return TrimmableTypeMap.Instance?.GetContainerFactory (elementType);
151+
if (RuntimeFeature.TrimmableTypeMap) {
152+
return TrimmableTypeMap.Instance?.GetContainerFactory (elementType);
153+
}
154+
155+
return null;
152156
}
153157

154158
static Func<IntPtr, JniHandleOwnership, object> GetJniHandleConverterForType ([DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicMethods)] Type t)

0 commit comments

Comments
 (0)