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

NullReferenceException with V4.X when using long?[] #405

Closed
KolyaNET opened this issue Apr 19, 2024 · 2 comments
Closed

NullReferenceException with V4.X when using long?[] #405

KolyaNET opened this issue Apr 19, 2024 · 2 comments
Assignees
Labels
Milestone

Comments

@KolyaNET
Copy link

KolyaNET commented Apr 19, 2024

Hello. I used FastExpressionCompiler version 3.3.4 and everything worked. After updating to version 4.1.0 I started getting errors. I also use Mapster 7.4.0.

I was able to find the problem using a NUnit test

using FastExpressionCompiler;
using Mapster;
using NUnit.Framework;

namespace Garda.Unit.Tests.Mapster;

[TestFixture]
[Parallelizable(ParallelScope.Default)]
internal sealed class NullItemArrayFastExpressionCompilerTests
{
    private sealed record ExportInfoDto(long[] Locations);

    private sealed record ExportInfoModel(long?[] Locations);

    private class ReportAdaptRule : TypeAdapterRule
    {
        internal ReportAdaptRule()
        {
            TypeAdapterConfig<ExportInfoModel, ExportInfoDto>
                .NewConfig();
        }
    }

    [TestCase(CompilerFlags.Default)]
    [TestCase(CompilerFlags.NoInvocationLambdaInlining)]
    [TestCase(CompilerFlags.EnableDelegateDebugInfo)]
    [TestCase(CompilerFlags.ThrowOnNotSupportedExpression)]
    public void NullItemArray(CompilerFlags compilerFlags)
    {
        // Arrange
        var report = new ExportInfoModel(new long?[] { 1 });

        TypeAdapterConfig.RulesTemplate.Add(new ReportAdaptRule());

        TypeAdapterConfig.GlobalSettings.Compiler = exp => exp.CompileFast(flags: compilerFlags);
        TypeAdapterConfig.GlobalSettings.Compile();

        // Act
        Assert.Throws<NullReferenceException>(() => report.Adapt<ExportInfoDto>());
    }
}

If I change long?[] to long[] or return version 3.3.4 then the NullReferenceException will no longer occur

Similar problems:

@dadhi dadhi self-assigned this Apr 19, 2024
@dadhi dadhi added this to the v4.1.1 milestone Apr 19, 2024
@dadhi dadhi added the bug label Apr 19, 2024
@dadhi
Copy link
Owner

dadhi commented Apr 19, 2024

@KolyaNET Hi, thanks for the Test and the references to the similar issues.

As I understood, the problem is with the mapping long?[] to long[] or is it the other way around?

If it is from long?[] to long[] what happens with nulls, are they skipped?

dadhi added a commit that referenced this issue Apr 21, 2024
@dadhi
Copy link
Owner

dadhi commented Apr 21, 2024

@KolyaNET The test is passing in the latest code, so it is hopefully fixed.

@dadhi dadhi closed this as completed Apr 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants