Skip to content

Commit

Permalink
Fix of PVS-Studio warnings. (#6497)
Browse files Browse the repository at this point in the history
  • Loading branch information
F0b0s authored Mar 9, 2023
1 parent dbb8b58 commit f92c609
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 26 deletions.
28 changes: 28 additions & 0 deletions src/core/Akka.Tests/Util/Base64EncodingSpec.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// //-----------------------------------------------------------------------
// // <copyright file="Base64EncodingSpec.cs" company="Akka.NET Project">
// // Copyright (C) 2009-2023 Lightbend Inc. <http://www.lightbend.com>
// // Copyright (C) 2013-2023 .NET Foundation <https://github.com/akkadotnet/akka.net>
// // </copyright>
// //-----------------------------------------------------------------------

using Akka.Util;
using Xunit;

namespace Akka.Tests.Util;

public class Base64EncodingSpec
{
[Fact]
public void When_prefix_is_null_it_should_work_correctly()
{
var actual = Base64Encoding.Base64Encode(12345, null);
Assert.Equal("5ad", actual);
}

[Fact]
public void Should_calculate_base_64_correctly()
{
var actual = Base64Encoding.Base64Encode(12345, "");
Assert.Equal("5ad", actual);
}
}
39 changes: 18 additions & 21 deletions src/core/Akka/Actor/ActorCell.FaultHandling.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,30 +58,27 @@ private void FaultRecreate(Exception cause)
if (System.Settings.DebugLifecycle)
Publish(new Debug(_self.Path.ToString(), failedActor.GetType(), "Restarting"));

if(!(failedActor is null))
var optionalMessage = CurrentMessage;
try
{
var optionalMessage = CurrentMessage;
try
{
// if the actor fails in preRestart, we can do nothing but log it: it’s best-effort
failedActor.AroundPreRestart(cause, optionalMessage);
// if the actor fails in preRestart, we can do nothing but log it: it’s best-effort
failedActor.AroundPreRestart(cause, optionalMessage);

// run actor pre-incarnation plugin pipeline
var pipeline = _systemImpl.ActorPipelineResolver.ResolvePipeline(failedActor.GetType());
pipeline.BeforeActorIncarnated(failedActor, this);
}
catch (Exception e)
{
HandleNonFatalOrInterruptedException(() =>
{
var ex = new PreRestartException(_self, e, cause, optionalMessage);
Publish(new Error(ex, _self.Path.ToString(), failedActor.GetType(), e.Message));
});
}
finally
// run actor pre-incarnation plugin pipeline
var pipeline = _systemImpl.ActorPipelineResolver.ResolvePipeline(failedActor.GetType());
pipeline.BeforeActorIncarnated(failedActor, this);
}
catch (Exception e)
{
HandleNonFatalOrInterruptedException(() =>
{
ClearActor(_actor);
}
var ex = new PreRestartException(_self, e, cause, optionalMessage);
Publish(new Error(ex, _self.Path.ToString(), failedActor.GetType(), e.Message));
});
}
finally
{
ClearActor(_actor);
}

global::System.Diagnostics.Debug.Assert(Mailbox.IsSuspended(), "Mailbox must be suspended during restart, status=" + Mailbox.CurrentStatus());
Expand Down
2 changes: 1 addition & 1 deletion src/core/Akka/Util/Base64Encoding.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ internal static string Base64Encode(this long value, string prefix)
{
// 11 is the number of characters it takes to represent long.MaxValue
// so we will never need a larger size for encoding longs
Span<char> sb = stackalloc char[11 + prefix?.Length ?? 0];
Span<char> sb = stackalloc char[11 + (prefix?.Length ?? 0)];
var spanIndex = 0;
if (!string.IsNullOrWhiteSpace(prefix) && prefix.Length > 0)
{
Expand Down
15 changes: 11 additions & 4 deletions src/examples/HelloAkka/HelloWorld/GreetingActor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
//-----------------------------------------------------------------------

#region akka-hello-world-greeting
using System;
using Akka.Actor;

namespace HelloWorld
Expand All @@ -19,11 +18,19 @@ public class GreetingActor : ReceiveActor
public GreetingActor()
{
// Tell the actor to respond to the Greet message
Receive<Greet>(greet => Console.WriteLine($"Hello {greet.Who}", ConsoleColor.Green));
Receive<Greet>(greet => Console.WriteLine($"Hello {greet.Who}"));
}
protected override void PreStart()
{
Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine("Good Morning, we are awake!");
}
protected override void PreStart() => Console.WriteLine("Good Morning, we are awake!", ConsoleColor.Green);

protected override void PostStop() => Console.WriteLine("Good Night, going to bed!", ConsoleColor.Red);
protected override void PostStop()
{
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine("Good Night, going to bed!");
}
}
}
#endregion
Expand Down

0 comments on commit f92c609

Please sign in to comment.