Skip to content

Commit

Permalink
Fix NRE in IsInRealmNamespace
Browse files Browse the repository at this point in the history
  • Loading branch information
nirinchev committed Jul 20, 2023
1 parent 4ff5a06 commit 4e13543
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* None

### Fixed
* None
* Fixed an issue where building for Android on Unity would fail with "Could not analyze the user's assembly. Object reference not set to an instance of an object". (Issue [#3380](https://github.com/realm/realm-dotnet/issues/3380))

### Compatibility
* Realm Studio: 13.0.0 or later.
Expand Down
16 changes: 8 additions & 8 deletions Realm/Realm.Weaver/Analytics/Analytics.cs
Original file line number Diff line number Diff line change
Expand Up @@ -122,18 +122,18 @@ public Analytics(Config config, ImportedReferences references, ILogger logger, M
// check if it's the right signature, that is 2 params in total of which
// the second a bool and that it's set to true.
[Feature.Add] = instruction =>
IsInRealmNamespace(instruction.Operand) &&
instruction.Operand is MethodSpecification methodSpecification &&
IsInRealmNamespace(instruction?.Operand) &&
instruction?.Operand is MethodSpecification methodSpecification &&
methodSpecification.Parameters.Count == 2 &&
methodSpecification.Parameters[1].ParameterType.MetadataType == MetadataType.Boolean &&
instruction.Previous.OpCode == OpCodes.Ldc_I4_1 ?
new(true, Feature.Add) : default,
instruction.Previous?.OpCode == OpCodes.Ldc_I4_1
? new(true, Feature.Add) : default,
[Feature.ShouldCompactOnLaunch] = _ => new(true, Feature.ShouldCompactOnLaunch),
[Feature.MigrationCallback] = _ => new(true, Feature.MigrationCallback),
[Feature.RealmChanged] = _ => new(true, Feature.RealmChanged),
["SubscribeForNotifications"] = instruction =>
{
if (instruction.Operand is not MethodSpecification methodSpecification || !IsInRealmNamespace(instruction.Operand))
if (instruction?.Operand is not MethodSpecification methodSpecification || !IsInRealmNamespace(instruction?.Operand))
{
return default;
}
Expand Down Expand Up @@ -222,7 +222,7 @@ property.PropertyType is not GenericInstanceType genericType ||

FeatureAnalysisResult AnalyzeRealmApi(Instruction instruction, string key)
{
if (IsInRealmNamespace(instruction.Operand))
if (IsInRealmNamespace(instruction?.Operand))
{
return new(true, key);
}
Expand Down Expand Up @@ -506,14 +506,14 @@ private static async Task SendRequest(string prefixAddr, string payload, string
await httpClient.GetAsync(new Uri(prefixAddr + payload + suffixAddr));
}

private static bool IsInRealmNamespace(object operand)
private static bool IsInRealmNamespace(object? operand)
{
if (operand is not MemberReference memberReference)
{
return false;
}

return memberReference.DeclaringType.FullName.StartsWith("Realms", StringComparison.Ordinal);
return memberReference?.DeclaringType?.FullName?.StartsWith("Realms", StringComparison.Ordinal) == true;
}

public class Config
Expand Down

0 comments on commit 4e13543

Please sign in to comment.