Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix NRE in IsInRealmNamespace #3379

Merged
merged 3 commits into from
Jul 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
### Fixed
* Fixed a Unity Editor crash when the domain is reloaded while a `Realm.GetInstanceAsync` operation is in progress. (Issue [#3344](https://github.com/realm/realm-dotnet/issues/3344))
* Fixed the implementation `App.Equals` and `App.GetHashCode` to return correct results, particularly when the `App` instance is cached. (PR [#3385](https://github.com/realm/realm-dotnet/pull/3385))
* 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
18 changes: 9 additions & 9 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 @@ -283,7 +283,7 @@ private void AnalyzeUserAssembly(ModuleDefinition module)
}
catch (Exception e)
{
_logger.Error($"Could not analyze the user's assembly.{Environment.NewLine}{e.Message}");
_logger.Warning($"Could not analyze the user's assembly. Please file an issue at https://github.com/realm/realm-dotnet/issues. {Environment.NewLine}{e}");
}
}

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
Loading