Skip to content

Commit

Permalink
Fast fix for NullRefException from FileAppender
Browse files Browse the repository at this point in the history
  • Loading branch information
erikmav committed Mar 9, 2024
1 parent 3877e0b commit 74ee334
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
11 changes: 11 additions & 0 deletions src/log4net.Tests/Appender/RollingFileAppenderTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2013,6 +2013,17 @@ public void TestInitializeRollBackups4()
VerifyInitializeRollBackups(8, iMaxRollBackups);
}

/// <summary>
/// Ensures that no problems result from creating and then closing the appender
/// when it has not also been initialized with ActivateOptions().
/// </summary>
[Test]
public void TestCreateCloseNoActivateOptions()
{
var appender = new RollingFileAppender();
appender.Close();
}

/// <summary>
///
/// </summary>
Expand Down
1 change: 1 addition & 0 deletions src/log4net.Tests/log4net.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.9.0" />
<PackageReference Include="NUnit" Version="3.14.0" />
<PackageReference Include="NExpect" Version="1.0.273" />
<PackageReference Include="Quackers.TestLogger" Version="1.0.24" />
Expand Down
4 changes: 2 additions & 2 deletions src/log4net/Appender/FileAppender.cs
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ private LockStateException(SerializationInfo info, StreamingContext context) : b
}

private Stream m_realStream = null;
private LockingModelBase m_lockingModel = null;
private readonly LockingModelBase m_lockingModel;
private int m_lockLevel = 0;

public LockingStream(LockingModelBase locking)
Expand Down Expand Up @@ -1306,7 +1306,7 @@ protected override void Reset()
protected override void OnClose()
{
base.OnClose();
m_lockingModel.OnClose();
m_lockingModel?.OnClose();
}

/// <summary>
Expand Down

0 comments on commit 74ee334

Please sign in to comment.