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 expected on correct DateTime constructor #218

Open
Almazis opened this issue Jan 18, 2023 · 0 comments
Open

NullReferenceException expected on correct DateTime constructor #218

Almazis opened this issue Jan 18, 2023 · 0 comments

Comments

@Almazis
Copy link
Collaborator

Almazis commented Jan 18, 2023

Simple usage of DateTime constructor

public static DateTime DateTimeConstructor()
{
    var res = new DateTime(2022, 1, 1);
    return res;
}

generates the test with expected NullReferenceException

Before exception is generated (in ILInterpreter member x.Raise)
ipstack:

[0] Instruction (54, System.UInt64 System.DateTime.DateToTicks(System.Int32, System.Int32, System.Int32))
[1] Instruction (4, System.Void System.DateTime..ctor(this, System.Int32, System.Int32, System.Int32))
[2] Instruction (7, System.DateTime IntegrationTests.Environment.DateTimeConstructor())

The latest frame points to
if ((uint)day > days[month] - days[month - 1])
where array days is loaded from a static member :

private static readonly uint[] s_daysToMonth365 = {
    0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334, 365 };
private static readonly uint[] s_daysToMonth366 = {
    0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335, 366 };

<...>

uint[] days = IsLeapYear(year) ? s_daysToMonth366 : s_daysToMonth365;

Possible reason for false NullReferenceException are uninitialized statics.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant