stryker-mutator / stryker-net

Mutation testing for .NET core and .NET framework!
https://stryker-mutator.io
Apache License 2.0
1.75k stars 176 forks source link

Stryker.NET encountered a compile error in Stryker.Core.InjectedHelpers.MutantControl.cs (at 14:15) with message: Non-nullable field '[...]' must contain a non-null value when exiting constructor #2867

Closed tristanevain closed 4 months ago

tristanevain commented 4 months ago

Describe the bug On one specific (but not exotic) .net 8 project, Stryker fails and repeatedly prints the error in the title. It happens on Windows machines but not when running in an Azure pipeline. Other projects of the same solution run fine.

The flow of repeating, and similar errors ends with the following message:

Stryker.NET could not compile the project after mutation. This is probably an error for Stryker.NET and not your project. Please report this issue on github with the previous error message.

Logs

Note that the place in the file is not always the same. Neither is the name of the faulty field.

[09:17:33 WRN] Stryker.NET encountered a compile error in Stryker.Core.InjectedHelpers.MutantControl.cs (at 14:15) with message: Non-nullable field '_coveredMutants' must contain a non-null value when exiting constructor. Consider declaring the field as nullable. (Source code: static MutantControl() { InitCoverage(); }) [09:17:33 INF] Safe Mode! Stryker will flag mutations in MutantControl as compile error. [09:17:33 WRN] Stryker.NET encountered a compile error in Stryker.Core.InjectedHelpers.MutantControl.cs (at 14:15) with message: Non-nullable field '_coveredStaticdMutants' must contain a non-null value when exiting constructor. Consider declaring the field as nullable. (Source code: static MutantControl() { InitCoverage(); }) [09:17:33 INF] Safe Mode! Stryker will flag mutations in MutantControl as compile error. [09:17:33 WRN] Stryker.NET encountered a compile error in Stryker.Core.InjectedHelpers.MutantControl.cs (at 14:15) with message: Non-nullable field 'envName' must contain a non-null value when exiting constructor. Consider declaring the field as nullable. (Source code: static MutantControl() { InitCoverage(); }) [09:17:33 INF] Safe Mode! Stryker will flag mutations in MutantControl as compile error. [09:17:33 WRN] Stryker.NET encountered a compile error in Stryker.Core.InjectedHelpers.MutantControl.cs (at 53:45) with message: Converting null literal or possible null value to non-nullable type. (Source code: System.Environment.GetEnvironmentVariable("ActiveMutation")) [09:17:33 INF] Safe Mode! Stryker will flag mutations in IsActive as compile error. [09:17:33 WRN] Stryker.NET encountered a compile error in Stryker.Core.InjectedHelpers.MutantControl.cs (at 14:15) with message: Non-nullable field '_coveredMutants' must contain a non-null value when exiting constructor. Consider declaring the field as nullable. (Source code: static MutantControl() { InitCoverage(); }) [09:17:33 INF] Safe Mode! Stryker will flag mutations in MutantControl as compile error. [09:17:33 WRN] Stryker.NET encountered a compile error in Stryker.Core.InjectedHelpers.MutantControl.cs (at 14:15) with message: Non-nullable field '_coveredStaticdMutants' must contain a non-null value when exiting constructor. Consider declaring the field as nullable. (Source code: static MutantControl() { InitCoverage(); }) [09:17:33 INF] Safe Mode! Stryker will flag mutations in MutantControl as compile error. [09:17:33 WRN] Stryker.NET encountered a compile error in Stryker.Core.InjectedHelpers.MutantControl.cs (at 14:15) with message: Non-nullable field 'envName' must contain a non-null value when exiting constructor. Consider declaring the field as nullable. (Source code: static MutantControl() { InitCoverage(); }) [09:17:33 INF] Safe Mode! Stryker will flag mutations in MutantControl as compile error. [09:17:33 WRN] Stryker.NET encountered a compile error in Stryker.Core.InjectedHelpers.MutantControl.cs (at 53:45) with message: Converting null literal or possible null value to non-nullable type. (Source code: System.Environment.GetEnvironmentVariable("ActiveMutation")) [09:17:33 INF] Safe Mode! Stryker will flag mutations in IsActive as compile error. [09:17:33 WRN] Stryker.NET encountered a compile error in Stryker.Core.InjectedHelpers.MutantControl.cs (at 14:15) with message: Non-nullable field '_coveredMutants' must contain a non-null value when exiting constructor. Consider declaring the field as nullable. (Source code: static MutantControl() { InitCoverage(); }) [09:17:33 INF] Safe Mode! Stryker will flag mutations in MutantControl as compile error. [09:17:33 WRN] Stryker.NET encountered a compile error in Stryker.Core.InjectedHelpers.MutantControl.cs (at 14:15) with message: Non-nullable field '_coveredStaticdMutants' must contain a non-null value when exiting constructor. Consider declaring the field as nullable. (Source code: static MutantControl() { InitCoverage(); }) ...

Expected behavior Stryker executes without reporting compilation errors in its own files.

Desktop (please complete the following information):

dupdob commented 4 months ago

this problems from the fact that Stryker's MutantControl class does not use nullable annotations as it needs to be compatible with older CSharp versions and it is not nullable correct, which leads to warnings, which result in errors when warning as errors is enabled.

We need to update the code to fix these warnings. In the meantime, the single workaround I can think of is either disabling warning as errors or nullable disagnostics when using Stryker.

tristanevain commented 4 months ago

Thank you for your answer. It made me investigate more why the Azure pipeline was successful and not the local run.

It turns out that one setup works: a non-global installation of Stryker (installed under the test project to mutate) in version 3.11.0

Versions 3.13.2 and 4.0.0 both still fail in this setup.

So I have a temporary solution to my problem, but it looks like a regression in Stryker since I didn't have to disable "warnings as errors" to make 3.11.0 work. It also means that we are currently stuck with an outdated version. Wishing we could upgrade for a more recent version soon.

dupdob commented 4 months ago

thanks for the feedback. This is not a regression per se: 'warnings as errors' was disregarded by Stryker, but users requested it, arguing some mutations would be rightfully flagged as killed/compile error due/thanks to 'warnings as errors'

dupdob commented 4 months ago

I just opened a PR that should fix this