Skip to content

Commit f92c609

Browse files
authored
Fix of PVS-Studio warnings. (#6497)
1 parent dbb8b58 commit f92c609

File tree

4 files changed

+58
-26
lines changed

4 files changed

+58
-26
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// //-----------------------------------------------------------------------
2+
// // <copyright file="Base64EncodingSpec.cs" company="Akka.NET Project">
3+
// // Copyright (C) 2009-2023 Lightbend Inc. <http://www.lightbend.com>
4+
// // Copyright (C) 2013-2023 .NET Foundation <https://github.com/akkadotnet/akka.net>
5+
// // </copyright>
6+
// //-----------------------------------------------------------------------
7+
8+
using Akka.Util;
9+
using Xunit;
10+
11+
namespace Akka.Tests.Util;
12+
13+
public class Base64EncodingSpec
14+
{
15+
[Fact]
16+
public void When_prefix_is_null_it_should_work_correctly()
17+
{
18+
var actual = Base64Encoding.Base64Encode(12345, null);
19+
Assert.Equal("5ad", actual);
20+
}
21+
22+
[Fact]
23+
public void Should_calculate_base_64_correctly()
24+
{
25+
var actual = Base64Encoding.Base64Encode(12345, "");
26+
Assert.Equal("5ad", actual);
27+
}
28+
}

src/core/Akka/Actor/ActorCell.FaultHandling.cs

+18-21
Original file line numberDiff line numberDiff line change
@@ -58,30 +58,27 @@ private void FaultRecreate(Exception cause)
5858
if (System.Settings.DebugLifecycle)
5959
Publish(new Debug(_self.Path.ToString(), failedActor.GetType(), "Restarting"));
6060

61-
if(!(failedActor is null))
61+
var optionalMessage = CurrentMessage;
62+
try
6263
{
63-
var optionalMessage = CurrentMessage;
64-
try
65-
{
66-
// if the actor fails in preRestart, we can do nothing but log it: it’s best-effort
67-
failedActor.AroundPreRestart(cause, optionalMessage);
64+
// if the actor fails in preRestart, we can do nothing but log it: it’s best-effort
65+
failedActor.AroundPreRestart(cause, optionalMessage);
6866

69-
// run actor pre-incarnation plugin pipeline
70-
var pipeline = _systemImpl.ActorPipelineResolver.ResolvePipeline(failedActor.GetType());
71-
pipeline.BeforeActorIncarnated(failedActor, this);
72-
}
73-
catch (Exception e)
74-
{
75-
HandleNonFatalOrInterruptedException(() =>
76-
{
77-
var ex = new PreRestartException(_self, e, cause, optionalMessage);
78-
Publish(new Error(ex, _self.Path.ToString(), failedActor.GetType(), e.Message));
79-
});
80-
}
81-
finally
67+
// run actor pre-incarnation plugin pipeline
68+
var pipeline = _systemImpl.ActorPipelineResolver.ResolvePipeline(failedActor.GetType());
69+
pipeline.BeforeActorIncarnated(failedActor, this);
70+
}
71+
catch (Exception e)
72+
{
73+
HandleNonFatalOrInterruptedException(() =>
8274
{
83-
ClearActor(_actor);
84-
}
75+
var ex = new PreRestartException(_self, e, cause, optionalMessage);
76+
Publish(new Error(ex, _self.Path.ToString(), failedActor.GetType(), e.Message));
77+
});
78+
}
79+
finally
80+
{
81+
ClearActor(_actor);
8582
}
8683

8784
global::System.Diagnostics.Debug.Assert(Mailbox.IsSuspended(), "Mailbox must be suspended during restart, status=" + Mailbox.CurrentStatus());

src/core/Akka/Util/Base64Encoding.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ internal static string Base64Encode(this long value, string prefix)
3131
{
3232
// 11 is the number of characters it takes to represent long.MaxValue
3333
// so we will never need a larger size for encoding longs
34-
Span<char> sb = stackalloc char[11 + prefix?.Length ?? 0];
34+
Span<char> sb = stackalloc char[11 + (prefix?.Length ?? 0)];
3535
var spanIndex = 0;
3636
if (!string.IsNullOrWhiteSpace(prefix) && prefix.Length > 0)
3737
{

src/examples/HelloAkka/HelloWorld/GreetingActor.cs

+11-4
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
//-----------------------------------------------------------------------
77

88
#region akka-hello-world-greeting
9-
using System;
109
using Akka.Actor;
1110

1211
namespace HelloWorld
@@ -19,11 +18,19 @@ public class GreetingActor : ReceiveActor
1918
public GreetingActor()
2019
{
2120
// Tell the actor to respond to the Greet message
22-
Receive<Greet>(greet => Console.WriteLine($"Hello {greet.Who}", ConsoleColor.Green));
21+
Receive<Greet>(greet => Console.WriteLine($"Hello {greet.Who}"));
22+
}
23+
protected override void PreStart()
24+
{
25+
Console.ForegroundColor = ConsoleColor.Green;
26+
Console.WriteLine("Good Morning, we are awake!");
2327
}
24-
protected override void PreStart() => Console.WriteLine("Good Morning, we are awake!", ConsoleColor.Green);
2528

26-
protected override void PostStop() => Console.WriteLine("Good Night, going to bed!", ConsoleColor.Red);
29+
protected override void PostStop()
30+
{
31+
Console.ForegroundColor = ConsoleColor.Red;
32+
Console.WriteLine("Good Night, going to bed!");
33+
}
2734
}
2835
}
2936
#endregion

0 commit comments

Comments
 (0)