Skip to content

[MyPerf4J-90] Fix SysGenProfilingFile rename fail #90 - #91

Closed
JiaRG wants to merge 6 commits into
LinShunKang:developfrom
JiaRG:issues-#90
Closed

JiaRG wants to merge 6 commits into
LinShunKang:developfrom
JiaRG:issues-#90

Conversation

@JiaRG

@JiaRG JiaRG commented Apr 2, 2023 •

Copy link
Copy Markdown
Contributor

What is the purpose of the change

fix #90

Brief ChangeLog

fix SysGenProfilingFile rename fail

Verifying this change

Follow this checklist to help us incorporate your contribution quickly and easily:

  • Make sure there is a GITHUB_issue field for the change (usually before you start working on it). Trivial changes like typos do not require a GITHUB issue. Your pull request should address just this issue, without pulling in other changes - one PR resolves one issue.
  • Format the pull request title like [MyPerf4J-XXX] Fix NullPointerException when host is null #XXX. Each commit in the pull request should have a meaningful subject line and body.
  • Write a pull request description that is detailed enough to understand what the pull request does, how, and why.
  • Write necessary unit-test to verify your logic correction, more mock a little better when cross module dependency exist.
  • Run mvn clean package -Dmaven.test.skip=false to make sure unit-test pass.

Comment thread MyPerf4J-Core/src/main/java/cn/myperf4j/core/MethodMetricsHistogram.java Outdated
Comment thread MyPerf4J-Core/src/test/java/cn/myperf4j/core/FileTest.java
Comment thread MyPerf4J-Core/src/test/java/cn/myperf4j/core/FileTest.java Outdated
Comment thread MyPerf4J-Core/src/test/java/cn/myperf4j/core/FileTest.java Outdated
Comment thread MyPerf4J-Core/src/test/java/cn/myperf4j/core/FileTest.java
Comment thread MyPerf4J-Core/src/test/java/cn/myperf4j/core/FileTest.java Outdated
Comment thread MyPerf4J-Core/src/main/java/cn/myperf4j/core/MethodMetricsHistogram.java Outdated
Comment thread MyPerf4J-Core/src/test/java/cn/myperf4j/core/FileTest.java Outdated
Comment thread MyPerf4J-Core/src/test/java/cn/myperf4j/core/FileTest.java
fileWriter.write("#This is a file automatically generated by MyPerf4J, please do not edit!\n");
fileWriter.flush();
// 流还没释放导致
Assert.assertFalse(tmpFilePath.toFile().renameTo(testFilePath1.toFile()));

@LinShunKang LinShunKang Apr 14, 2023 •

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

在 MacOS 里这行代码执行失败

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

你之前的代码在 MacOS 里能成功吗?

Assert.assertTrue(testFilePath2.toFile().setReadOnly());
} else {
// 第一次rename能成功,后续就失败
Assert.assertFalse(tmpFilePath.toFile().renameTo(testFilePath2.toFile()));

@LinShunKang LinShunKang Apr 14, 2023 •

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

在 MacOS 里这行代码执行失败

final File tempFile = buildTmpProfilingFile(filePath);
final Path destPath = Files.move(tempFile.toPath(), Paths.get(filePath), REPLACE_EXISTING);
final File destFile = destPath.toFile();
// 此处不能设置只读,否则在windows环境下次move的时候会报错 AccessDeniedException

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

如果 destFile.setReadOnly() 之后再次 move 会报错的话,那 FileTest 的第 89 行就会抛异常

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

不一样,FileTest 能跑成功,但是 agent 加载到 tomcat 里面就会报错

@LinShunKang
LinShunKang force-pushed the develop branch 2 times, most recently from fff7d47 to 91761b6 Compare October 18, 2025 09:22
@LinShunKang
LinShunKang deleted the branch LinShunKang:develop November 16, 2025 12:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

File.renameTo及File.setReadOnly的问题

2 participants