Skip to content

Commit 42f9d9d

Browse files
ArkatufusF0b0s
andauthored
[BACKPORT #6497] Fix of PVS-Studio warnings. (#6521)
* [BACKPORT #6497] Fix of PVS-Studio warnings. (cherry-picked from f92c609) * Revert new language features --------- Co-authored-by: Sergey Popov <[email protected]>
1 parent 3970e40 commit 42f9d9d

File tree

4 files changed

+59
-27
lines changed

4 files changed

+59
-27
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
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, (string)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+
}
29+
}

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
@@ -34,7 +34,7 @@ internal static string Base64Encode(this long value, string prefix)
3434
{
3535
// 11 is the number of characters it takes to represent long.MaxValue
3636
// so we will never need a larger size for encoding longs
37-
Span<char> sb = stackalloc char[11 + prefix?.Length ?? 0];
37+
Span<char> sb = stackalloc char[11 + (prefix?.Length ?? 0)];
3838
var spanIndex = 0;
3939
if (!string.IsNullOrWhiteSpace(prefix) && prefix.Length > 0)
4040
{

src/examples/HelloAkka/HelloWorld/GreetingActor.cs

+11-5
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55
// </copyright>
66
//-----------------------------------------------------------------------
77
#region akka-hello-world-greeting
8-
9-
using System;
108
using Akka.Actor;
119

1210
namespace HelloWorld
@@ -19,11 +17,19 @@ public class GreetingActor : ReceiveActor
1917
public GreetingActor()
2018
{
2119
// Tell the actor to respond to the Greet message
22-
Receive<Greet>(greet => Console.WriteLine($"Hello {greet.Who}", ConsoleColor.Green));
20+
Receive<Greet>(greet => Console.WriteLine($"Hello {greet.Who}"));
21+
}
22+
protected override void PreStart()
23+
{
24+
Console.ForegroundColor = ConsoleColor.Green;
25+
Console.WriteLine("Good Morning, we are awake!");
2326
}
24-
protected override void PreStart() => Console.WriteLine("Good Morning, we are awake!", ConsoleColor.Green);
2527

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

0 commit comments

Comments
 (0)