Skip to content

Fix writeHeader computation in RollingRandomAccessFileManager#4008

Merged
vy merged 7 commits intoapache:2.xfrom
NeatGuyCoding:hotfix-wrong-check
Dec 30, 2025
Merged

Fix writeHeader computation in RollingRandomAccessFileManager#4008
vy merged 7 commits intoapache:2.xfrom
NeatGuyCoding:hotfix-wrong-check

Conversation

@NeatGuyCoding
Copy link
Copy Markdown
Contributor

Fix writeHeader computation in RollingRandomAccessFileManager

The writeHeader boolean was computed after creating the RandomAccessFile, which creates the file if it doesn't exist. This made file.exists() always return true, causing incorrect header write decisions.

This change captures the file's pre-existing state before opening the RandomAccessFile by:

  • Declaring a fileExistedBefore boolean initialized to false
  • Setting it by checking fileName != null && new File(fileName).exists() before calling new RandomAccessFile(...)
  • Using !fileExistedBefore instead of !file.exists() in the writeHeader calculation

When fileName is null, fileExistedBefore remains false as expected.

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Dec 21, 2025

Job Requested goals Build Tool Version Build Outcome Build Scan®
build-macos-latest clean install 3.9.8 Build Scan PUBLISHED
build-ubuntu-latest clean install 3.9.8 Build Scan PUBLISHED
build-windows-latest clean install 3.9.8 Build Scan PUBLISHED
Generated by gradle/develocity-actions

@vy vy assigned vy and NeatGuyCoding and unassigned vy Dec 26, 2025
@vy vy added appenders:Rolling Affects log file rolling functionality bug Incorrect, unexpected, or unintended behavior of existing code labels Dec 26, 2025
@vy
Copy link
Copy Markdown
Member

vy commented Dec 26, 2025

@NeatGuyCoding, the report and the fix look legitimate, thanks. Would you mind providing also a changelog entry and a test, please?

I'd appreciate it if you can keep the test as minimal as possible.

@NeatGuyCoding
Copy link
Copy Markdown
Contributor Author

@vy done

Comment thread src/changelog/.2.x.x/fix_RollingRandomAccessFileManager_writeHeader.xml Outdated
@github-project-automation github-project-automation Bot moved this to Changes requested in Log4j pull request tracker Dec 29, 2025
NeatGuyCoding and others added 3 commits December 30, 2025 17:34
…eader.xml

Co-authored-by: Volkan Yazıcı <volkan.yazici@oracle.com>
…r/rolling/RollingRandomAccessFileManager.java

Co-authored-by: Volkan Yazıcı <volkan.yazici@oracle.com>
@github-project-automation github-project-automation Bot moved this from Changes requested to Approved in Log4j pull request tracker Dec 30, 2025
@vy vy added this to the 2.25.4 milestone Dec 30, 2025
@vy vy enabled auto-merge (squash) December 30, 2025 12:28
@vy vy merged commit 752d023 into apache:2.x Dec 30, 2025
5 checks passed
@github-project-automation github-project-automation Bot moved this from Approved to Merged in Log4j pull request tracker Dec 30, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

appenders:Rolling Affects log file rolling functionality bug Incorrect, unexpected, or unintended behavior of existing code

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

2 participants