question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Stryker falls back to safe mode for this method

See original GitHub issue

Describe the bug While running stryker the following warning was printed to the console, asking me to report this issue

[13:21:55 WRN] Stryker.NET encountered an compile error in D:\xxxx\VarUInt64.cs (at 56:22) with message: Verwendung der nicht zugewiesenen lokalen Variablen "b". (Source code: b)
[13:21:55 WRN] Safe Mode! Stryker will try to continue by rolling back all mutations in method. This should not happen, please report this as an issue on github with the previous error message.

Exception message in English: “Use of unassigned local variable”

Luckily this class does not have any external dependencies, so my guess is that it should be reproducable.

Here is the code:

using System.Diagnostics.CodeAnalysis;
using System.IO;

namespace XXXXX
{
	public static class VarUInt64
	{
		private const byte Msb0 = 0b0111_1111;
		private const byte Msb1 = 0b1000_0000;

		[SuppressMessage("Design", "CA1062:Validate arguments of public methods", Justification = "No null check for performance reasons")]
		public static int Write(Stream stream, ulong value)
		{
			ulong next;
			var cnt = 1;

			while ((next = value >> 7) != 0)
			{
				stream.WriteByte((byte)((value & Msb0) | Msb1));
				value = next;
				cnt++;
			}

			stream.WriteByte((byte)value);
			return cnt;
		}

		[SuppressMessage("Design", "CA1062:Validate arguments of public methods", Justification = "No null check for performance reasons")]
		public static int Read(Stream stream, out ulong value)
		{
			ulong b, result = 0;
			var shift = 0;
			var cnt = 0;

			while (true)
			{
				var x = stream.ReadByte();
				cnt++;

				if (x < 0)
				{
					throw new EndOfStreamException();
				}

				if (((b = (ulong)x) & Msb1) == 0)
				{
					break;
				}

				result |= (b & Msb0) << shift;
				shift += 7;
			}

			value = result | ((b & Msb0) << shift);

			return cnt;
		}
	}
}

Expected behavior stryker cli asked my to report it, but I guess the expected behaviour would be that stryker is able to mutate the Read method without entering safe mode.

Desktop:

  • OS: Windows
  • Type of project: core3 / xunit tests
  • Framework Version: .net core 3.1
  • Stryker Version: 0.16.0 (beta)

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:16 (13 by maintainers)

github_iconTop GitHub Comments

1reaction
rouke-broersmacommented, Mar 20, 2020

IMHO, I think most while(true) constructions will result in compilation issues.

Asking user to report safe mode was there to prevent the persistence of mutation process bugs that would result in triggering safe mode.

I know, but if we acknowledge that some mutations have issues we can stop asking users to report on those specific issues (if it’s possible to detect that of course).

We could exclude mutating while(true) from the default boolean mutator and create a new separate mutator for it that is not turned on by default and can be turned on manually if people want a very thorough mutation testrun?

I think especially because while(true) is such a dangerous construct it would make sense to make sure it is properly tested when possible.

1reaction
dupdobcommented, Mar 20, 2020

My comment on the ugliness of the code was referring to the minimal example, not the original code (which I failed to read). so sorry about that. I agree, Stryker should not crash, and it does not. It just fails to manage the cascading effects of the mutation, which is difficult, because while(true)allows very specific constructions.

By the way, replacing while(true)by for(;;)will remove the message.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Operations/Maintenance Manual
Return To Table of Contents. • Always use all restraint straps to secure the patient on the cot. An unrestrained patient may fall...
Read more >
Maintenance Manual
CaUTIoN. Alerts the reader of a potentially hazardous situation, which if not avoided, may result in minor or moderate injury to.
Read more >
sagittal saw
A handpiece that contains a battery should always be placed in the SAFE mode while it is either sitting idle or an accessory...
Read more >
Heavy Duty Rotary Handpiece Attachments
ALWAYS slide the function switch to the safe mode position when the handpiece is idle, before installing an attachment or accessory, or when...
Read more >
reciprocating saw
A handpiece that contains a battery should always be placed in the SAFE mode while it is either sitting idle or an accessory...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found