This issue has been created
There are 2 updates.
 
 
XWiki Commons / cid:jira-generated-image-avatar-695f474b-c1ce-48f6-8153-5ec450c47c26 XCOMMONS-3831 Open

XWikiTempDir injects the same directory in all the fields and parameters resolved within the same millisecond

 
View issue   ·   Add comment
 

Issue created

 
cid:jira-generated-image-avatar-d08b2997-e900-42e7-a970-52dbe4b717c7 Claude created this issue on 12/Oct/26 16:57
 
Summary: XWikiTempDir injects the same directory in all the fields and parameters resolved within the same millisecond
Issue Type: cid:jira-generated-image-avatar-695f474b-c1ce-48f6-8153-5ec450c47c26 Bug
Affects Versions: 11.7-rc-1
Assignee: Unassigned
Components: Development Issues only - Test
Created: 12/Oct/26 16:57
Priority: cid:jira-generated-image-static-major-8a69a21f-13d0-410d-b3b8-02656ced5981 Major
Reporter: Claude
Description:

What happens

XWikiTempDirExtension injects XWikiTempDirUtil.createTemporaryDirectory() into every field and parameter annotated with @XWikiTempDir. That method names the directory target/test-<current time in milliseconds>, so all the directories requested within the same millisecond are the same directory, although its javadoc describes it as unique.

In practice, a test class with several @XWikiTempDir fields (or a field and a parameter) usually gets the same directory in all of them, since they are injected one after the other in the same beforeEach. The test then silently shares files between what it expects to be separate directories.

Found while writing tests for the remote observation module: the test base class emulates two XWiki instances and gives each one an @XWikiTempDir field as permanent directory. Both instances read and wrote the same observation/id.txt, so they had the same identifier and a test checking the cluster members passed without checking anything. The test was changed to create its own sub-directories, but any other test relying on several @XWikiTempDir injections is exposed to the same problem.

Expected

Each injection gets its own new directory, still under target. For example, keep the test-<time> prefix and add a counter or a random suffix, or use Files.createTempDirectory(Path.of("target"), "test-"), and make sure the returned directory did not exist before.

 
 

2 updates

 
cid:jira-generated-image-avatar-c30b6a4d-8287-4344-9b39-d891328a840d Changes by Clément Christiaens on 12/Oct/26 17:06
 
Reporter: Claude Clément Christiaens
Assignee: Clément Christiaens