Skip to content

Commit

Permalink
Merge pull request #624 from WideSpectrumComputing/master
Browse files Browse the repository at this point in the history
Hot fix: resolve #623 - NullReference exception while initializing RollbarInfrastructure
  • Loading branch information
akornich authored Mar 15, 2022
2 parents 269c335 + 6ddf15b commit b244fea
Show file tree
Hide file tree
Showing 18 changed files with 160 additions and 298 deletions.
44 changes: 21 additions & 23 deletions Rollbar/Common/EmptyDisposable.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
namespace Rollbar.Common
{
using System;
using System.Diagnostics;
using System.Collections.Generic;
using System.Text;

Expand All @@ -11,46 +12,43 @@
public sealed class EmptyDisposable
: IDisposable
{
/// <summary>
/// Prevents a default instance of the <see cref="EmptyDisposable"/> class from being created.
/// </summary>
private EmptyDisposable()
{
}
private static readonly TraceSource traceSource =
new TraceSource(typeof(EmptyDisposable).FullName ?? "EmptyDisposable");

#region singleton implementation

private static readonly Lazy<EmptyDisposable> lazySingleton =
new Lazy<EmptyDisposable>(() => new EmptyDisposable());

/// <summary>
/// Gets the singleton-like IRollbar instance.
/// Gets the instance.
/// </summary>
/// <value>
/// The single shared IRollbar instance.
/// </value>
/// <value>The instance.</value>
public static EmptyDisposable Instance
{
get
{
return NestedSingleInstance.TheInstance;
return lazySingleton.Value;
}
}

/// <summary>
/// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
/// Prevents a default instance of the <see cref="EmptyDisposable" /> class from being created.
/// </summary>
public void Dispose()
private EmptyDisposable()
{
// no-op...
traceSource.TraceInformation($"Creating the {typeof(EmptyDisposable).Name}...");
}

private sealed class NestedSingleInstance
{
static NestedSingleInstance()
{
}
#endregion singleton implementation

private NestedSingleInstance()
{
}

internal static readonly EmptyDisposable TheInstance = new EmptyDisposable();
/// <summary>
/// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
/// </summary>
public void Dispose()
{
// no-op...
}
}
}
28 changes: 4 additions & 24 deletions Rollbar/Infrastructure/RollbarConnectivityMonitor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
/// Implements the <see cref="System.IDisposable" />
/// </summary>
/// <seealso cref="System.IDisposable" />
internal class RollbarConnectivityMonitor
internal sealed class RollbarConnectivityMonitor
: IRollbarConnectivityMonitor
, IDisposable
{
Expand All @@ -30,14 +30,14 @@ public static RollbarConnectivityMonitor? Instance
{
get
{
return NestedSingleInstance.TheInstance;
return RollbarInfrastructure.Instance.ConnectivityMonitor as RollbarConnectivityMonitor;
}
}

/// <summary>
/// Prevents a default instance of the <see cref="RollbarConnectivityMonitor"/> class from being created.
/// </summary>
private RollbarConnectivityMonitor()
internal RollbarConnectivityMonitor()
{
TimeSpan initialDelay = TimeSpan.Zero;
this._minMonitoringInterval = TimeSpan.FromSeconds(10);
Expand All @@ -56,26 +56,6 @@ private RollbarConnectivityMonitor()
this.CheckConnectivityStatus(null);
}

/// <summary>
/// Class NestedSingleInstance. This class cannot be inherited.
/// </summary>
private sealed class NestedSingleInstance
{
/// <summary>
/// Prevents a default instance of the <see cref="NestedSingleInstance" /> class from being created.
/// </summary>
private NestedSingleInstance()
{
}

/// <summary>
/// The instance
/// </summary>
internal static readonly RollbarConnectivityMonitor? TheInstance =
RollbarInfrastructure.Instance.IsInitialized ? new RollbarConnectivityMonitor()
: null;
}

#endregion singleton implementation

/// <summary>
Expand Down Expand Up @@ -264,7 +244,7 @@ public static bool TestApiServer()
/// </summary>
/// <param name="disposing"><c>true</c> to release both managed and unmanaged resources; <c>false</c> to release only unmanaged resources.</param>
[System.Diagnostics.CodeAnalysis.SuppressMessage("Major Code Smell", "S1066:Collapsible \"if\" statements should be merged", Justification = "Promotes better code structure.")]
protected virtual void Dispose(bool disposing)
private void Dispose(bool disposing)
{
if(!_disposedValue)
{
Expand Down
28 changes: 5 additions & 23 deletions Rollbar/Infrastructure/RollbarQueueController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,43 +49,25 @@ public static RollbarQueueController? Instance
{
get
{
return NestedSingleInstance.TheInstance;
return RollbarInfrastructure.Instance.QueueController as RollbarQueueController;
}
}

/// <summary>
/// Prevents a default instance of the <see cref="RollbarQueueController" /> class from being created.
/// </summary>
private RollbarQueueController()
internal RollbarQueueController()
{
}

/// <summary>
/// Class NestedSingleInstance. This class cannot be inherited.
/// </summary>
private sealed class NestedSingleInstance
{
/// <summary>
/// Prevents a default instance of the <see cref="NestedSingleInstance"/> class from being created.
/// </summary>
private NestedSingleInstance()
{
}

/// <summary>
/// The instance
/// </summary>
internal static readonly RollbarQueueController? TheInstance =
RollbarInfrastructure.Instance.IsInitialized ? new RollbarQueueController()
: null;
traceSource.TraceInformation($"Creating the {typeof(RollbarQueueController).Name}...");
}

#endregion singleton implementation

/// <summary>
/// The trace source
/// </summary>
private static readonly TraceSource traceSource = new TraceSource(typeof(RollbarQueueController).FullName ?? "RollbarQueueController");
private static readonly TraceSource traceSource =
new TraceSource(typeof(RollbarQueueController).FullName ?? "RollbarQueueController");

/// <summary>
/// Enum PayloadTraceSources
Expand Down
2 changes: 1 addition & 1 deletion Rollbar/Infrastructure/_RollbarPackages.cd
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<Class Name="Rollbar.RollbarPackageBase">
<Position X="6.5" Y="1.5" Width="4" />
<TypeIdentifier>
<HashCode>AAAABAAAAAgAAAAAAgAAAEAAAACBAIAAAAAAQAAQAAA=</HashCode>
<HashCode>AAAABAAAAAgAAAAgAgAAAAAAAACBAIAAAAAAQAAQAAA=</HashCode>
<FileName>Infrastructure\RollbarPackageBase.cs</FileName>
</TypeIdentifier>
<Lollipop Position="0.2" />
Expand Down
30 changes: 9 additions & 21 deletions Rollbar/RollbarDataScrubbingHelper.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
namespace Rollbar
{
using System;
using System.Diagnostics;
using System.Linq;
using System.Collections.Generic;

Expand All @@ -14,9 +15,14 @@
/// </remarks>
public class RollbarDataScrubbingHelper
{
private static readonly TraceSource traceSource =
new TraceSource(typeof(RollbarDataScrubbingHelper).FullName ?? "RollbarDataScrubbingHelper");

#region singleton implementation

private static readonly Lazy<RollbarDataScrubbingHelper> lazySingleton =
new Lazy<RollbarDataScrubbingHelper>(() => new RollbarDataScrubbingHelper());

/// <summary>
/// Gets the instance.
/// </summary>
Expand All @@ -25,34 +31,16 @@ public static RollbarDataScrubbingHelper Instance
{
get
{
return NestedSingleInstance.TheInstance;
return lazySingleton.Value;
}
}

/// <summary>
/// Prevents a default instance of the <see cref="RollbarDataScrubbingHelper" /> class from being created.
/// Prevents a default instance of the <see cref="EmptyDisposable" /> class from being created.
/// </summary>
private RollbarDataScrubbingHelper()
{
}

/// <summary>
/// Class NestedSingleInstance. This class cannot be inherited.
/// </summary>
private sealed class NestedSingleInstance
{
/// <summary>
/// Prevents a default instance of the <see cref="NestedSingleInstance" /> class from being created.
/// </summary>
private NestedSingleInstance()
{
}

/// <summary>
/// The instance
/// </summary>
internal static readonly RollbarDataScrubbingHelper TheInstance =
new RollbarDataScrubbingHelper();
traceSource.TraceInformation($"Creating the {typeof(RollbarDataScrubbingHelper).Name}...");
}

#endregion singleton implementation
Expand Down
Loading

0 comments on commit b244fea

Please sign in to comment.