StyleTest.testNewerStylesheet intermittent test failure

Jaikiran Pai <[email protected]> Sun, 26 Jul 2026 22:33:20 +0530
Newsgroups gmane.comp.jakarta.ant.devel
Message-ID <[email protected]>
The org.apache.tools.ant.taskdefs.StyleTest.testNewerStylesheet test has 
recently started intermittently failing in our CI with failures like the 
one I pasted in the end of this mail.

I had a look at this test today. The test itself has been around for 
several decades. The test verifies the behaviour of the "xslt" task. It 
uses a input XML file and a stylesheet file. The stylesheet is then 
applied against the input file and the output is written to a output 
file. The output is then compared for the correct transformation. This 
works fine. Then immediately after this is done, the input stylesheet 
file is replaced/updated by the test and the transformation against the 
input XML file is repeated to the same output file. It is expected that 
the transformation will use the newly updated stylesheet content to do 
the transformation. In the intermittently failing cases, this doesn't 
happen and the output file consists the old content. It appears that the 
update to the stylesheet content goes unnoticed by the "xslt" task.

I went through the history of changes to that task. It looks like we 
recently changed the code in that task through 
https://github.com/apache/ant/commit/dc3d7ed34cd506a5b853af5f6dee25ec9ff8a094. 
As noted in our release notes:

 > Under certain edge cases this means xslt will now not process files 
it would have processed before (when the timestamps of source or 
stylesheet are very close or even equal to the timestamp of the target). 
In this case you can set granularity to 0 to get back to the behavior of 
1.10.15.

As part of that commit the test was (rightly) updated to use a 
granularity of 0 to retain the previous behaviour. However, it looks 
like this is not enough to get back the old behaviour. Specifically, in 
the new behaviour, the "SelectorUtils.isOutOfDate()" has this check:

(sourceLastModified - granularity) > targetLastModified)

Notice the use of greater than in that check. That differs from what was 
before the change, which was 
https://github.com/apache/ant/commit/dc3d7ed34cd506a5b853af5f6dee25ec9ff8a094#diff-ef05d180b6be18199aec5998859d8da5d9dd6f82f6f645883b50f949fde043ae 
:

if (force || inFile.lastModified() >= outFile.lastModified()
     || styleSheetLastModified >= outFile.lastModified())

Notice the use of >= in this check. So even with a granularity of 0, the 
newer check will not behave like it was previously. That explains these 
intermittent failures. If the stylesheet timestamp happens to be the 
same as the output file timestamp (due to the stylesheet update and a 
subsequent xslt task call happening quickly enough) then the 
transformation ends up being skipped in the newer code unlike previously.

I can't think of a way to address this failure and I wonder if this 
could impact actual builds, that use "xslt", as well. Any thoughts on 
what we should do?

A sample failure log is available here 
https://ci-builds.apache.org/job/Ant/job/Ant-Build-Matrix-master-Linux/OS=ubuntu,jdk=jdk_1.8_latest/4521/testReport/junit/org.apache.tools.ant.taskdefs/StyleTest/testNewerStylesheet/ 
and looks like:

expecting file build/testcases/tmp/testoutput_798403_main/out.xml to 
contain new-value but got
old-value

Expected: a string containing "new-value"
      but: was "
old-value
"

-Jaikiran